public class ProfilerImpl extends java.lang.Object implements Profiler, java.io.Serializable, Jsonable
Generally users of the library will not need to
interact directly with this class, instead getting references to the current
profiler through MiniProfiler.start(String)
,
MiniProfiler.current()
,
ProfilerProvider.start(String)
and
MiniProfiler.current()
, and then
just treating it as a Profiler
.
However, writers of custom ProfilerProvider
implementations may
need to construct a new profiler by calling
ProfilerImpl(String, ProfileLevel, ProfilerProvider)
.
Constructor and Description |
---|
ProfilerImpl(java.util.UUID id,
java.lang.String name,
java.lang.String rootName,
ProfileLevel level,
ProfilerProvider profilerProvider)
Construct a new profiling session.
|
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.
|
ProfileLevel |
getLevel() |
java.lang.String |
getMachineName() |
Timing |
getRoot()
Returns the root timing for this profiler.
|
java.lang.String |
getUser()
Returns the user name for the profile session.
|
boolean |
hasQueryTimings() |
void |
setHasQueryTimings(boolean hasQueryTimings) |
void |
setMachineName(java.lang.String machineName) |
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.
|
java.util.LinkedHashMap<java.lang.String,java.lang.Object> |
toMap() |
public ProfilerImpl(java.util.UUID id, java.lang.String name, java.lang.String rootName, ProfileLevel level, ProfilerProvider profilerProvider)
This will create an implicit root Timing
step considered to have
started now, with the given root name.
A new random UUID id is created for every profiler.
Any profiling steps more verbose than the given level will be ignored.
The profiler provider constructing the profiler is passed in so that
when stop()
is called, the profiler can notify the provider to store
the profiling info for later retrieval via
ProfilerProvider.stopSession(ProfilerImpl, boolean)
.
id
- the id to use, or null to generate a random uuidname
- name of the requestrootName
- name of the root timing step to startlevel
- the level of the profilerprofilerProvider
- the profiler provider constructing thepublic void stop()
Profiler
public void stop(boolean discardResults)
Profiler
public Timing step(java.lang.String name, ProfileLevel level)
Profiler
public Timing step(java.lang.String name)
Profiler
ProfileLevel.Info
level;public void step(java.lang.String name, ProfileLevel level, java.lang.Runnable block)
Profiler
public void step(java.lang.String name, java.lang.Runnable block)
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 <T> T step(java.lang.String name, java.util.concurrent.Callable<T> function) throws java.lang.Exception
Profiler
public 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 java.util.LinkedHashMap<java.lang.String,java.lang.Object> toMap()
public java.lang.String asUiJson()
Profiler
public java.lang.String asPlainText()
asPlainText
in interface Profiler
public java.util.UUID getId()
Profiler
public java.lang.String getMachineName()
public void setMachineName(java.lang.String machineName)
public ProfileLevel getLevel()
public Timing getRoot()
Profiler
public boolean hasQueryTimings()
public Timing getHead()
Profiler
public java.lang.String getUser()
Profiler
public void setUser(java.lang.String user)
Profiler
public void setHasQueryTimings(boolean hasQueryTimings)
public void close()
Profiler
Profiler.stop()
.
Here to satisfy Closeable
and mark the method as not throwing a checked exception.