public class ControlledThreadProfiler extends Profiler
Profiler
. The difference between the two is
while the Profiler
profiles all running threads on the VM. This implementation only
profiles threads which you explicitly add to be profiled.
It can be useful to use a ConfigurableThreadFactory
where
addProfiledThread(Thread)
is provided as the Consumer
on
thread creation.
Constructor and Description |
---|
ControlledThreadProfiler()
Constructs a new profiler instance.
|
ControlledThreadProfiler(int pollIntervalInMs)
Constructs a new profiler instance.
|
ControlledThreadProfiler(int pollIntervalInMs,
java.util.function.Function<? super Profiler,java.lang.String> startFutureResultSupplier)
Constructs a new profiler instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addProfiledThread(java.lang.Thread t)
Adds a thread to be checked by the running profiler.
|
int |
getProfiledThreadCount()
Call to check how many threads are currently being checked by the profiler.
|
boolean |
removeProfiledThread(java.lang.Thread t)
Removed a thread from the set of tracked threads.
|
public ControlledThreadProfiler()
#dump()
with a provided output stream to get the results to.public ControlledThreadProfiler(int pollIntervalInMs)
#dump()
with a provided output stream to get the results to.pollIntervalInMs
- frequency to check running threadspublic ControlledThreadProfiler(int pollIntervalInMs, java.util.function.Function<? super Profiler,java.lang.String> startFutureResultSupplier)
#dump()
with a provided output stream to get the results to.
This constructor allows you to change the behavior of the ListenableFuture
result when
Profiler.start(long)
or Profiler.start(Executor, long)
is used. Generally this will provide
the complete result of Profiler.dump()
. This can be replaced with calling
Profiler.dump(OutputStream, boolean, int)
with parameters to reduce the output, or even
null
so long as the consumers of the future can handle a null result.
pollIntervalInMs
- frequency to check running threadsstartFutureResultSupplier
- Supplier to be used for providing future resultspublic void addProfiledThread(java.lang.Thread t)
If the thread is already included, or if the thread is null
, this is a no-op.
t
- Thread to add to the list of tracked threadspublic boolean removeProfiledThread(java.lang.Thread t)
t
- Thread to remove from tracked settrue
if the thread was found and removed.public int getProfiledThreadCount()