aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlbert Pham <the.sk89q@gmail.com>2013-06-14 11:18:21 -0700
committerAlbert Pham <the.sk89q@gmail.com>2013-06-14 11:18:21 -0700
commitfc698cd6b4e774aae99795f017cac75c98db67df (patch)
tree48d2603a555b210c32f39c280aef8cb66fd0810b /src
parent464c0f4bf8658ee89677f1913e9ee021911d8b30 (diff)
downloadspark-fc698cd6b4e774aae99795f017cac75c98db67df.tar.gz
spark-fc698cd6b4e774aae99795f017cac75c98db67df.tar.bz2
spark-fc698cd6b4e774aae99795f017cac75c98db67df.zip
Added --timeout to set a sampling timeout in seconds.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/sk89q/warmroast/RoastOptions.java3
-rw-r--r--src/main/java/com/sk89q/warmroast/WarmRoast.java28
2 files changed, 29 insertions, 2 deletions
diff --git a/src/main/java/com/sk89q/warmroast/RoastOptions.java b/src/main/java/com/sk89q/warmroast/RoastOptions.java
index edb6a0e..e7d2b07 100644
--- a/src/main/java/com/sk89q/warmroast/RoastOptions.java
+++ b/src/main/java/com/sk89q/warmroast/RoastOptions.java
@@ -45,5 +45,8 @@ public class RoastOptions {
@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;
}
diff --git a/src/main/java/com/sk89q/warmroast/WarmRoast.java b/src/main/java/com/sk89q/warmroast/WarmRoast.java
index 6ddd9ca..d437c61 100644
--- a/src/main/java/com/sk89q/warmroast/WarmRoast.java
+++ b/src/main/java/com/sk89q/warmroast/WarmRoast.java
@@ -70,6 +70,7 @@ public class WarmRoast extends TimerTask {
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 class WarmRoast extends TimerTask {
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 @@ public class WarmRoast extends TimerTask {
@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 class WarmRoast extends TimerTask {
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();