Public Member Functions

alma.acs.util.StopWatch Class Reference

Inheritance diagram for alma.acs.util.StopWatch:
alma.acs.time.Profiler

List of all members.

Public Member Functions

 StopWatch ()
 StopWatch (Logger logger)
void setLogger (Logger logger)
void reset ()
StopWatch createStopWatchForSubtask (String newSubtaskName)
Date getStartTime ()
void stop ()
long getLapTimeMillis ()
String formattedMillis ()
long getLapTimeNanos ()
void logLapTime (String taskDesc)
void logLapTime (String taskDesc, Level logLevel)
void logLapTimeWithSubtaskDetails (String taskDesc, Level logLevel)
String getSubtaskDetails ()

Detailed Description

Class that facilitates elapsed-time runtime profiling. For per-thread time profiling better use an external profiler.

This class requires external synchronization if used from different threads.

About system clock issues and the JVM, see https://blogs.oracle.com/dholmes/entry/inside_the_hotspot_vm_clocks

Over the years also other open source libs have developed similar classes, but as of ACS 12.2 we do not see a need to replace our StopWatch or change its API. See http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Stopwatch.html, http://jamonapi.sourceforge.net/, http://commons.apache.org/proper/commons-lang/javadocs/api-release/index.html?org/apache/commons/lang3/time/StopWatch.html

Author:
hsommer May 7, 2003 2:18:39 PM

Constructor & Destructor Documentation

alma.acs.util.StopWatch.StopWatch (  ) 

Ctor without logger provided. Either call setLogger later, or logs will be printed to stdout.

Referenced by alma.acs.util.StopWatch.createStopWatchForSubtask().

alma.acs.util.StopWatch.StopWatch ( Logger  logger  ) 

Constructor that resets the time count.

Parameters:
logger the logger to be used in logLapTime(String). If null, logs will be printed to stdout.

Member Function Documentation

StopWatch alma.acs.util.StopWatch.createStopWatchForSubtask ( String  newSubtaskName  ) 

Creates a StopWatch for a subtask. The returned StopWatch can be used to profile blocks of code to get a single log in the end that contains details about how the total time was spent. The returned StopWatch can be used to create more sub-StopWatches, which is convenient if you pass it to a called method which itself uses subtask timing.
When a subtask is done, you must call stop() on the subtask's StopWatch.

Do not expect that subtask elapsed times add up exactly to the total elapsed time. The system-dependent timing granularity does not allow this.

References alma.acs.util.StopWatch.StopWatch().

Referenced by alma.acs.logging.AcsLogger.log(), alma.acs.logging.StdOutConsoleHandler.publish(), and alma.acs.logging.AcsLoggingHandler.publish().

String alma.acs.util.StopWatch.formattedMillis (  ) 

Converts getLapTimeNanos() to fractional milliseconds, using the format from millisecFormatter.

References alma.acs.util.StopWatch.getLapTimeNanos().

long alma.acs.util.StopWatch.getLapTimeMillis (  ) 

Gets the time in milliseconds that has elapsed since this object was created or reset() was called.

The implementation relies on System.nanoTime(), so that the granularity of measurements is OS dependent and can be more than one ms. Also, note that the time spent on all threads together is returned, which might be a poor measure for runtime profiling of a particular method.

Returns:
elapsed time in milliseconds

References alma.acs.util.StopWatch.getLapTimeNanos().

Referenced by alma.acs.container.AcsContainer.activate_component(), alma.COUNTER.CounterConsumerImpl.CounterConsumerImpl.cleanUp(), alma.acs.container.corba.AcsCorba.deactivateComponentPOAManager(), com.cosylab.cdb.jdal.DALImpl.loadRecords(), alma.acs.profiling.orb.OrbProfilerParser.parse(), alma.acs.nc.AcsEventSubscriberImplBase< T >.processEvent(), and alma.acs.monitoring.blobber.BlobberWorker.run().

long alma.acs.util.StopWatch.getLapTimeNanos (  ) 

Gets the time in nanoseconds that has elapsed since this object was created or reset() was called.

The implementation simply relies on System.nanoTime(), so that the granularity of measurements is OS dependent. Also, note that the time spent on all threads together is returned, which might be a poor measure for runtime profiling a particular method.

Returns:
elapsed time in nanoseconds

Referenced by alma.acs.util.StopWatch.formattedMillis(), alma.acs.util.StopWatch.getLapTimeMillis(), and alma.acs.logging.AcsLogger.log().

Date alma.acs.util.StopWatch.getStartTime (  ) 

Returns the time when this StopWatch was created / started. This method can be useful for log output, to later correlate the profiled elapsed time with other occurrences in the system.

Referenced by alma.acs.logging.AcsLogger.log().

String alma.acs.util.StopWatch.getSubtaskDetails (  ) 

Gets the subtask timing data as a string. The returned String has the same format that is also used in logLapTimeWithSubtaskDetails(String, Level).

Referenced by alma.acs.logging.AcsLogger.log().

void alma.acs.util.StopWatch.logLapTime ( String  taskDesc  ) 

Logs a message about the elapsed time for a certain task. It uses log level Level.FINE and inserts the supplied description: "<code>elapsed time in ms to </code><i>taskDescription</i><code>: </code><i>elapsed-time</i>".

If no logger has been supplied, it will get one using Logger#getLogger(java.lang.String). This ad-hoc logger will likely not work in an ACS environment where log handlers are configured for the needs of containers and remote logging.

todo: provide nicer text mask for message

Parameters:
taskDesc the message to be include in the standard message which should describe the task for which the lap time is taken.
See also:
getLapTimeMillis()

Referenced by alma.acs.eventbrowser.parts.PopulateEventList.getThreadForEventList(), alma.acs.util.StopWatch.logLapTime(), alma.acs.util.StopWatch.logLapTimeWithSubtaskDetails(), and alma.acs.monitoring.blobber.BlobberWorker.run().

void alma.acs.util.StopWatch.logLapTime ( String  taskDesc,
Level  logLevel 
)

Variant of logLapTime(String) that allows the user to specify the log level. Generally the FINE (=DEBUG) level is appropriate for performance logs, but in special cases such as unit tests it can be necessary to log at INFO or other levels.

References alma.acs.util.StopWatch.logLapTime().

void alma.acs.util.StopWatch.logLapTimeWithSubtaskDetails ( String  taskDesc,
Level  logLevel 
)
Since:
ACS 12.3

References alma.acs.util.StopWatch.logLapTime().

void alma.acs.util.StopWatch.setLogger ( Logger  logger  ) 
void alma.acs.util.StopWatch.stop (  ) 

Stops the StopWatch. This method must be called for subtask StopWatches (see createStopWatchForSubtask(String)). It is optional in case of top-level StopWatches where it makes little difference whether or not we first stop the watch right before retrieving or logging the lap time.

This method can be called more than once without (side) effects.

Reimplemented in alma.acs.time.Profiler.

Referenced by alma.acs.logging.AcsLogger.log(), alma.acs.logging.StdOutConsoleHandler.publish(), and alma.acs.logging.AcsLoggingHandler.publish().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Enumerations Properties