@API(value=MAINTAINED) public class StoreTimer extends Object
A store timer is a thread-safe record of call counts and nanosecond call times for various database operations,
classified by an StoreTimer.Event
.
If a context has a store timer, various operations will record timing information in it. It is up to the caller to
provide the necessary integration between this information and any system monitoring tools.
Modifier and Type | Class and Description |
---|---|
static interface |
StoreTimer.Aggregate
An aggregate event is an event whose value is computed over the value of another set of events.
|
static interface |
StoreTimer.Count
StoreTimer.Event s that only count occurrences or total size. |
static class |
StoreTimer.Counter
Contains the number of occurrences and cummulative time spent on an associated
StoreTimer.Event . |
static interface |
StoreTimer.DetailEvent
StoreTimer.Event s that are a significant part of a larger process. |
static interface |
StoreTimer.Event
An identifier for occurrences that need to be timed.
|
static interface |
StoreTimer.Wait
StoreTimer.Event s that can be waited on. |
Modifier and Type | Field and Description |
---|---|
protected Map<StoreTimer.Event,StoreTimer.Counter> |
counters |
protected long |
lastReset |
protected Map<StoreTimer.Event,StoreTimer.Counter> |
timeoutCounters |
protected UUID |
uuid |
Constructor and Description |
---|
StoreTimer() |
Modifier and Type | Method and Description |
---|---|
static void |
checkEventNameUniqueness(Stream<StoreTimer.Event> events)
Confirm that there is no naming conflict among the event names that will be used.
|
Set<StoreTimer.Aggregate> |
getAggregates()
Return the set of aggregates that this store timer can produce.
|
int |
getCount(StoreTimer.Event event)
Get the total count for a given event.
|
StoreTimer.Counter |
getCounter(StoreTimer.Event event)
Return the counter for a given event.
|
protected StoreTimer.Counter |
getCounter(StoreTimer.Event event,
boolean createIfNotExists)
Return the counter value for a given event type.
|
static StoreTimer |
getDifference(StoreTimer timer,
StoreTimerSnapshot timerSnapshot)
Subtracts counts and times recorded by a snapshot of a timer returning a new timer representing the difference.
|
Collection<StoreTimer.Event> |
getEvents()
Get all events known to this timer.
|
Map<String,Number> |
getKeysAndValues()
Suitable for
KeyValueLogMessage . |
long |
getTimeNanos(StoreTimer.Event event)
Get the total time spent for a given event.
|
int |
getTimeoutCount(StoreTimer.Event event)
Get the total count of timeouts for a given event.
|
StoreTimer.Counter |
getTimeoutCounter(StoreTimer.Event event)
Return the timeout counter value for a given event type.
|
protected StoreTimer.Counter |
getTimeoutCounter(StoreTimer.Event event,
boolean createIfNotExists) |
Collection<StoreTimer.Event> |
getTimeoutEvents()
Get all events that have timed out.
|
long |
getTimeoutTimeNanos(StoreTimer.Event event)
Get the total time spent for a given event that timed out.
|
UUID |
geUUID()
Get the UUID of this timer.
|
void |
increment(Set<StoreTimer.Count> events)
Record that each event in a set occurred once.
|
void |
increment(Set<StoreTimer.Count> events,
int amount)
Record that each event occurred one or more times.
|
void |
increment(StoreTimer.Count event)
Record that an event occurred once.
|
void |
increment(StoreTimer.Count event,
int amount)
Record that an event occurred one or more times.
|
<T> CompletableFuture<T> |
instrument(Set<StoreTimer.Event> events,
CompletableFuture<T> future,
Executor executor)
Add timing instrumentation to an asynchronous operation.
|
<T> CompletableFuture<T> |
instrument(Set<StoreTimer.Event> events,
CompletableFuture<T> future,
Executor executor,
long startTime)
Add timing instrumentation to an asynchronous operation.
|
<T> CompletableFuture<T> |
instrument(StoreTimer.Event event,
CompletableFuture<T> future,
Executor executor)
Add timing instrumentation to an asynchronous operation.
|
<T> CompletableFuture<T> |
instrument(StoreTimer.Event event,
CompletableFuture<T> future,
Executor executor,
long startTime)
Add timing instrumentation to an asynchronous operation.
|
<T> RecordCursor<T> |
instrument(StoreTimer.Event event,
RecordCursor<T> inner)
Instrument an asynchronous cursor.
|
protected <T> CompletableFuture<T> |
instrumentAsync(Set<StoreTimer.Event> events,
CompletableFuture<T> future,
Executor executor,
long startTime) |
void |
record(Set<StoreTimer.Event> events,
long timeDifferenceNanos)
Record the amount of time each element in a set of events took to run.
|
void |
record(StoreTimer.Count event)
Deprecated.
replaced with
increment(Count) |
void |
record(StoreTimer.Event event,
long timeDifferenceNanos)
Record the amount of time an event took to run.
|
void |
recordSinceNanoTime(StoreTimer.Event event,
long startTime)
Record time since given time.
|
void |
recordTimeout(StoreTimer.Wait event,
long startTime)
Record that some operation timed out.
|
void |
reset()
Clear all recorded timing information.
|
@Nonnull protected final Map<StoreTimer.Event,StoreTimer.Counter> counters
@Nonnull protected final Map<StoreTimer.Event,StoreTimer.Counter> timeoutCounters
protected long lastReset
public static void checkEventNameUniqueness(@Nonnull Stream<StoreTimer.Event> events)
events
- a stream of events to check for duplicates@Nonnull public static StoreTimer getDifference(@Nonnull StoreTimer timer, @Nonnull StoreTimerSnapshot timerSnapshot)
Subtracting a snapshot of a timer from the original timer after subsequent operations have been performed and timed can provide useful metrics as to the cost of those subsequent operations.
The timer must have been previously derived from the snapshot. Moreover, the timer should not have been reset after the snapshot was taken.
timer
- timer to subtract the snapshot fromtimerSnapshot
- snapshot of the provided timer@Nullable public StoreTimer.Counter getCounter(@Nonnull StoreTimer.Event event)
event
- the event to have its counter retrievednull
if not counter exists@Nullable protected StoreTimer.Counter getCounter(@Nonnull StoreTimer.Event event, boolean createIfNotExists)
createIfNotExists
is true
and a counter
for the event
did not previously exists, a zero-value counter will be created and returned, ensuring
that you will never receive a null
value; for StoreTimer.Aggregate
events, the zero-value counter will
be immutable, however for non-aggregate events the counter returned may be updated by the caller as necessary.event
- the event to have its counter retrievedcreateIfNotExists
- if true the counter returned will be created if it did not already existnull
if there is no value present for the event and
createIfNotExists
was false@Nullable public StoreTimer.Counter getTimeoutCounter(@Nonnull StoreTimer.Event event)
event
- the event to have its counter retrievednull
if there is no value present for the event@Nullable protected StoreTimer.Counter getTimeoutCounter(@Nonnull StoreTimer.Event event, boolean createIfNotExists)
public void record(Set<StoreTimer.Event> events, long timeDifferenceNanos)
events
- the set of events being recordedtimeDifferenceNanos
- the time that the instrumented events took to runpublic void record(StoreTimer.Event event, long timeDifferenceNanos)
event
- the event being recordedtimeDifferenceNanos
- the time that instrumented event took to run@Deprecated public void record(@Nonnull StoreTimer.Count event)
increment(Count)
increment(Count)
instead.event
- the event being recordedpublic void recordSinceNanoTime(@Nonnull StoreTimer.Event event, long startTime)
event
- the event being recordedstartTime
- the System.nanoTime()
when the event startedpublic void recordTimeout(StoreTimer.Wait event, long startTime)
event
- the event that was waited forstartTime
- the System.nanoTime()
when the event startedpublic void increment(@Nonnull Set<StoreTimer.Count> events)
events
- the set of events being recordedpublic void increment(@Nonnull StoreTimer.Count event)
event
- the event being recordedpublic void increment(@Nonnull Set<StoreTimer.Count> events, int amount)
amount
.events
- the set of events being recordedamount
- the number of times each event occurredpublic void increment(@Nonnull StoreTimer.Count event, int amount)
amount
.event
- the event being recordedamount
- the number of times the event occurredpublic long getTimeNanos(StoreTimer.Event event)
event
- the event to get time information forpublic int getCount(StoreTimer.Event event)
event
- the event to get count information forpublic long getTimeoutTimeNanos(StoreTimer.Event event)
event
- the event to get time information forpublic int getTimeoutCount(StoreTimer.Event event)
event
- the event to get timeout information for@Nonnull public Set<StoreTimer.Aggregate> getAggregates()
StoreTimer.Aggregate.compute(StoreTimer)
).public Collection<StoreTimer.Event> getEvents()
public Collection<StoreTimer.Event> getTimeoutEvents()
public Map<String,Number> getKeysAndValues()
KeyValueLogMessage
.public void reset()
public <T> CompletableFuture<T> instrument(StoreTimer.Event event, CompletableFuture<T> future, Executor executor)
T
- the type of the futureevent
- the event type to use to record timingfuture
- a future that will complete when the operation is finishedexecutor
- an asynchronous executor to use to run the recordingpublic <T> CompletableFuture<T> instrument(Set<StoreTimer.Event> events, CompletableFuture<T> future, Executor executor)
T
- the type of the futureevents
- the event types to use to record timingfuture
- a future that will complete when the operation is finishedexecutor
- an asynchronous executor to use to run the recordingpublic <T> CompletableFuture<T> instrument(StoreTimer.Event event, CompletableFuture<T> future, Executor executor, long startTime)
T
- the type of the futureevent
- the event type to use to record timingfuture
- a future that will complete when the operation is finishedexecutor
- an asynchronous executor to use to run the recordingstartTime
- the nanosecond time at which the operation startedpublic <T> CompletableFuture<T> instrument(Set<StoreTimer.Event> events, CompletableFuture<T> future, Executor executor, long startTime)
T
- the type of the futureevents
- the event types to use to record timingfuture
- a future that will complete when the operation is finishedexecutor
- an asynchronous executor to use to run the recordingstartTime
- the nanosecond time at which the operation startedpublic <T> RecordCursor<T> instrument(StoreTimer.Event event, RecordCursor<T> inner)
RecordCursor.onHasNext()
asynchronous method.T
- the type of the cursor elementsevent
- the event type to use to record timinginner
- the cursor to record timing information forprotected <T> CompletableFuture<T> instrumentAsync(Set<StoreTimer.Event> events, CompletableFuture<T> future, Executor executor, long startTime)