1 17 package org.apache.activemq.tool.sampler; 18 19 import org.apache.activemq.tool.sampler.plugins.CpuSamplerPlugin; 20 import org.apache.activemq.tool.sampler.plugins.LinuxCpuSamplerPlugin; 21 import org.apache.activemq.tool.reports.AbstractPerfReportWriter; 22 23 import java.io.IOException ; 24 25 public class CpuSamplerTask extends AbstractPerformanceSampler { 26 27 private CpuSamplerPlugin plugin = null; 28 29 public void createPlugin() throws IOException { 30 createPlugin(System.getProperty("os.name")); 31 } 32 33 public void createPlugin(String osName) throws IOException { 34 if (osName == null) { 35 throw new IOException ("No defined OS name found. Found: " + osName); 36 } 37 38 if (osName.equalsIgnoreCase(CpuSamplerPlugin.LINUX)) { 39 plugin = new LinuxCpuSamplerPlugin(getInterval()); 40 } else { 41 throw new IOException ("No CPU Sampler Plugin found for OS: " + osName + ". CPU Sampler will not be started."); 42 } 43 } 44 45 public void sampleData() { 46 if (plugin != null && perfReportWriter != null) { 47 perfReportWriter.writeCsvData(AbstractPerfReportWriter.REPORT_PLUGIN_CPU, "index=" + sampleIndex + "," + plugin.getCpuUtilizationStats()); 48 } 49 } 50 51 protected void onRampUpStart() { 52 super.onRampUpStart(); 53 if (plugin != null) { 54 plugin.start(); 55 } 56 } 57 58 protected void onRampDownEnd() { 59 super.onRampDownEnd(); 60 if (plugin != null) { 61 plugin.stop(); 62 } 63 } 64 } 65 | Popular Tags |