Class PerformanceStats
Each performance event can have an associated maximum acceptable duration that is specified in the platform debug options file (.options). Events that take longer than this maximum are logged as errors. Along with option file entries for each debug event, there are some global debug options for enabling or disabling performance event gathering and reporting. See the "org.eclipse.core.runtime/perf*" debug options in the .options file for the org.eclipse.core.runtime plugin for more details.
A performance event can optionally have additional context information
(getContext()
). This information is only stored in the case
of a performance failure, and can be used to provide further diagnostic
information that can help track down the cause of the failure.
Performance events and performance failures are batched up and periodically sent to interested performance event listeners.
This class is not intended to be subclassed or instantiated by clients.
- Since:
- 3.1
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A performance listener is periodically notified after performance events occur or after events fail. -
Field Summary
Modifier and TypeFieldDescriptionstatic final boolean
Constant indicating whether or not tracing is enabled -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Adds a listener that is notified when performance events occur.void
Adds an occurrence of this event to the cumulative counters.static void
clear()
Discards all known performance event statistics.void
endRun()
Stops timing the occurrence of this event that was started by the previous call tostartRun
.boolean
static PerformanceStats[]
Returns all performance event statistics.getBlame()
Returns an object that can be used to figure out who caused the event, or a string describing the cause of the event.Returns a string describing the blame for this event.Returns the optional event context, such as the input of an editor, or the target project of a build event.getEvent()
Returns the symbolic name of the event that occurred.int
Returns the total number of times this event has occurred.long
Returns the total execution time in milliseconds for all occurrences of this event.static PerformanceStats
Returns the stats object corresponding to the given parameters.int
hashCode()
static boolean
Returns whether monitoring of a given performance event is enabled.boolean
Returns whether this performance event represents a performance failure.static void
Prints all statistics to the standard output.static void
printStats
(PrintWriter out) Writes all statistics using the provided writerstatic void
Removes an event listener.static void
removeStats
(String eventName, Object blameObject) Removes statistics for a given event and blamevoid
reset()
Resets count and running time for this particular stats event.void
startRun()
Starts timing an occurrence of this event.void
Starts timing an occurrence of this event.toString()
For debugging purposes only.
-
Field Details
-
ENABLED
public static final boolean ENABLEDConstant indicating whether or not tracing is enabled
-
-
Method Details
-
addListener
Adds a listener that is notified when performance events occur. If an equal listener is already installed, it will be replaced.- Parameters:
listener
- The listener to be added- See Also:
-
clear
public static void clear()Discards all known performance event statistics. -
getAllStats
Returns all performance event statistics.- Returns:
- An array of known performance event statistics. The array will be empty if there are no recorded statistics.
-
getStats
Returns the stats object corresponding to the given parameters. A stats object is created and added to the global list of events if it did not already exist.- Parameters:
eventName
- A symbolic event name. This is usually the name of the debug option for this event. An example event name from the org.eclipse.core.resources plugin describing a build event might look like:"org.eclipse.core.resources/perf/building"
"blameObject
- The blame for the event. This is typically the object whose code was running when the event occurred. If a blame object cannot be obtained, aString
describing the event should be supplied
-
isEnabled
Returns whether monitoring of a given performance event is enabled.For frequent performance events, the result of this method call should be cached by the caller to minimize overhead when performance monitoring is turned off. It is not possible for enablement to change during the life of this invocation of the platform.
- Parameters:
eventName
- The name of the event to determine enablement for- Returns:
true
If the performance event with the given name is enabled, andfalse
otherwise.
-
printStats
public static void printStats()Prints all statistics to the standard output. -
printStats
Writes all statistics using the provided writer- Parameters:
out
- The writer to print stats to.
-
removeListener
Removes an event listener. Has no effect if an equal listener object is not currently registered.- Parameters:
listener
- The listener to remove- See Also:
-
removeStats
Removes statistics for a given event and blame- Parameters:
eventName
- The name of the event to removeblameObject
- The blame for the event to remove
-
addRun
Adds an occurrence of this event to the cumulative counters. This method can be used as an alternative tostartRun
andendRun
for clients that want to track the context and execution time separately.- Parameters:
elapsed
- The elapsed time of the new occurrence in millisecondscontextName
- The context for the event to return, ornull
. The context optionally provides extra information about an event, such as the name of a project being built, or the input of an editor being opened.
-
endRun
public void endRun()Stops timing the occurrence of this event that was started by the previous call tostartRun
. The event is automatically added to the cumulative counters for this event and listeners are notified.Note that this facility guards itself against runs that start but fail to stop, so it is not necessary to call this method from a finally block. Tracking performance of failure cases is generally not of interest.
- See Also:
-
equals
-
getBlame
Returns an object that can be used to figure out who caused the event, or a string describing the cause of the event.- Returns:
- The blame for this event
-
getBlameString
Returns a string describing the blame for this event.- Returns:
- A string describing the blame.
-
getContext
Returns the optional event context, such as the input of an editor, or the target project of a build event.- Returns:
- The context, or
null
if there is none
-
getEvent
Returns the symbolic name of the event that occurred.- Returns:
- The name of the event.
-
getRunCount
public int getRunCount()Returns the total number of times this event has occurred.- Returns:
- The number of occurrences of this event.
-
getRunningTime
public long getRunningTime()Returns the total execution time in milliseconds for all occurrences of this event.- Returns:
- The total running time in milliseconds.
-
hashCode
public int hashCode() -
isFailure
public boolean isFailure()Returns whether this performance event represents a performance failure.- Returns:
true
if this is a performance failure, andfalse
otherwise.
-
reset
public void reset()Resets count and running time for this particular stats event. -
startRun
public void startRun()Starts timing an occurrence of this event. This is a convenience method, fully equivalent tostartRun(null)
. -
startRun
Starts timing an occurrence of this event. The event should be stopped by a subsequent call toendRun
.- Parameters:
contextName
- The context for the event to return, ornull
. The context optionally provides extra information about an event, such as the name of a project being built, or the input of an editor being opened.- See Also:
-
toString
For debugging purposes only.
-