public final class SimonUtils extends Object
Stopwatch
and Counter
provide human readable
toString
outputs. All nanosecond values are converted into few valid digits with
proper unit (ns, us, ms, s) - this is done via method presentNanoTime(long)
.
Max/min counter values are checked for undefined state (max/min long value is converted
to string "undef") - via method presentMinMaxCount(long)
.
calculateCounterAggregate(org.javasimon.Simon)
or calculateStopwatchAggregate(org.javasimon.Simon)
.
Methods come also in versions allowing to filter by SimonFilter
.
Split split = SimonManager.getStopwatch("com.my.other.stopwatch").start(); SimonManager.getCounter("com.my.counter").setState(SimonState.DISABLED, false); split.stop(); System.out.println(SimonUtils.simonTreeString(SimonManager.getRootSimon()));And the output is:
(+): Unknown Simon: [ ENABLED] com(+): Unknown Simon: [com INHERIT] my(+): Unknown Simon: [com.my INHERIT] other(+): Unknown Simon: [com.my.other INHERIT] stopwatch(+): Simon Stopwatch: total 24.2 ms, counter 1, max 24.2 ms, min 24.2 ms, mean 24.2 ms [com.my.other.stopwatch INHERIT] counter(-): Simon Counter: counter=0, max=undef, min=undef [com.my.counter DISABLED]Notice +/- signs in parenthesis that displays effective Simon state (enabled/disabled), further details are printed via each Simon's
toString
method.
localName(String)
or check if the name is valid Simon name via checkName(String)
.Modifier and Type | Field and Description |
---|---|
static String |
ALLOWED_CHARS
Allowed Simon name characters.
|
static String |
MANAGER_SERVLET_CTX_ATTRIBUTE
Name of the attribute where manager is searched for in an appropriate context - used for Spring/JavaEE/console integration.
|
static Pattern |
NAME_PATTERN
Regex pattern for Simon names.
|
static String |
NAME_PATTERN_CHAR_CLASS_CONTENT
Regex character class content for
NAME_PATTERN . |
Modifier and Type | Method and Description |
---|---|
static CounterAggregate |
calculateCounterAggregate(Simon simon)
Aggregate statistics from all counters in hierarchy of simons.
|
static CounterAggregate |
calculateCounterAggregate(Simon simon,
SimonFilter filter)
Aggregate statistics from all counters in hierarchy that pass specified filter.
|
static StopwatchAggregate |
calculateStopwatchAggregate(Simon simon)
Aggregate statistics from all stopwatches in hierarchy of simons.
|
static StopwatchAggregate |
calculateStopwatchAggregate(Simon simon,
SimonFilter filter)
Aggregate statistics from all stopwatches in hierarchy that pass specified filter.
|
static boolean |
checkName(String name)
Checks if the input string is correct Simon name.
|
static String |
compact(String input,
int limitTo)
Shrinks the middle of the input string if it is too long, so it does not exceed limitTo.
|
static <T> T |
doWithStopwatch(String name,
Callable<T> callable)
Calls a block of code with stopwatch around and returns result.
|
static void |
doWithStopwatch(String name,
Runnable runnable)
Calls a block of code with stopwatch around, can not return any result or throw an exception
(use
doWithStopwatch(String, java.util.concurrent.Callable) instead). |
static String |
generateName()
Autogenerates name for the Simon using the class name and the method name.
|
static String |
generateNameForClass(String suffix)
Autogenerates name for the Simon using the fully-qualified class name.
|
static String |
generateNameForClassAndMethod(String suffix)
Autogenerates name for the Simon using the fully qualified class name and the method name.
|
static String |
localName(String name)
Returns last part of Simon name - local name.
|
static String |
presentMinMaxCount(long minmax)
Returns min/max counter values in human readable form - if the value is max or min long value
it is considered unused and string "undef" is returned.
|
static String |
presentNanoTime(double nanos)
Returns nano-time in human readable form with unit.
|
static String |
presentNanoTime(long nanos)
Returns nano-time in human readable form with unit.
|
static String |
presentTimestamp(long timestamp)
Returns timestamp in human readable (yet condensed) form "yyMMdd-HHmmss.SSS".
|
static String |
simonTreeString(Simon simon)
Returns multi-line string containing Simon tree starting with the specified Simon.
|
static void |
validateSimonName(String name)
Checks if the input string is correct Simon name and throws
SimonException otherwise. |
public static final String NAME_PATTERN_CHAR_CLASS_CONTENT
NAME_PATTERN
.public static final Pattern NAME_PATTERN
public static final String ALLOWED_CHARS
public static final String MANAGER_SERVLET_CTX_ATTRIBUTE
SimonWebConfigurationBean
(Spring module) and then picked up by SimonServletFilter
(JavaEE module) and SimonConsoleFilter
(Embeddable console). If no manager is found in the attribute of the context,
it is expected that components will use default SimonManager
instead.public static String presentNanoTime(long nanos)
Long.MAX_VALUE
or
Long.MIN_VALUE
) string UNDEF_STRING
is returned, so it can be used for min/max values as well.nanos
- time in nanosecondspublic static String presentNanoTime(double nanos)
nanos
- time in nanosecondspublic static String presentTimestamp(long timestamp)
timestamp
- timestamp in millispublic static String presentMinMaxCount(long minmax)
minmax
- counter extreme valueLong.MIN_VALUE
or Long.MAX_VALUE
public static String simonTreeString(Simon simon)
null
for
input value of null or for NullSimon or any Simon with name equal to null (anonymous
Simons) - this is also the case when the Manager is disabled and tree for its root
Simon is requested.simon
- root Simon of the output treepublic static String localName(String name)
name
- full Simon namepublic static boolean checkName(String name)
NAME_PATTERN
.name
- checked Simon namepublic static void validateSimonName(String name)
SimonException
otherwise.name
- checked Simon nameSimonException
- if the string is not proper Simon namepublic static String generateNameForClass(String suffix)
suffix
- name suffix for eventual Simon discriminationpublic static String generateNameForClassAndMethod(String suffix)
suffix
- name suffix for eventual Simon discriminationpublic static String generateName()
generateNameForClassAndMethod(String)
public static <T> T doWithStopwatch(String name, Callable<T> callable) throws Exception
T
- return typename
- name of the Stopwatchcallable
- callable block of codeException
- whatever block of code throwspublic static void doWithStopwatch(String name, Runnable runnable)
doWithStopwatch(String, java.util.concurrent.Callable)
instead).name
- name of the Stopwatchrunnable
- wrapped block of codepublic static String compact(String input, int limitTo)
public static StopwatchAggregate calculateStopwatchAggregate(Simon simon)
simon
- root of the hierarchy of simons for which statistics will be aggregatedpublic static StopwatchAggregate calculateStopwatchAggregate(Simon simon, SimonFilter filter)
simon
- root of the hierarchy of simons for which statistics will be aggregatedfilter
- filter to select subsets of simons to aggregatepublic static CounterAggregate calculateCounterAggregate(Simon simon)
simon
- root of the hierarchy of simons for which statistics will be aggregatedpublic static CounterAggregate calculateCounterAggregate(Simon simon, SimonFilter filter)
simon
- root of the hierarchy of simons for which statistics will be aggregatedfilter
- filter to select subsets of simons to aggregateCopyright © 2019. All rights reserved.