Package org.djutils.profile
Class Profile
java.lang.Object
org.djutils.profile.Profile
Utility class to profile code execution times.
Insert a call to one of the
The collected statistics information can be retrieved with the
To output statistics at (somewhat) regular intervals call
Insert a call to one of the
start
methods at the start of each method (or part thereof) that must be timed and a
call to one of the end
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 the
statistics
method. To output statistics at (somewhat) regular intervals call
print
method often. The default interval is 1 second;
this can be changed by calling the setPrintInterval method
.
Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.
- Author:
- Alexander Verbraeck, Peter Knoppers, Wouter Schakel
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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
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
Starts timing on the calling class and method, specified by given name.static String
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 Details
-
start
public static void start()Starts timing on the calling class and method, specified by line number. -
start
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
Ends timing on the calling class and method, specified by given name.- Parameters:
name
- String; name
-
statistics
Returns a formatted string of a table with statistics.- Returns:
- String formatted string of a table with statistics
-
statistics
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.
-