@ThreadSafe public class StateSampler extends TimerTask implements AutoCloseable
| Modifier and Type | Class and Description |
|---|---|
class |
StateSampler.ScopedState
A nested class that is used to account for states and state
transitions based on lexical scopes.
|
| Modifier and Type | Field and Description |
|---|---|
static long |
DEFAULT_SAMPLING_PERIOD_MS |
| Constructor and Description |
|---|
StateSampler(String prefix,
CounterSet.AddCounterMutator counterSetMutator)
Constructs a new
StateSampler that can be used to obtain
an approximate breakdown of the time spent by an execution
context in various states, as a fraction of the total time. |
StateSampler(String prefix,
CounterSet.AddCounterMutator counterSetMutator,
long samplingPeriodMs)
Constructs a new
StateSampler that can be used to obtain
an approximate breakdown of the time spent by an execution
context in various states, as a fraction of the total time. |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
void |
run() |
StateSampler.ScopedState |
scopedState(int state)
Returns an AutoCloseable
StateSampler.ScopedState that will perform a
state transition to the given state, and will automatically reset
the state to the prior state upon closing. |
int |
setState(int state)
Sets the current thread state.
|
int |
setState(String name)
Sets the current thread state.
|
int |
stateForName(String name)
Returns the state associated with a name; creating a new state if
necessary.
|
cancel, scheduledExecutionTimepublic static final long DEFAULT_SAMPLING_PERIOD_MS
public StateSampler(String prefix, CounterSet.AddCounterMutator counterSetMutator, long samplingPeriodMs)
StateSampler that can be used to obtain
an approximate breakdown of the time spent by an execution
context in various states, as a fraction of the total time.prefix - the prefix of the counter names for the statescounterSetMutator - the CounterSet.AddCounterMutator
used to create a counter for each distinct statesamplingPeriodMs - the sampling period in millisecondspublic StateSampler(String prefix, CounterSet.AddCounterMutator counterSetMutator)
StateSampler that can be used to obtain
an approximate breakdown of the time spent by an execution
context in various states, as a fraction of the total time.prefix - the prefix of the counter names for the statescounterSetMutator - the CounterSet.AddCounterMutator
used to create a counter for each distinct statepublic void close()
close in interface AutoCloseablepublic int stateForName(String name)
public int setState(int state)
state - the new state to transition topublic int setState(String name)
name - the name of the new state to transition topublic StateSampler.ScopedState scopedState(int state)
StateSampler.ScopedState that will perform a
state transition to the given state, and will automatically reset
the state to the prior state upon closing.state - the new state to transition toStateSampler.ScopedState that automatically resets the state
to the prior state