Package org.threadly.util.debug
Class ControlledThreadProfiler
- java.lang.Object
-
- org.threadly.util.debug.Profiler
-
- org.threadly.util.debug.ControlledThreadProfiler
-
public class ControlledThreadProfiler extends Profiler
This class functions very similar to theProfiler
. The difference between the two is while theProfiler
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
whereaddProfiledThread(Thread)
is provided as theConsumer
on thread creation.- Since:
- 1.0.0
-
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.
-
-
-
Constructor Detail
-
ControlledThreadProfiler
public ControlledThreadProfiler()
Constructs a new profiler instance. The only way to get results from this instance is to call#dump()
with a provided output stream to get the results to.
-
ControlledThreadProfiler
public ControlledThreadProfiler(int pollIntervalInMs)
Constructs a new profiler instance. The only way to get results from this instance is to call#dump()
with a provided output stream to get the results to.- Parameters:
pollIntervalInMs
- frequency to check running threads
-
ControlledThreadProfiler
public ControlledThreadProfiler(int pollIntervalInMs, java.util.function.Function<? super Profiler,java.lang.String> startFutureResultSupplier)
Constructs a new profiler instance. The only way to get results from this instance is to call#dump()
with a provided output stream to get the results to.This constructor allows you to change the behavior of the
ListenableFuture
result whenProfiler.start(long)
orProfiler.start(Executor, long)
is used. Generally this will provide the complete result ofProfiler.dump()
. This can be replaced with callingProfiler.dump(OutputStream, boolean, int)
with parameters to reduce the output, or evennull
so long as the consumers of the future can handle a null result.- Parameters:
pollIntervalInMs
- frequency to check running threadsstartFutureResultSupplier
- Supplier to be used for providing future results
-
-
Method Detail
-
addProfiledThread
public void addProfiledThread(java.lang.Thread t)
Adds a thread to be checked by the running profiler.If the thread is already included, or if the thread is
null
, this is a no-op.- Parameters:
t
- Thread to add to the list of tracked threads
-
removeProfiledThread
public boolean removeProfiledThread(java.lang.Thread t)
Removed a thread from the set of tracked threads. It is good practice to remove a thread from the profiler if it is no longer alive. This profiler makes NO attempt to automatically remove dead threads.- Parameters:
t
- Thread to remove from tracked set- Returns:
true
if the thread was found and removed.
-
getProfiledThreadCount
public int getProfiledThreadCount()
Call to check how many threads are currently being checked by the profiler. Keep in mind that threads that are not alive may be skipped by the profiler, but will be included in this count.- Returns:
- count of tracked threads.
-
-