public class NullProfiler extends java.lang.Object implements Profiler
ProfilerProvider.current()
won't ever have to return null.
This makes it possible to call:
try (Timing t = profilerProvider.current().step("do my thing")) { // do stuff here }
...without having to worry about whether there is a current profiler
or not. A NullProfiler
should be returned in those cases.
Modifier and Type | Field and Description |
---|---|
static NullProfiler |
INSTANCE |
Modifier and Type | Method and Description |
---|---|
Profiler |
addChild(java.lang.String name)
Adds a child profiler to the current on.
|
void |
addCustomTiming(java.lang.String type,
java.lang.String executeType,
java.lang.String command,
long duration)
Add a query timing inside the current timing step.
|
java.lang.String |
asPlainText()
Render a plain test version of this profiler, for logging
|
java.lang.String |
asUiJson()
Returns a JSON string representing this profiler instance in a form understood by the Javascript UI.
|
void |
close()
/**
Same as calling
Profiler.stop() . |
CustomTiming |
customTiming(java.lang.String type,
java.lang.String executeType,
java.lang.String command)
Starts a custom timing under this timing.
|
<T> T |
customTiming(java.lang.String type,
java.lang.String executeType,
java.lang.String command,
java.util.concurrent.Callable<T> function)
Start and stop a new custom timing with the given callable function.
|
void |
customTiming(java.lang.String type,
java.lang.String executeType,
java.lang.String command,
java.lang.Runnable block)
Start and stop a new custom timing with the given block.
|
Timing |
getHead()
Returns the current live timing for this profiler.
|
java.util.UUID |
getId()
Returns a unique id for the profiling session.
|
Timing |
getRoot()
Returns the root timing for this profiler.
|
java.lang.String |
getUser()
Returns the user name for the profile session.
|
void |
setUser(java.lang.String user)
Set the user name for the current profiling session
|
Timing |
step(java.lang.String name)
Start a new profiling step with the default
ProfileLevel.Info level; |
<T> T |
step(java.lang.String name,
java.util.concurrent.Callable<T> function)
Start and stop a new profiling step with the given callable function.
|
Timing |
step(java.lang.String name,
ProfileLevel level)
Start a new profiling step with the given level;
|
<T> T |
step(java.lang.String name,
ProfileLevel level,
java.util.concurrent.Callable<T> function)
Start and stop a new profiling step with the given block.
|
void |
step(java.lang.String name,
ProfileLevel level,
java.lang.Runnable block)
Start and stop a new profiling step with the given block.
|
void |
step(java.lang.String name,
java.lang.Runnable block)
Start and stop a new profiling step with the given block.
|
void |
stop()
Stop the current timing session.
|
void |
stop(boolean discardResults)
Stop the current timing session.
|
public static final NullProfiler INSTANCE
public Timing step(java.lang.String name)
Profiler
ProfileLevel.Info
level;public Timing step(java.lang.String name, ProfileLevel level)
Profiler
public void step(java.lang.String name, java.lang.Runnable block)
Profiler
public void step(java.lang.String name, ProfileLevel level, java.lang.Runnable block)
Profiler
public <T> T step(java.lang.String name, java.util.concurrent.Callable<T> function) throws java.lang.Exception
Profiler
public <T> T step(java.lang.String name, ProfileLevel level, java.util.concurrent.Callable<T> function) throws java.lang.Exception
Profiler
step
in interface Profiler
T
- the return type of the functionname
- The name of the step.level
- The profiling level for this stepfunction
- The function to timejava.lang.Exception
- when the function throws an exceptionpublic void addCustomTiming(java.lang.String type, java.lang.String executeType, java.lang.String command, long duration)
Profiler
addCustomTiming
in interface Profiler
type
- the type of query, e.g. sql, memcache etcexecuteType
- the type of command executed, e.g. read, fetch, update etccommand
- the query to saveduration
- how long it took, in millisecondspublic CustomTiming customTiming(java.lang.String type, java.lang.String executeType, java.lang.String command)
Profiler
The custom timing will not have a duration until CustomTiming.stop()
is called on the returned object.
customTiming
in interface Profiler
type
- type of timing, e.g. "sql"executeType
- what type of execution, e.g. "query"command
- e.g. "select * from foo"public void customTiming(java.lang.String type, java.lang.String executeType, java.lang.String command, java.lang.Runnable block)
Profiler
customTiming
in interface Profiler
type
- type of timing, e.g. "sql"executeType
- what type of execution, e.g. "query"command
- e.g. "select * from foo"block
- the code to runpublic <T> T customTiming(java.lang.String type, java.lang.String executeType, java.lang.String command, java.util.concurrent.Callable<T> function) throws java.lang.Exception
Profiler
customTiming
in interface Profiler
T
- the return type of the functiontype
- type of timing, e.g. "sql"executeType
- what type of execution, e.g. "query"command
- e.g. "select * from foo"function
- The function to timejava.lang.Exception
- when the function throws an exceptionpublic void close()
Profiler
Profiler.stop()
.
Here to satisfy Closeable
and mark the method as not throwing a checked exception.
public void stop()
Profiler
public void stop(boolean discardResults)
Profiler
public java.lang.String asUiJson()
Profiler
public java.lang.String asPlainText()
Profiler
asPlainText
in interface Profiler
public java.util.UUID getId()
Profiler
public Timing getHead()
Profiler
public Timing getRoot()
Profiler
public void setUser(java.lang.String user)
Profiler
public java.lang.String getUser()
Profiler