public interface Profiler
extends java.io.Closeable
Typical usage involves starting a profiling session by calling
ProfilerProvider.start(String, ProfileLevel) or
MiniProfiler.start(String, ProfileLevel). A profiling session
should be stopped by calling stop(). Typically this might be
done in a finally block around some code:
Profiler profiler = MiniProfiler.start("/my/uri", Info);
try {
// do stuff here
} finally {
profiler.stop();
}
or, since the interface implements Closeable, you can use
Java 7 ARM blocks:
try(Profiler profiler = profilerProvider.start("/my/uri", Info)) {
// do stuff here
}
Individual profiling steps can then be added by calling
step(String, ProfileLevel). Usually it would be necessary
to get a handle on the current profiler first, using either
ProfilerProvider.current()
or MiniProfiler.current().
try(Timing profiler = profilerProvider.current().step("Some complicated step", Info)) {
// do stuff here
}
Calls can be nested, and nested steps will be displayed indented in the UI.
try(Timing profiler = profilerProvider.current().step("Some complicated step", Info)) {
// do stuff here
try(Timing profiler = profilerProvider.current().step("Another step inside that one!", Info)) {
// do stuff here
}
}
| 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
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.
|
Timing step(java.lang.String name)
ProfileLevel.Info level;name - The name of the step.Timing step(java.lang.String name, ProfileLevel level)
name - The name of the step.level - the profiling level for this stepvoid step(java.lang.String name,
java.lang.Runnable block)
name - The name of the step.block - The block to timevoid step(java.lang.String name,
ProfileLevel level,
java.lang.Runnable block)
name - The name of the step.level - The profiling level for this stepblock - The block to time<T> T step(java.lang.String name,
java.util.concurrent.Callable<T> function)
throws java.lang.Exception
T - the return type of the functionname - The name of the step.function - The function to timejava.lang.Exception - when the function throws an exception<T> T step(java.lang.String name,
ProfileLevel level,
java.util.concurrent.Callable<T> function)
throws java.lang.Exception
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 exceptionvoid addCustomTiming(java.lang.String type,
java.lang.String executeType,
java.lang.String command,
long duration)
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 millisecondsCustomTiming customTiming(java.lang.String type, java.lang.String executeType, java.lang.String command)
The custom timing will not have a duration until CustomTiming.stop() is called on the returned object.
type - type of timing, e.g. "sql"executeType - what type of execution, e.g. "query"command - e.g. "select * from foo"void customTiming(java.lang.String type,
java.lang.String executeType,
java.lang.String command,
java.lang.Runnable block)
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 run<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
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 exceptionvoid stop()
void stop(boolean discardResults)
discardResults - whether to skip storing the current session datavoid close()
stop().
Here to satisfy Closeable and mark the method as not throwing a checked exception.
close in interface java.lang.AutoCloseableclose in interface java.io.Closeablejava.util.UUID getId()
Timing getHead()
Timing getRoot()
void setUser(java.lang.String user)
user - the userjava.lang.String getUser()
Profiler addChild(java.lang.String name)
name - The name to give the child profilerjava.lang.String asUiJson()
java.lang.String asPlainText()