public class Profiler
extends java.lang.Object
This tool definitely incurs some load within the system, so it should only be used while debugging, and not as general use. In addition if it is left running without being reset, it will continue to consume more and more memory.
Constructor and Description |
---|
Profiler()
Constructs a new profiler instance.
|
Profiler(int pollIntervalInMs)
Constructs a new profiler instance.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
dump()
Output all the currently collected statistics to the provided output stream.
|
java.lang.String |
dump(boolean dumpIndividualThreads)
Deprecated.
Use
dump(boolean, int) with a value of 1 |
java.lang.String |
dump(boolean dumpIndividualThreads,
int minimumStackWitnessCount)
Output all the currently collected statistics to the provided output stream.
|
void |
dump(java.io.OutputStream out)
Output all the currently collected statistics to the provided output stream.
|
void |
dump(java.io.OutputStream out,
boolean dumpIndividualThreads)
Deprecated.
Use
dump(OutputStream, boolean, int) with a value of 1 |
void |
dump(java.io.OutputStream out,
boolean dumpIndividualThreads,
int minimumStackWitnessCount)
Output all the currently collected statistics to the provided output stream.
|
void |
dump(java.io.PrintStream ps)
Output all the currently collected statistics to the provided output stream.
|
void |
dump(java.io.PrintStream ps,
boolean dumpIndividualThreads)
Deprecated.
Use
dump(PrintStream, boolean, int) with a value of 1 |
void |
dump(java.io.PrintStream ps,
boolean dumpIndividualThreads,
int minimumStackWitnessCount)
Output all the currently collected statistics to the provided output stream.
|
int |
getCollectedSampleQty()
Call to get an estimate on how many times the profiler has collected a sample of the thread
stacks.
|
int |
getPollInterval()
Call to get the currently set profile interval.
|
boolean |
isRunning()
Call to check weather the profile is currently running/started.
|
void |
reset()
Reset the current stored statistics.
|
void |
setPollInterval(int pollIntervalInMs)
Change how long the profiler waits before getting additional thread stacks.
|
void |
start()
Starts the profiler running in a new thread.
|
void |
start(java.util.concurrent.Executor executor)
Starts the profiler running in a new thread.
|
ListenableFuture<java.lang.String> |
start(java.util.concurrent.Executor executor,
long sampleDurationInMillis)
Starts the profiler running in a new thread.
|
ListenableFuture<java.lang.String> |
start(long sampleDurationInMillis)
Starts the profiler running in a new thread.
|
void |
stop()
Stops the profiler from collecting more statistics.
|
public Profiler()
dump()
with a provided output stream to get the results to.
This uses a default poll interval of 100 milliseconds.
public Profiler(int pollIntervalInMs)
dump()
with a provided output stream to get the results to.pollIntervalInMs
- frequency to check running threadspublic void setPollInterval(int pollIntervalInMs)
pollIntervalInMs
- time in milliseconds to wait between thread data dumpspublic int getPollInterval()
public int getCollectedSampleQty()
public void reset()
public boolean isRunning()
true
if there is a thread currently collecting statistics.public void start()
If this profiler had previously ran, and is now sitting in a stopped state again. The
statistics from the previous run will still be included in this run. If you wish to clear
out previous runs you must call reset()
first.
public void start(java.util.concurrent.Executor executor)
If this profiler had previously ran, and is now sitting in a stopped state again. The
statistics from the previous run will still be included in this run. If you wish to clear
out previous runs you must call reset()
first.
If an executor is provided, this call will block until the the profiler has been started on the provided executor.
executor
- executor to execute on, or null
if new thread should be createdpublic ListenableFuture<java.lang.String> start(long sampleDurationInMillis)
If this profiler had previously ran, and is now sitting in a stopped state again. The
statistics from the previous run will still be included in this run. If you wish to clear
out previous runs you must call reset()
first.
If sampleDurationInMillis
is greater than zero the Profiler will invoke
stop()
in that many milliseconds.
The returned ListenableFuture
will be provided the dump when stop()
is
invoked next. Either from a timeout provided to this call, or a manual invocation of
stop()
.
sampleDurationInMillis
- if greater than 0
the profiler will only run for this many millisecondspublic ListenableFuture<java.lang.String> start(java.util.concurrent.Executor executor, long sampleDurationInMillis)
If this profiler had previously ran, and is now sitting in a stopped state again. The
statistics from the previous run will still be included in this run. If you wish to clear
out previous runs you must call reset()
first.
If an executor is provided, this call will block until the the profiler has been started on the provided executor.
If sampleDurationInMillis
is greater than zero the Profiler will invoke
stop()
in that many milliseconds.
The returned ListenableFuture
will be provided the dump when stop()
is
invoked next. Either from a timeout provided to this call, or a manual invocation of
stop()
.
executor
- executor to execute on, or null
if new thread should be createdsampleDurationInMillis
- if greater than 0
the profiler will only run for this many millisecondspublic void stop()
dump()
call after it has stopped.public java.lang.String dump()
@Deprecated public java.lang.String dump(boolean dumpIndividualThreads)
dump(boolean, int)
with a value of 1
dumpIndividualThreads
- If true
then a report of stacks seen for individual threads is also dumpedpublic java.lang.String dump(boolean dumpIndividualThreads, int minimumStackWitnessCount)
dumpIndividualThreads
- If true
then a report of stacks seen for individual threads is also dumpedminimumStackWitnessCount
- Minimum times profiler must have seen the stack to include in the dumppublic void dump(java.io.OutputStream out)
out
- OutputStream to write results to@Deprecated public void dump(java.io.OutputStream out, boolean dumpIndividualThreads)
dump(OutputStream, boolean, int)
with a value of 1
out
- OutputStream to write results todumpIndividualThreads
- If true
then a report of stacks seen for individual threads is also dumpedpublic void dump(java.io.OutputStream out, boolean dumpIndividualThreads, int minimumStackWitnessCount)
out
- OutputStream to write results todumpIndividualThreads
- If true
then a report of stacks seen for individual threads is also dumpedminimumStackWitnessCount
- Minimum times profiler must have seen the stack to include in the dumppublic void dump(java.io.PrintStream ps)
ps
- PrintStream to write results to@Deprecated public void dump(java.io.PrintStream ps, boolean dumpIndividualThreads)
dump(PrintStream, boolean, int)
with a value of 1
ps
- PrintStream to write results todumpIndividualThreads
- If true
then a report of stacks seen for individual threads is also dumpedpublic void dump(java.io.PrintStream ps, boolean dumpIndividualThreads, int minimumStackWitnessCount)
ps
- PrintStream to write results todumpIndividualThreads
- If true
then a report of stacks seen for individual mthreads is also dumpedminimumStackWitnessCount
- Minimum times profiler must have seen the stack to include in the dump