activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r417341 - in /incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler: ./ plugins/
Date Tue, 27 Jun 2006 05:15:31 GMT
Author: aco
Date: Mon Jun 26 22:15:30 2006
New Revision: 417341

URL: http://svn.apache.org/viewvc?rev=417341&view=rev
Log:
Modify the vmstat plugin as it was returning only the summary previously.

Modified:
    incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/AbstractPerformanceSampler.java
    incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/CpuSamplerTask.java
    incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/ThroughputSamplerTask.java
    incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/plugins/CpuSamplerPlugin.java
    incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/plugins/LinuxCpuSamplerPlugin.java

Modified: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/AbstractPerformanceSampler.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/AbstractPerformanceSampler.java?rev=417341&r1=417340&r2=417341&view=diff
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/AbstractPerformanceSampler.java
(original)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/AbstractPerformanceSampler.java
Mon Jun 26 22:15:30 2006
@@ -72,9 +72,6 @@
 
     public void run() {
         try {
-            // Compute for the actual duration window of the sampler
-            long endTime = System.currentTimeMillis() + duration - rampDownTime;
-
             onRampUpStart();
             if (perfEventListener != null) {
             	perfEventListener.onRampUpStart(this);
@@ -91,15 +88,7 @@
             	perfEventListener.onSamplerStart(this);
             }
 
-            while (System.currentTimeMillis() < endTime) {
-                try {
-                    Thread.sleep(interval);
-                } catch (InterruptedException e) {
-                    e.printStackTrace();
-                }
-                sampleData();
-                sampleIndex++;
-            }
+            sample();
 
             onSamplerEnd();
             if (perfEventListener != null) {
@@ -124,7 +113,22 @@
         }
 	}
 
-	public abstract void sampleData();
+    protected void sample() {
+        // Compute for the actual duration window of the sampler
+        long endTime = System.currentTimeMillis() + duration - rampDownTime - rampUpTime;
+
+        while (System.currentTimeMillis() < endTime) {
+            try {
+                Thread.sleep(interval);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+            sampleData();
+            sampleIndex++;
+        }
+    }
+
+    public abstract void sampleData();
 
     public boolean isRunning() {
 		return isRunning.get();

Modified: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/CpuSamplerTask.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/CpuSamplerTask.java?rev=417341&r1=417340&r2=417341&view=diff
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/CpuSamplerTask.java
(original)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/CpuSamplerTask.java
Mon Jun 26 22:15:30 2006
@@ -16,11 +16,11 @@
 
     public void createPlugin(String osName) throws IOException {
         if (osName == null) {
-            throw new IOException("No defined OS name found. Foound: " + osName);
+            throw new IOException("No defined OS name found. Found: " + osName);
         }
 
         if (osName.equalsIgnoreCase(CpuSamplerPlugin.LINUX)) {
-            plugin = new LinuxCpuSamplerPlugin();
+            plugin = new LinuxCpuSamplerPlugin(getInterval());
         } else {
             throw new IOException("No CPU Sampler Plugin found for OS: " + osName + ". CPU
Sampler will not be started.");
         }
@@ -29,6 +29,20 @@
     public void sampleData() {
         if (plugin != null && perfReportWriter != null) {
             perfReportWriter.writeCsvData(ReportPlugin.REPORT_PLUGIN_CPU, plugin.getCpuUtilizationStats());
+        }
+    }
+
+    protected void onRampUpStart() {
+        super.onRampUpStart();
+        if (plugin != null) {
+            plugin.start();
+        }
+    }
+
+    protected void onRampDownEnd() {
+        super.onRampDownEnd();
+        if (plugin != null) {
+            plugin.stop();
         }
     }
 }

Modified: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/ThroughputSamplerTask.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/ThroughputSamplerTask.java?rev=417341&r1=417340&r2=417341&view=diff
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/ThroughputSamplerTask.java
(original)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/ThroughputSamplerTask.java
Mon Jun 26 22:15:30 2006
@@ -11,6 +11,12 @@
     private final Object mutex = new Object();
     private List clients = new ArrayList();
 
+    public void registerClient(MeasurableClient client) {
+        synchronized (mutex) {
+            clients.add(client);
+        }
+    }
+
 	public void sampleData() {
 		for (Iterator i = clients.iterator(); i.hasNext();) {
             MeasurableClient client = (MeasurableClient) i.next();
@@ -22,12 +28,6 @@
             client.reset();
         }
 	}
-
-	public void registerClient(MeasurableClient client) {
-        synchronized (mutex) {
-            clients.add(client);
-        }
-    }
 
     protected void onSamplerStart() {
         // Reset the throughput of the clients

Modified: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/plugins/CpuSamplerPlugin.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/plugins/CpuSamplerPlugin.java?rev=417341&r1=417340&r2=417341&view=diff
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/plugins/CpuSamplerPlugin.java
(original)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/plugins/CpuSamplerPlugin.java
Mon Jun 26 22:15:30 2006
@@ -14,6 +14,8 @@
 	public final static String MAC_OS_X     = "Mac OS X";
 	public final static String POWERPC      = "PowerPC";
 	public final static String OS_2         = "OS/2";
-	
+
 	public String getCpuUtilizationStats();
+    public void start();
+    public void stop();
 }

Modified: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/plugins/LinuxCpuSamplerPlugin.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/plugins/LinuxCpuSamplerPlugin.java?rev=417341&r1=417340&r2=417341&view=diff
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/plugins/LinuxCpuSamplerPlugin.java
(original)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/plugins/LinuxCpuSamplerPlugin.java
Mon Jun 26 22:15:30 2006
@@ -1,32 +1,75 @@
 package org.apache.activemq.tool.sampler.plugins;
 
+import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
+
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
+import java.io.IOException;
 import java.util.StringTokenizer;
 
-public class LinuxCpuSamplerPlugin implements CpuSamplerPlugin {
-
-	private String vmstat = "vmstat";
-
-	public String getCpuUtilizationStats() {
-		try {
-			Process p = Runtime.getRuntime().exec(vmstat);
-			BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()), 1024);
-
-			br.readLine(); // throw away the first line
+public class LinuxCpuSamplerPlugin implements CpuSamplerPlugin, Runnable {
 
-			String header = br.readLine();
-			String data   = br.readLine();
-
-			br.close();
-
-			// Convert to CSV of key=value pair
-			return convertToCSV(header, data);
-		} catch (Exception e) {
-			e.printStackTrace();
-			return "";
-		}
-	}
+    private Process vmstatProcess;
+    private String vmstat;
+    private String result = "";
+    private final Object mutex = new Object();
+    private AtomicBoolean stop = new AtomicBoolean(false);
+
+    public LinuxCpuSamplerPlugin(long intervalInMs) {
+        vmstat = "vmstat -n " + (int)(intervalInMs / 1000);
+    }
+
+    public void start() {
+        stop.set(false);
+        Thread t = new Thread(this);
+        t.start();
+    }
+
+    public void stop() {
+        stop.set(true);
+        try {
+            vmstatProcess.waitFor();
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void run() {
+
+        try {
+            vmstatProcess = Runtime.getRuntime().exec(vmstat);
+            BufferedReader br = new BufferedReader(new InputStreamReader(vmstatProcess.getInputStream()),
1024);
+
+            br.readLine(); // throw away the first line
+
+            String header = br.readLine();
+            String data;
+
+            while (!stop.get()) {
+                data = br.readLine();
+                if (data != null) {
+                    String csvData = convertToCSV(header, data);
+                    synchronized (mutex) {
+                        result = csvData;
+                    }
+                }
+            }
+            br.close();
+            vmstatProcess.destroy();
+
+        } catch (IOException ioe) {
+            ioe.printStackTrace();
+        }
+    }
+
+    public String getCpuUtilizationStats() {
+        String data;
+        synchronized (mutex) {
+            data = result;
+            result = "";
+        }
+        return data;
+    }
 
 	public String getVmstat() {
 		return vmstat;
@@ -36,7 +79,7 @@
 		this.vmstat = vmstat;
 	}
 
-	protected String convertToCSV(String header, String data) {
+    protected String convertToCSV(String header, String data) {
 		StringTokenizer headerTokens = new StringTokenizer(header, " ");
 		StringTokenizer dataTokens   = new StringTokenizer(data, " ");
 



Mime
View raw message