Package org.slf4j.profiler
Class Profiler
- java.lang.Object
-
- org.slf4j.profiler.Profiler
-
- All Implemented Interfaces:
TimeInstrument
public class Profiler extends java.lang.Object implements TimeInstrument
A poor man's profiler to measure the time elapsed performing some lengthy task.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.List<TimeInstrument>
childTimeInstrumentList
(package private) static java.lang.String
ELAPSED_TIME
(package private) StopWatch
globalStopWatch
(package private) Logger
logger
(package private) static int
MIN_SW_ELAPSED_TIME_NUMBER_LENGTH
(package private) static int
MIN_SW_NAME_LENGTH
(package private) java.lang.String
name
(package private) static java.lang.String
NESTED_PROFILER_FIRST_PREFIX
(package private) static java.lang.String
PROFILER_MARKER_NAME
(package private) ProfilerRegistry
profilerRegistry
(package private) static java.lang.String
SUBTOTAL_ELAPSED
(package private) static java.lang.String
TOP_PROFILER_FIRST_PREFIX
(package private) static java.lang.String
TOTAL_ELAPSED
-
Constructor Summary
Constructors Constructor Description Profiler(java.lang.String name)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.String
buildProfilerString(DurationUnit du, java.lang.String firstPrefix, java.lang.String label, java.lang.String indentation)
private static void
buildStopWatchString(java.lang.StringBuilder buf, DurationUnit du, java.lang.String prefix, java.lang.String indentation, StopWatch sw)
long
elapsedTime()
Time elapsed between start and stop, in nanoseconds.java.util.List<TimeInstrument>
getCopyOfChildTimeInstruments()
Return a copy of the child instrument list for this Profiler instance.StopWatch
getCopyOfGlobalStopWatch()
Return a copy of the global stopwatch of this Profiler instance.(package private) TimeInstrument
getLastTimeInstrument()
Logger
getLogger()
java.lang.String
getName()
All time instruments are named entities.ProfilerRegistry
getProfilerRegistry()
TimeInstrumentStatus
getStatus()
void
log()
If the time instrument has an associated logger, then log information about this time instrument.void
print()
Print information about this time instrument on the console.void
registerWith(ProfilerRegistry profilerRegistry)
(package private) void
sanityCheck()
This method is used in tests.void
setLogger(Logger logger)
void
start(java.lang.String name)
Starts a child stop watch and stops any previously started time instruments.Profiler
startNested(java.lang.String name)
TimeInstrument
stop()
Stop this time instrument.(package private) void
stopLastTimeInstrument()
java.lang.String
toString()
-
-
-
Field Detail
-
PROFILER_MARKER_NAME
static final java.lang.String PROFILER_MARKER_NAME
- See Also:
- Constant Field Values
-
MIN_SW_NAME_LENGTH
static final int MIN_SW_NAME_LENGTH
- See Also:
- Constant Field Values
-
MIN_SW_ELAPSED_TIME_NUMBER_LENGTH
static final int MIN_SW_ELAPSED_TIME_NUMBER_LENGTH
- See Also:
- Constant Field Values
-
name
final java.lang.String name
-
globalStopWatch
final StopWatch globalStopWatch
-
childTimeInstrumentList
java.util.List<TimeInstrument> childTimeInstrumentList
-
profilerRegistry
ProfilerRegistry profilerRegistry
-
logger
Logger logger
-
TOP_PROFILER_FIRST_PREFIX
static java.lang.String TOP_PROFILER_FIRST_PREFIX
-
NESTED_PROFILER_FIRST_PREFIX
static java.lang.String NESTED_PROFILER_FIRST_PREFIX
-
TOTAL_ELAPSED
static java.lang.String TOTAL_ELAPSED
-
SUBTOTAL_ELAPSED
static java.lang.String SUBTOTAL_ELAPSED
-
ELAPSED_TIME
static java.lang.String ELAPSED_TIME
-
-
Method Detail
-
getName
public java.lang.String getName()
Description copied from interface:TimeInstrument
All time instruments are named entities.- Specified by:
getName
in interfaceTimeInstrument
- Returns:
- the name of this instrument
-
getProfilerRegistry
public ProfilerRegistry getProfilerRegistry()
-
registerWith
public void registerWith(ProfilerRegistry profilerRegistry)
-
getLogger
public Logger getLogger()
-
setLogger
public void setLogger(Logger logger)
-
start
public void start(java.lang.String name)
Starts a child stop watch and stops any previously started time instruments.- Specified by:
start
in interfaceTimeInstrument
-
startNested
public Profiler startNested(java.lang.String name)
-
getLastTimeInstrument
TimeInstrument getLastTimeInstrument()
-
stopLastTimeInstrument
void stopLastTimeInstrument()
-
elapsedTime
public long elapsedTime()
Description copied from interface:TimeInstrument
Time elapsed between start and stop, in nanoseconds.- Specified by:
elapsedTime
in interfaceTimeInstrument
- Returns:
- time elapsed in nanoseconds
-
stop
public TimeInstrument stop()
Description copied from interface:TimeInstrument
Stop this time instrument.- Specified by:
stop
in interfaceTimeInstrument
- Returns:
- this
-
getStatus
public TimeInstrumentStatus getStatus()
- Specified by:
getStatus
in interfaceTimeInstrument
-
sanityCheck
void sanityCheck() throws java.lang.IllegalStateException
This method is used in tests.- Throws:
java.lang.IllegalStateException
-
print
public void print()
Description copied from interface:TimeInstrument
Print information about this time instrument on the console.- Specified by:
print
in interfaceTimeInstrument
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
log
public void log()
Description copied from interface:TimeInstrument
If the time instrument has an associated logger, then log information about this time instrument. Note thatStopWatch
instances cannot log whileProfiler
instances can.- Specified by:
log
in interfaceTimeInstrument
-
getCopyOfChildTimeInstruments
public java.util.List<TimeInstrument> getCopyOfChildTimeInstruments()
Return a copy of the child instrument list for this Profiler instance.- Returns:
- a copy of this instance's child time instrument list
- Since:
- 1.5.9
-
getCopyOfGlobalStopWatch
public StopWatch getCopyOfGlobalStopWatch()
Return a copy of the global stopwatch of this Profiler instance.- Returns:
- a copy of this instance's global stop watch
- Since:
- 1.5.9
-
buildProfilerString
private java.lang.String buildProfilerString(DurationUnit du, java.lang.String firstPrefix, java.lang.String label, java.lang.String indentation)
-
buildStopWatchString
private static void buildStopWatchString(java.lang.StringBuilder buf, DurationUnit du, java.lang.String prefix, java.lang.String indentation, StopWatch sw)
-
-