public class PerformanceStats extends Object
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.
Modifier and Type | Class and Description |
---|---|
static class |
PerformanceStats.PerformanceListener
A performance listener is periodically notified after performance events occur
or after events fail.
|
Modifier and Type | Field and Description |
---|---|
static boolean |
ENABLED
Constant indicating whether or not tracing is enabled
|
Modifier and Type | Method and Description |
---|---|
static void |
addListener(PerformanceStats.PerformanceListener listener)
Adds a listener that is notified when performance events occur.
|
void |
addRun(long elapsed,
String contextName)
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 to
startRun . |
boolean |
equals(Object obj) |
static PerformanceStats[] |
getAllStats()
Returns all performance event statistics.
|
Object |
getBlame()
Returns an object that can be used to figure out who caused the event,
or a string describing the cause of the event.
|
String |
getBlameString()
Returns a string describing the blame for this event.
|
String |
getContext()
Returns the optional event context, such as the input of an editor, or the target project
of a build event.
|
String |
getEvent()
Returns the symbolic name of the event that occurred.
|
int |
getRunCount()
Returns the total number of times this event has occurred.
|
long |
getRunningTime()
Returns the total execution time in milliseconds for all occurrences
of this event.
|
static PerformanceStats |
getStats(String eventName,
Object blameObject)
Returns the stats object corresponding to the given parameters.
|
int |
hashCode() |
static boolean |
isEnabled(String eventName)
Returns whether monitoring of a given performance event is enabled.
|
boolean |
isFailure()
Returns whether this performance event represents a performance failure.
|
static void |
printStats()
Prints all statistics to the standard output.
|
static void |
printStats(PrintWriter out)
Writes all statistics using the provided writer
|
static void |
removeListener(PerformanceStats.PerformanceListener listener)
Removes an event listener.
|
static void |
removeStats(String eventName,
Object blameObject)
Removes statistics for a given event and blame
|
void |
reset()
Resets count and running time for this particular stats event.
|
void |
startRun()
Starts timing an occurrence of this event.
|
void |
startRun(String contextName)
Starts timing an occurrence of this event.
|
String |
toString()
For debugging purposes only.
|
public static final boolean ENABLED
public static void addListener(PerformanceStats.PerformanceListener listener)
listener
- The listener to be addedremoveListener(PerformanceStats.PerformanceListener)
public static void clear()
public static PerformanceStats[] getAllStats()
public static PerformanceStats getStats(String eventName, Object blameObject)
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, a String
describing the event should be suppliedpublic static boolean isEnabled(String eventName)
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.
eventName
- The name of the event to determine enablement fortrue
If the performance event with the given
name is enabled, and false
otherwise.public static void printStats()
public static void printStats(PrintWriter out)
out
- The writer to print stats to.public static void removeListener(PerformanceStats.PerformanceListener listener)
listener
- The listener to removeaddListener(PerformanceStats.PerformanceListener)
public static void removeStats(String eventName, Object blameObject)
eventName
- The name of the event to removeblameObject
- The blame for the event to removepublic void addRun(long elapsed, String contextName)
startRun
and endRun
for clients that want to track the context and execution time separately.elapsed
- The elapsed time of the new occurrence in millisecondscontextName
- The context for the event to return, or null
.
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.public void endRun()
startRun
. 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.
startRun()
public Object getBlame()
public String getBlameString()
public String getContext()
null
if there is nonepublic String getEvent()
public int getRunCount()
public long getRunningTime()
public boolean isFailure()
true
if this is a performance failure, and
false
otherwise.public void reset()
public void startRun()
startRun(null)
.public void startRun(String contextName)
endRun
.contextName
- The context for the event to return, or null
.
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()
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.