activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject svn commit: r416547 - in /incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler: ./ plugins/
Date Fri, 23 Jun 2006 02:26:20 GMT
Author: aco
Date: Thu Jun 22 19:26:20 2006
New Revision: 416547

URL: http://svn.apache.org/viewvc?rev=416547&view=rev
Log:
- Redesigned the sampler and added the cpu sampler.

Added:
    incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/
    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/MeasurableClient.java
    incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/PerformanceEventListener.java
    incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/PerformanceSampler.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/
    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

Added: 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=416547&view=auto
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/AbstractPerformanceSampler.java
(added)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/AbstractPerformanceSampler.java
Thu Jun 22 19:26:20 2006
@@ -0,0 +1,150 @@
+package org.apache.activemq.tool.sampler;
+
+import org.apache.activemq.tool.reports.PerformanceReportWriter;
+import org.apache.activemq.tool.properties.AbstractObjectProperties;
+
+import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
+
+public abstract class AbstractPerformanceSampler extends AbstractObjectProperties implements
PerformanceSampler {
+	protected long rampUpTime   = 30 * 1000; // 30 secs
+	protected long rampDownTime = 30 * 1000; // 30 secs
+	protected long duration     = 5 * 60 * 1000; // 5 mins
+	protected long interval     = 1000; // 1 sec
+	protected PerformanceReportWriter perfReportWriter = null;
+	protected PerformanceEventListener perfEventListener = null;
+	protected final AtomicBoolean isRunning = new AtomicBoolean(false);
+
+	protected long sampleIndex = 0;
+
+	public long getRampUpTime() {
+		return rampUpTime;
+	}
+
+	public void setRampUpTime(long rampUpTime) {
+		this.rampUpTime = rampUpTime;
+	}
+
+	public long getRampDownTime() {
+		return rampDownTime;
+	}
+
+	public void setRampDownTime(long rampDownTime) {
+		this.rampDownTime = rampDownTime;
+	}
+
+	public long getDuration() {
+		return duration;
+	}
+
+	public void setDuration(long duration) {
+		this.duration = duration;
+	}
+
+	public long getInterval() {
+		return interval;
+	}
+
+	public void setInterval(long interval) {
+		this.interval = interval;
+	}
+
+	public PerformanceReportWriter getPerfReportWriter() {
+		return perfReportWriter;
+	}
+
+	public void setPerfReportWriter(PerformanceReportWriter perfReportWriter) {
+		this.perfReportWriter = perfReportWriter;
+	}
+
+	public PerformanceEventListener getPerfEventListener() {
+		return perfEventListener;
+	}
+
+	public void setPerfEventListener(PerformanceEventListener perfEventListener) {
+		this.perfEventListener = perfEventListener;
+	}
+
+    public void startSampler() {
+        isRunning.set(true);
+        Thread t = new Thread(this);
+        t.start();
+    }
+
+    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);
+            }
+
+            try {
+                Thread.sleep(rampUpTime);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+
+            onSamplerStart();
+            if (perfEventListener != null) {
+            	perfEventListener.onSamplerStart(this);
+            }
+
+            while (System.currentTimeMillis() < endTime) {
+                try {
+                    Thread.sleep(interval);
+                } catch (InterruptedException e) {
+                    e.printStackTrace();
+                }
+                sampleData();
+                sampleIndex++;
+            }
+
+            onSamplerEnd();
+            if (perfEventListener != null) {
+            	perfEventListener.onSamplerEnd(this);
+            }
+
+            try {
+                Thread.sleep(rampDownTime);
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+
+            onRampDownEnd();
+            if (perfEventListener != null) {
+            	perfEventListener.onRampDownEnd(this);
+            }
+        } finally {
+            isRunning.set(false);
+            synchronized (isRunning) {
+                isRunning.notifyAll();
+            }
+        }
+	}
+
+	public abstract void sampleData();
+
+    public boolean isRunning() {
+		return isRunning.get();
+	}
+
+	public void waitUntilDone() {
+		while (isRunning()) {
+            try {
+                synchronized (isRunning) {
+                    isRunning.wait(0);
+                }
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+	}
+
+    // Call back functions to customize behavior of thread.
+    protected void onRampUpStart() {}
+    protected void onSamplerStart() {}
+    protected void onSamplerEnd() {}
+    protected void onRampDownEnd() {}
+}

Added: 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=416547&view=auto
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/CpuSamplerTask.java
(added)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/CpuSamplerTask.java
Thu Jun 22 19:26:20 2006
@@ -0,0 +1,34 @@
+package org.apache.activemq.tool.sampler;
+
+import org.apache.activemq.tool.sampler.plugins.CpuSamplerPlugin;
+import org.apache.activemq.tool.sampler.plugins.LinuxCpuSamplerPlugin;
+import org.apache.activemq.tool.reports.plugins.ReportPlugin;
+
+import java.io.IOException;
+
+public class CpuSamplerTask extends AbstractPerformanceSampler {
+
+    private CpuSamplerPlugin plugin = null;
+
+    public void createPlugin() throws IOException {
+        createPlugin(System.getProperty("os.name"));
+    }
+
+    public void createPlugin(String osName) throws IOException {
+        if (osName == null) {
+            throw new IOException("No defined OS name found. Foound: " + osName);
+        }
+
+        if (osName.equalsIgnoreCase(CpuSamplerPlugin.LINUX)) {
+            plugin = new LinuxCpuSamplerPlugin();
+        } else {
+            throw new IOException("No CPU Sampler Plugin found for OS: " + osName + ". CPU
Sampler will not be started.");
+        }
+    }
+
+    public void sampleData() {
+        if (plugin != null && perfReportWriter != null) {
+            perfReportWriter.writeCsvData(ReportPlugin.REPORT_PLUGIN_CPU, plugin.getCpuUtilizationStats());
+        }
+    }
+}

Added: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/MeasurableClient.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/MeasurableClient.java?rev=416547&view=auto
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/MeasurableClient.java
(added)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/MeasurableClient.java
Thu Jun 22 19:26:20 2006
@@ -0,0 +1,23 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.tool.sampler;
+
+public interface MeasurableClient {
+    public void   reset();
+    public String getClientName();
+    public long   getThroughput();
+}

Added: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/PerformanceEventListener.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/PerformanceEventListener.java?rev=416547&view=auto
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/PerformanceEventListener.java
(added)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/PerformanceEventListener.java
Thu Jun 22 19:26:20 2006
@@ -0,0 +1,8 @@
+package org.apache.activemq.tool.sampler;
+
+public interface PerformanceEventListener {
+	public void onRampUpStart(PerformanceSampler sampler);
+	public void onSamplerStart(PerformanceSampler sampler);
+	public void onSamplerEnd(PerformanceSampler sampler);
+	public void onRampDownEnd(PerformanceSampler sampler);
+}

Added: incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/PerformanceSampler.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/PerformanceSampler.java?rev=416547&view=auto
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/PerformanceSampler.java
(added)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/PerformanceSampler.java
Thu Jun 22 19:26:20 2006
@@ -0,0 +1,22 @@
+package org.apache.activemq.tool.sampler;
+
+import org.apache.activemq.tool.reports.PerformanceReportWriter;
+
+public interface PerformanceSampler extends Runnable {
+	public long getRampUpTime();
+	public void setRampUpTime(long rampUpTime);
+	public long getRampDownTime();
+	public void setRampDownTime(long rampDownTime);
+	public long getDuration();
+	public void setDuration(long duration);
+	public long getInterval();
+	public void setInterval(long interval);
+	public PerformanceReportWriter getPerfReportWriter();
+	public void setPerfReportWriter(PerformanceReportWriter writer);
+	public PerformanceEventListener getPerfEventListener();
+	public void setPerfEventListener(PerformanceEventListener listener);
+
+	public void sampleData();
+	public boolean isRunning();
+	public void waitUntilDone();
+}

Added: 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=416547&view=auto
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/ThroughputSamplerTask.java
(added)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/ThroughputSamplerTask.java
Thu Jun 22 19:26:20 2006
@@ -0,0 +1,39 @@
+package org.apache.activemq.tool.sampler;
+
+import org.apache.activemq.tool.reports.plugins.ReportPlugin;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class ThroughputSamplerTask extends AbstractPerformanceSampler {
+
+    private final Object mutex = new Object();
+    private List clients = new ArrayList();
+
+	public void sampleData() {
+		for (Iterator i = clients.iterator(); i.hasNext();) {
+            MeasurableClient client = (MeasurableClient) i.next();
+            if (perfReportWriter != null) {
+            	perfReportWriter.writeCsvData(ReportPlugin.REPORT_PLUGIN_THROUGHPUT,
+                        "index=" + sampleIndex + ",clientName=" + client.getClientName()
+
+                        ",throughput=" + client.getThroughput());
+            }
+            client.reset();
+        }
+	}
+
+	public void registerClient(MeasurableClient client) {
+        synchronized (mutex) {
+            clients.add(client);
+        }
+    }
+
+    protected void onSamplerStart() {
+        // Reset the throughput of the clients
+        for (Iterator i = clients.iterator(); i.hasNext();) {
+            MeasurableClient client = (MeasurableClient) i.next();
+            client.reset();
+        }
+    }
+}

Added: 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=416547&view=auto
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/plugins/CpuSamplerPlugin.java
(added)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/plugins/CpuSamplerPlugin.java
Thu Jun 22 19:26:20 2006
@@ -0,0 +1,19 @@
+package org.apache.activemq.tool.sampler.plugins;
+
+public interface CpuSamplerPlugin {
+	public final static String WINDOWS_2000 = "Windows 2000";
+	public final static String WINDOWS_NT   = "Windows NT";
+	public final static String WINDOWS_XP   = "Windows XP";
+	public final static String WINDOWS_95   = "Windows 95";
+	public final static String WINDOWS_CE   = "Windows CE";
+	public final static String LINUX        = "Linux";
+	public final static String SOLARIS      = "Solaris";
+	public final static String AIX          = "AIX";
+	public final static String FREEBSD      = "FreeBSD";
+	public final static String MAC_OS       = "Mac OS";
+	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();
+}

Added: 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=416547&view=auto
==============================================================================
--- incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/plugins/LinuxCpuSamplerPlugin.java
(added)
+++ incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/sampler/plugins/LinuxCpuSamplerPlugin.java
Thu Jun 22 19:26:20 2006
@@ -0,0 +1,50 @@
+package org.apache.activemq.tool.sampler.plugins;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+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
+			
+			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 "";
+		}
+	}
+
+	public String getVmstat() {
+		return vmstat;
+	}
+
+	public void setVmstat(String vmstat) {
+		this.vmstat = vmstat;
+	}
+	
+	protected String convertToCSV(String header, String data) {
+		StringTokenizer headerTokens = new StringTokenizer(header, " ");
+		StringTokenizer dataTokens   = new StringTokenizer(data, " ");
+		
+		String csv = "";
+		while (headerTokens.hasMoreTokens()) {
+			csv += (headerTokens.nextToken() + "=" + dataTokens.nextToken() + ";");
+		}
+		
+		return csv;
+	}
+}



Mime
View raw message