public interface ProfilerProvider
If your system uses any form of dependency injection, the usual
way to do things is to inject a ProfilerProvider instance into
anything that need to be profiled, which can then call
getCurrent()
to get a handle on the current
provider and add timing steps.
The profiler provider would also need to be injected into an
entry point in the program - in a servlet environment this would
usually be a servlet filter. An example is the provided
ProfilingFilter
.
If your system doesn't use dependency injection, then code starting
a new session should call MiniProfiler.start(String)
and
MiniProfiler.current()
,
which defers to a static profiler provider instance. That
instance can be set using
MiniProfiler.setProfilerProvider(ProfilerProvider)
.
Modifier and Type | Method and Description |
---|---|
Profiler |
current()
Returns the current MiniProfiler.
|
Profiler |
getCurrent()
A properties-friendly version of
current() . |
Storage |
getStorage()
Returns the
Storage associated with this provider. |
ProfilerUiConfig |
getUiConfig()
Returns the
ProfilerUiConfig associated with this provider. |
boolean |
hasCurrent()
Return true if there is a current profiler.
|
void |
setStorage(Storage storage)
Sets the
Storage for this provider to use. |
void |
setUiConfig(ProfilerUiConfig uiConfig)
Sets the
ProfilerUiConfig for this provider to use. |
Profiler |
start(java.lang.String rootName)
Start a new profiling session with the default
ProfileLevel.Info level. |
Profiler |
start(java.lang.String rootName,
ProfileLevel level)
Start a new profiling session with the given level.
|
Profiler |
start(java.util.UUID id,
java.lang.String rootName)
Start a new profiling session with the default
ProfileLevel.Info level. |
Profiler |
start(java.util.UUID id,
java.lang.String rootName,
ProfileLevel level)
Start a new profiling session with the given level, root name and UUID.
|
void |
stopCurrentSession(boolean discardResults)
Ends the current profiling session, if one exists.
|
void |
stopSession(ProfilerImpl profilingSession,
boolean discardResults)
Marks the given profiling session as stopped.
|
Profiler start(java.lang.String rootName)
ProfileLevel.Info
level.rootName
- the name of the root timing step. This might often be the uri of the current request.Profiler start(java.util.UUID id, java.lang.String rootName)
ProfileLevel.Info
level.id
- the UUID to userootName
- the name of the root timing step. This might often be the uri of the current request.Profiler start(java.lang.String rootName, ProfileLevel level)
rootName
- the name of the root timing step. This might often be the uri of the current request.level
- the level of the profiling sessionProfiler start(java.util.UUID id, java.lang.String rootName, ProfileLevel level)
id
- the UUID to userootName
- the name of the root timing step. This might often be the uri of the current request.level
- the level of the profiling sessionvoid stopCurrentSession(boolean discardResults)
Generally it is preferrable to stop a profiling session by
calling Profiler.stop()
, but in some circumstances
it may be easier to call this method.
discardResults
- When true, clears the miniprofiler for this request, allowing profiling to
be prematurely stopped and discarded. Useful for when a specific route does not need to be profiled.void stopSession(ProfilerImpl profilingSession, boolean discardResults)
ProfilerImpl.stop()
method. End users do not need to call it. Only public so that
custom ProfilerProviders can be developed.profilingSession
- the profiler to register as stoppeddiscardResults
- When true, clears the miniprofiler for this request, allowing profiling to
be prematurely stopped and discarded. Useful for when a specific route does not need to be profiled.Profiler current()
This method should never return null. If there is no current profiling session,
a NullProfiler
instance will be returned so that calling code does not
have to do null checks around every timing block.
Profiler getCurrent()
current()
.boolean hasCurrent()
Storage getStorage()
Storage
associated with this provider.void setStorage(Storage storage)
Storage
for this provider to use.storage
- the storage to useProfilerUiConfig getUiConfig()
ProfilerUiConfig
associated with this provider.void setUiConfig(ProfilerUiConfig uiConfig)
ProfilerUiConfig
for this provider to use.uiConfig
- the UI config to use