Permalink
Browse files

Added --timeout to set a sampling timeout in seconds.

  • Loading branch information...
sk89q committed Jun 14, 2013
1 parent 464c0f4 commit fc698cd6b4e774aae99795f017cac75c98db67df
@@ -45,5 +45,8 @@
@Parameter(names = { "--interval" }, description = "The sample rate, in milliseconds")
public Integer interval = 100;
@Parameter(names = { "--timeout" }, description = "The number of seconds before ceasing sampling (optional)")
public Integer timeout;
}
@@ -70,6 +70,7 @@
private MBeanServerConnection mbsc;
private ThreadMXBean threadBean;
private String filterThread;
private long endTime = -1;
public WarmRoast(VirtualMachine vm, int interval) {
this.vm = vm;
@@ -101,6 +102,14 @@ public void setFilterThread(String filterThread) {
this.filterThread = filterThread;
}
public long getEndTime() {
return endTime;
}
public void setEndTime(long l) {
this.endTime = l;
}
public void connect()
throws IOException, AgentLoadException, AgentInitializationException {
// Load the agent
@@ -139,6 +148,14 @@ private ThreadMXBean getThreadMXBean()
@Override
public synchronized void run() {
if (endTime >= 0) {
if (endTime <= System.currentTimeMillis()) {
cancel();
System.err.println("Sampling has stopped.");
return;
}
}
ThreadInfo[] threadDumps = threadBean.dumpAllThreads(false, false);
for (ThreadInfo threadInfo : threadDumps) {
String threadName = threadInfo.getThreadName();
@@ -289,13 +306,20 @@ public int compare(VirtualMachineDescriptor o1,
System.exit(2);
}
}
roast.setFilterThread(opt.threadName);
System.err.println(SEPARATOR);
roast.setFilterThread(opt.threadName);
if (opt.timeout != null && opt.timeout > 0) {
roast.setEndTime(System.currentTimeMillis() + opt.timeout * 1000);
System.err.println("Sampling set to stop in " + opt.timeout + " seconds.");
}
System.err.println("Starting a server on " + address.toString() + "...");
System.err.println("Once the server starts (shortly), visit the URL in your browser.");
System.err.println("Note: The longer you wait before using the output of that " +
"webpage, the more accurate the results will be.");
try {
roast.connect();

0 comments on commit fc698cd

Please sign in to comment.