|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.javasimon.utils.SimonUtils
public final class SimonUtils
SimonUtils provides static utility methods.
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).
Simon and all its children is provided -
recursiveReset(org.javasimon.Simon). For various debug purposes there is a method
that creates string displaying the whole Simon sub-tree. Here is example code that initializes
two random Simons and prints the whole Simon hierarchy (note that the method can be used to
obtain any sub-tree of the hierarchy):
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).
| Field Summary | |
|---|---|
static String |
ALLOWED_CHARS
Allowed Simon name characters. |
private static int |
CLIENT_CODE_STACK_INDEX
|
private static DecimalFormatSymbols |
DECIMAL_FORMAT_SYMBOLS
|
private static DecimalFormat |
DEFAULT_FORMAT
|
private static int |
HUNDRED
|
static long |
INIT_MILLIS
Value of System.currentTimeMillis() at a particular time, when INIT_NANOS is initialized as well. |
static long |
INIT_NANOS
Value of System.nanoTime() at a particular time, when INIT_MILLIS is initialized as well. |
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 long |
MILLIS_IN_SECOND
Number of milliseconds in one second. |
static Pattern |
NAME_PATTERN
Regex pattern for Simon names. |
static String |
NAME_PATTERN_CHAR_CLASS_CONTENT
Regex character class content for NAME_PATTERN. |
static long |
NANOS_IN_MILLIS
Number of nanoseconds in one millisecond. |
private static String |
SHRINKED_STRING
|
private static int |
TEN
|
private static SimpleDateFormat |
TIMESTAMP_FORMAT
|
private static String |
UNDEF_STRING
|
private static DecimalFormat |
UNDER_HUNDRED_FORMAT
|
private static DecimalFormat |
UNDER_TEN_FORMAT
|
private static int |
UNIT_PREFIX_FACTOR
|
| Constructor Summary | |
|---|---|
private |
SimonUtils()
|
| Method Summary | ||
|---|---|---|
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
|
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). |
|
private static String |
formatTime(double time,
String unit)
|
|
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. |
|
private static String |
generatePrivate(String suffix,
boolean includeMethodName)
|
|
static boolean |
checkName(String name)
Checks if the input string is correct Simon name. |
|
static String |
localName(String name)
Returns last part of Simon name - local name. |
|
static long |
millisForNano(long nanos)
Converts nano timer value into millis timestamp compatible with System.currentTimeMillis(). |
|
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 |
presentMinMaxSplit(long minmax)
Returns min/max split 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. |
|
private static String |
presentOverNanoTime(double time)
|
|
static String |
presentTimestamp(long timestamp)
Returns timestamp in human readable (yet condensed) form "yyMMdd-HHmmss.SSS". |
|
private static void |
printSimon(int level,
Simon simon,
StringBuilder sb)
|
|
private static void |
printSimonTree(int level,
Simon simon,
StringBuilder sb)
|
|
static void |
recursiveReset(Simon simon)
Resets the whole Simon subtree - calls Simon.reset() on the
Simon and recursively on all its children. |
|
static String |
simonTreeString(Simon simon)
Returns multi-line string containing Simon tree starting with the specified Simon. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final long MILLIS_IN_SECOND
public static final long NANOS_IN_MILLIS
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 final long INIT_NANOS
System.nanoTime() at a particular time, when INIT_MILLIS is initialized as well.
Used in millisForNano(long).
public static final long INIT_MILLIS
System.currentTimeMillis() at a particular time, when INIT_NANOS is initialized as well.
Used in millisForNano(long).
private static final SimpleDateFormat TIMESTAMP_FORMAT
private static final int UNIT_PREFIX_FACTOR
private static final DecimalFormatSymbols DECIMAL_FORMAT_SYMBOLS
private static final int TEN
private static final DecimalFormat UNDER_TEN_FORMAT
private static final int HUNDRED
private static final DecimalFormat UNDER_HUNDRED_FORMAT
private static final DecimalFormat DEFAULT_FORMAT
private static final String UNDEF_STRING
private static final int CLIENT_CODE_STACK_INDEX
private static final String SHRINKED_STRING
| Constructor Detail |
|---|
private SimonUtils()
| Method Detail |
|---|
public static String presentNanoTime(long nanos)
nanos - time in nanoseconds
public static String presentNanoTime(double nanos)
nanos - time in nanoseconds
private static String presentOverNanoTime(double time)
time - time in nanoseconds
private static String formatTime(double time,
String unit)
public static String presentTimestamp(long timestamp)
timestamp - timestamp in millis
public static String presentMinMaxCount(long minmax)
minmax - counter extreme value
Long.MIN_VALUE or Long.MAX_VALUEpublic static String presentMinMaxSplit(long minmax)
minmax - split extreme value
Long.MIN_VALUE or Long.MAX_VALUEpublic 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 tree
private static void printSimonTree(int level,
Simon simon,
StringBuilder sb)
private static void printSimon(int level,
Simon simon,
StringBuilder sb)
public static String localName(String name)
name - full Simon name
public static void recursiveReset(Simon simon)
Simon.reset() on the
Simon and recursively on all its children. Operation is not truly atomic as a whole,
consistency on the Simon level depends on the implementation of Simon.reset()
(which is thread-safe in all current implementations).
simon - subtree rootpublic static boolean checkName(String name)
NAME_PATTERN.
name - checked string
public static String generateNameForClass(String suffix)
suffix - name suffix for eventual Simon discrimination
public static String generateNameForClassAndMethod(String suffix)
suffix - name suffix for eventual Simon discrimination
private static String generatePrivate(String suffix,
boolean includeMethodName)
public 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 code
Exception - whatever block of code throws
public static void doWithStopwatch(String name,
Runnable runnable)
doWithStopwatch(String, java.util.concurrent.Callable) instead).
name - name of the Stopwatchrunnable - wrapped block of code
public static String compact(String input,
int limitTo)
public static long millisForNano(long nanos)
System.currentTimeMillis(). Method does not
just divide nanos by one million, but also works with remembered values for milli- and nano-timers at one particular moment.
nanos - nano timer value
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||