Package net.obvj.performetrics
Class TimingSessionContainer
- java.lang.Object
-
- net.obvj.performetrics.TimingSessionContainer
-
- Direct Known Subclasses:
MonitoredCallable,MonitoredRunnable,Stopwatch
public abstract class TimingSessionContainer extends Object
An object that maintains multiple timing sessions for different counter types, and provides methods to retrieve elapsed times is different formats.- Since:
- 2.5.0
- Author:
- oswaldo.bapvic.jr
- See Also:
TimingSession
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DurationelapsedTime()Returns the total elapsed time for a single counter type, provided that this object is keeping a single type.doubleelapsedTime(TimeUnit timeUnit)Returns the total elapsed time in the specified time unit for a single counter type, provided that this object is keeping a single type.doubleelapsedTime(TimeUnit timeUnit, ConversionMode conversionMode)Returns the total elapsed time in the specified time unit for a single counter type, provided that this object is keeping a single type.DurationelapsedTime(Counter.Type type)Returns the total elapsed time for a specific counter type.doubleelapsedTime(Counter.Type type, TimeUnit timeUnit)Returns the total elapsed time for a specific counter type, in the specified time unit.doubleelapsedTime(Counter.Type type, TimeUnit timeUnit, ConversionMode conversionMode)Returns the total elapsed time for a specific counter type, in the specified time unit, with a customConversionModeapplied.Map<Counter.Type,List<Counter>>getAllCountersByType()Returns a map of counters grouped by type, where each entry in the counters list represents a timing session.List<Counter>getCounters(Counter.Type type)Returns a list of available counters for a specific type in this object, or an empty list if no counter is found -- for example, if no timing session was started, or after callingreset().List<Counter.Type>getTypes()Returns the counter types associated with this object.TimingSessionlastSession()Returns the current/last timing session recorded in this object.voidprint(PrintStream printStream)Prints elapsed times in the specified print stream.voidprint(PrintStream printStream, PrintStyle printStyle)Prints elapsed times in the specified print stream with a customPrintStyle.voidprintDetails(PrintStream printStream)Prints detailed information about timing sessions in the specified print stream.voidprintDetails(PrintStream printStream, PrintStyle printStyle)Prints detailed information about timing sessions in the specified print stream, with a customPrintStyle.voidprintSummary(PrintStream printStream)Prints summarized elapsed times in the specified print stream.voidprintSummary(PrintStream printStream, PrintStyle printStyle)Prints summarized elapsed times in the specified print stream, with a customPrintStyle.voidreset()Cleans all timing sessions in this object.StringtoString()Returns a string containing a formatted output for this timing-session container in default style.StringtoString(PrintStyle printStyle)Returns a string containing a formatted output for this timing-session container in a customPrintStyle.
-
-
-
Method Detail
-
reset
public void reset()
Cleans all timing sessions in this object.
-
getTypes
public List<Counter.Type> getTypes()
Returns the counter types associated with this object.- Returns:
- a list of counter types associated with this object
- See Also:
Counter.Type
-
getAllCountersByType
public Map<Counter.Type,List<Counter>> getAllCountersByType()
Returns a map of counters grouped by type, where each entry in the counters list represents a timing session.- Returns:
- a map of populated counters grouped by type
- Since:
- 2.2.1
- See Also:
Counter
-
getCounters
public List<Counter> getCounters(Counter.Type type)
Returns a list of available counters for a specific type in this object, or an empty list if no counter is found -- for example, if no timing session was started, or after callingreset().- Parameters:
type- the counter type to be fetched- Returns:
- a list of counters associated with the given type, or an empty list
- Throws:
IllegalArgumentException- if the specified type was not assigned to this object during instantiation- Since:
- 2.2.0
- See Also:
Counter
-
elapsedTime
public Duration elapsedTime()
Returns the total elapsed time for a single counter type, provided that this object is keeping a single type.- Returns:
- the elapsed time for a single counter type in this object
- Throws:
IllegalStateException- if the object is keeping more than one counter type- Since:
- 2.2.4
-
elapsedTime
public double elapsedTime(TimeUnit timeUnit)
Returns the total elapsed time in the specified time unit for a single counter type, provided that this object is keeping a single type.- Parameters:
timeUnit- the time unit to which the elapsed time will be converted- Returns:
- the elapsed time for a single counter type in this object, converted to the given time unit with the default conversion mode
- Throws:
IllegalStateException- if the object is keeping more than one counter type- Since:
- 2.2.4
-
elapsedTime
public double elapsedTime(TimeUnit timeUnit, ConversionMode conversionMode)
Returns the total elapsed time in the specified time unit for a single counter type, provided that this object is keeping a single type.- Parameters:
timeUnit- the time unit to which the elapsed time will be convertedconversionMode- theConversionModeto be applied- Returns:
- the elapsed time for a single counter type in this object, converted to the given time unit with the given conversion mode
- Throws:
IllegalStateException- if the object is keeping more than one counter type- Since:
- 2.2.4
-
elapsedTime
public Duration elapsedTime(Counter.Type type)
Returns the total elapsed time for a specific counter type.- Parameters:
type- the counter type to be fetched- Returns:
- the elapsed time for the specified counter
- Throws:
IllegalArgumentException- if the specified type was not assigned to this object during instantiation- Since:
- 2.1.0
-
elapsedTime
public double elapsedTime(Counter.Type type, TimeUnit timeUnit)
Returns the total elapsed time for a specific counter type, in the specified time unit.- Parameters:
type- the counter type to be fetchedtimeUnit- the time unit to which the elapsed time will be converted- Returns:
- the elapsed time for the specified counter, converted to the given time unit with the default conversion mode.
- Throws:
IllegalArgumentException- if the specified type was not assigned to this object during instantiation- Since:
- 2.1.0
-
elapsedTime
public double elapsedTime(Counter.Type type, TimeUnit timeUnit, ConversionMode conversionMode)
Returns the total elapsed time for a specific counter type, in the specified time unit, with a customConversionModeapplied.- Parameters:
type- the counter type to be fetchedtimeUnit- the time unit to which the elapsed time will be convertedconversionMode- theConversionModeto be applied- Returns:
- the elapsed time for the specified counter, converted to the given time unit with the given conversion mode.
- Throws:
IllegalArgumentException- if the specified type was not assigned to this object during instantiation- Since:
- 2.1.0
-
print
public void print(PrintStream printStream)
Prints elapsed times in the specified print stream.The default
PrintStyle(defined byPerformetrics.setDefaultPrintStyle(PrintStyle)) will be applied.For a custom
PrintStyle, useprint(PrintStream, PrintStyle).- Parameters:
printStream- the print stream to which data will be sent- Throws:
NullPointerException- if thePrintStreamis null- Since:
- 2.4.0
-
print
public void print(PrintStream printStream, PrintStyle printStyle)
Prints elapsed times in the specified print stream with a customPrintStyle.The format (whether to generate a summarized or detailed view) will be determined by the specified
PrintStyle.- Parameters:
printStream- the print stream to which data will be sentprintStyle- thePrintStyle; ifnull, the defaultPrintStyle(defined byPerformetrics.setDefaultPrintStyle(PrintStyle)) will be applied- Throws:
NullPointerException- if thePrintStreamis null- Since:
- 2.4.0
-
printSummary
public void printSummary(PrintStream printStream)
Prints summarized elapsed times in the specified print stream.- Parameters:
printStream- the print stream to which data will be sent- Throws:
NullPointerException- if thePrintStreamis null- Since:
- 2.2.1
-
printSummary
public void printSummary(PrintStream printStream, PrintStyle printStyle)
Prints summarized elapsed times in the specified print stream, with a customPrintStyle.- Parameters:
printStream- the print stream to which data will be sentprintStyle- thePrintStyleto be applied- Throws:
NullPointerException- if thePrintStreamis nullIllegalArgumentException- if the specifiedPrintStyleis not compatible withPrintFormat.SUMMARIZED- Since:
- 2.2.1
-
printDetails
public void printDetails(PrintStream printStream)
Prints detailed information about timing sessions in the specified print stream.- Parameters:
printStream- the print stream to which information will be sent- Throws:
NullPointerException- if thePrintStreamis null- Since:
- 2.2.1
-
printDetails
public void printDetails(PrintStream printStream, PrintStyle printStyle)
Prints detailed information about timing sessions in the specified print stream, with a customPrintStyle.- Parameters:
printStream- the print stream to which information will be sentprintStyle- thePrintStyleto be applied- Throws:
NullPointerException- if thePrintStreamis nullIllegalArgumentException- if the specifiedPrintStyleis not compatible withPrintFormat.DETAILED- Since:
- 2.2.1
-
lastSession
public TimingSession lastSession()
Returns the current/last timing session recorded in this object.- Returns:
- the current/last timing session available in this object
- Throws:
IllegalStateException- if the object does not contain any recorded session- Since:
- 2.4.0
-
toString
public String toString()
Returns a string containing a formatted output for this timing-session container in default style.The default
PrintStyle(defined byPerformetrics.setDefaultPrintStyle(PrintStyle)) will be applied.For a custom
PrintStyle, usetoString(PrintStyle).
-
toString
public String toString(PrintStyle printStyle)
Returns a string containing a formatted output for this timing-session container in a customPrintStyle.The
PrintFormat(whether to generate a summarized or detailed view) will be determined by the specifiedPrintStyle.- Parameters:
printStyle- thePrintStyle; ifnull, the defaultPrintStyle(defined byPerformetrics.setDefaultPrintStyle(PrintStyle)) will be applied- Returns:
- a string containing a formatted output for this timing-session container in the
specified
PrintStyle - Since:
- 2.4.0
-
-