Package org.djutils.profile
Class Profile
- java.lang.Object
-
- org.djutils.profile.Profile
-
public final class Profile extends Object
Utility class to profile code execution times.
Insert a call to one of thestart
methods at the start of each method (or part thereof) that must be timed and a call to one of theend
methods at the end of the part to profile or right before every return statement of each of those methods.
The collected statistics information can be retrieved with thestatistics
method.
To output statistics at (somewhat) regular intervals callprint
method often. The default interval is 1 second; this can be changed by calling thesetPrintInterval method
.Copyright (c) 2013-2021 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.- Version:
- $Revision$, $LastChangedDate$, by $Author$, initial version 27 jan. 2018
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
clear()
Remove all collected statistics.static void
end()
Ends timing on the calling class and method, specified by line number (of the start command).static void
end(String name)
Ends timing on the calling class and method, specified by given name.static void
print()
Prints profiling output to the console once every 1s or longer, or according to the time set insetPrintInterval()
.static void
reset()
Reset the collected running time values of all observed methods and method fragments.static void
setPrintInterval(long printInterval)
Sets a print interval.static void
start()
Starts timing on the calling class and method, specified by line number.static void
start(String name)
Starts timing on the calling class and method, specified by given name.static String
statistics()
Returns a formatted string of a table with statistics.static String
statistics(String name)
Return statistics of one sampler (which must have identified itself with a name).
-
-
-
Method Detail
-
start
public static void start()
Starts timing on the calling class and method, specified by line number.
-
start
public static void start(String name)
Starts timing on the calling class and method, specified by given name.- Parameters:
name
- String; name
-
end
public static void end()
Ends timing on the calling class and method, specified by line number (of the start command).
-
end
public static void end(String name)
Ends timing on the calling class and method, specified by given name.- Parameters:
name
- String; name
-
statistics
public static String statistics()
Returns a formatted string of a table with statistics.- Returns:
- String formatted string of a table with statistics
-
statistics
public static String statistics(String name)
Return statistics of one sampler (which must have identified itself with a name).- Parameters:
name
- String; name that was used instart
andend
calls.- Returns:
- String; the results, or null if no information was gathered under that name
-
print
public static void print()
Prints profiling output to the console once every 1s or longer, or according to the time set insetPrintInterval()
. This method needs to be called frequently, and will only print again after the print interval has elapsed. If execution time between two calls to this method is longer than the print interval, this method prints directly.
-
setPrintInterval
public static void setPrintInterval(long printInterval)
Sets a print interval.- Parameters:
printInterval
- long; print interval in ms
-
clear
public static void clear()
Remove all collected statistics. Does not reset the print interval, or the time of last print.
-
reset
public static void reset()
Reset the collected running time values of all observed methods and method fragments.
-
-