Type | Name and description |
---|---|
java.lang.String |
CHAR_EMPTY |
java.lang.String |
CHAR_FILLED |
java.lang.String |
CHAR_HAS_CHILD |
java.lang.String |
CHAR_LAST |
java.lang.String |
CHAR_SIBLING |
java.util.List |
HEADER |
java.lang.String |
SEPARATOR |
Type Params | Return Type | Name and description |
---|---|---|
|
java.lang.Object |
_elementName(java.lang.Object obj) !!! |
|
java.lang.Object |
_formatMs(java.lang.Object time) !!! |
|
java.lang.Object |
_formatPct(java.lang.Object number, boolean pad = false) !!! |
|
java.lang.Object |
_renderPct(java.lang.Object time, java.lang.Object ratio) !!! |
|
java.util.Map |
_stopwatch() !!! |
|
java.lang.Object |
getStop() Groovy getter to enable the Stopwatch.stop syntax (without parentheses). |
|
void |
javadoc() The Stopwatch library can be used to measure performance of code blocks within a single formula element or across multiple elements. |
|
void |
lap(java.lang.String blockName) Stops measuring the previous time block and starts a new one. |
null |
static void |
main(java.lang.String[] args) Implicit main method for Groovy Scripts |
|
void |
measure(java.lang.String blockName, groovy.lang.Closure closure) Starts measuring a time block with the given name. |
|
void |
start(java.lang.Object elementName) Calls the method start(String) while converting the given Object to a String. |
|
void |
start(java.lang.String blockName) Starts measuring a time block with the given name. |
|
void |
stop() Stops measuring the time of the time block started with start(String). |
|
java.util.List |
toList(boolean verbose = false, java.lang.String blockName = null) Creates a time report and returns it in a List of Lists. |
|
net.pricefx.server.dto.calculation.ResultMatrix |
toResultMatrix(boolean verbose = false, java.lang.String blockName = null) Creates a time report and puts it into a ResultMatrix . |
|
java.lang.String |
toString(boolean verbose = false, java.lang.String blockName = null) Creates a time report and returns it in a formatted String . |
|
void |
trace(boolean verbose = false, java.lang.String blockName = null) Creates a time report and prints it using api.trace . |
Methods inherited from class | Name |
---|---|
class groovy.lang.Script |
groovy.lang.Script#invokeMethod(java.lang.String, java.lang.Object), groovy.lang.Script#evaluate(java.lang.String), groovy.lang.Script#evaluate(java.io.File), groovy.lang.Script#getBinding(), groovy.lang.Script#setBinding(groovy.lang.Binding), groovy.lang.Script#println(), groovy.lang.Script#println(java.lang.Object), groovy.lang.Script#run(java.io.File, [Ljava.lang.String;), groovy.lang.Script#run(), groovy.lang.Script#setProperty(java.lang.String, java.lang.Object), groovy.lang.Script#getProperty(java.lang.String), groovy.lang.Script#print(java.lang.Object), groovy.lang.Script#printf(java.lang.String, java.lang.Object), groovy.lang.Script#printf(java.lang.String, [Ljava.lang.Object;), groovy.lang.Script#getMetaClass(), groovy.lang.Script#setMetaClass(groovy.lang.MetaClass), groovy.lang.Script#wait(long, int), groovy.lang.Script#wait(long), groovy.lang.Script#wait(), groovy.lang.Script#equals(java.lang.Object), groovy.lang.Script#toString(), groovy.lang.Script#hashCode(), groovy.lang.Script#getClass(), groovy.lang.Script#notify(), groovy.lang.Script#notifyAll() |
class groovy.lang.GroovyObjectSupport |
groovy.lang.GroovyObjectSupport#getMetaClass(), groovy.lang.GroovyObjectSupport#invokeMethod(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#setMetaClass(groovy.lang.MetaClass), groovy.lang.GroovyObjectSupport#setProperty(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#getProperty(java.lang.String), groovy.lang.GroovyObjectSupport#wait(long, int), groovy.lang.GroovyObjectSupport#wait(long), groovy.lang.GroovyObjectSupport#wait(), groovy.lang.GroovyObjectSupport#equals(java.lang.Object), groovy.lang.GroovyObjectSupport#toString(), groovy.lang.GroovyObjectSupport#hashCode(), groovy.lang.GroovyObjectSupport#getClass(), groovy.lang.GroovyObjectSupport#notify(), groovy.lang.GroovyObjectSupport#notifyAll() |
!!! Private method, DO NOT USE !!!
!!! Private method, DO NOT USE !!!
!!! Private method, DO NOT USE !!!
!!! Private method, DO NOT USE !!!
!!! Private method, DO NOT USE !!!
Groovy getter to enable the Stopwatch.stop syntax (without parentheses). Calls the stop() method.
The Stopwatch library can be used to measure performance of code blocks within a single formula element or across multiple elements. It relies on System.nanoTime() for measuring the duration of the time blocks. Its main advantage in contrary to the standard trace in the Debug mode is that it can measure whole run time of multiple code blocks within a single formula element and not only specific Pricefx API calls and elements' total run time.
To measure performance of your code using Stopwatch, you can use two methods. Either enclose your code with start(String), lap(String) and stop() calls or use the measure(String, Closure) function with a closure whose performance will be measured.
The Stopwatch supports measuring of nested code blocks, e.g. performance of code within a for-loop.
Example for start()
, lap()
and stop()
: *
Example for measure():def Stopwatch = libs.StopwatchLib.Stopwatch // make a shortcut to the library Stopwatch.start "Element A" Stopwatch.start "Block 1" // creates a nested time block within Element A Stopwatch.start "Block 1.1" // creates a nested time block within Block 1 // ... your measured code Stopwatch.lap "Block 1.2" // ends measuring of Block 1.1 and starts Block 1.2 // ... your measured code Stopwatch.stop // ends measuring of Block 1.2 Stopwatch.start "Block 2" // creates a nested time block within Element A // ... your measured code Stopwatch.stop // ends measuring of Block 2 Stopwatch.stop // ends measuring of Element A Stopwatch.trace
The library supports four kinds of reports: via api.trace, via ResultMatrix, println or custom report. All you need to do is to call one of the following methods after the last stop() or measure() method.def Stopwatch = libs.StopwatchLib.Stopwatch // make a shortcut to the library Stopwatch.measure "Element A", { Stopwatch.measure "Block 1", { Stopwatch.measure "Block 1.1", { // ... your measured code } Stopwatch.measure "Block 1.2", { // ... your measured code } } Stopwatch.measure "Block 2", { // ... your measured code } } Stopwatch.trace
The first column contains the name of the measured time block with depicted hierarchy of nesting. The second column displays each time block's duration ratio to the root (1st level) time block. The third column displays each time block's duration ratio to its immediate parent time block.STOPWATCH REPORT | % to Overall | % to Parent Element A | ▓▓▓▓▓▓▓▓▓▓ 610 ms (100 %) | ▓▓▓▓▓▓▓▓▓▓ 610 ms (100 %) ├─ Block 1 | ▓▓▓▓▓░░░░░ 305 ms (50 %) | ▓▓▓▓▓░░░░░ 305 ms (50 %) │ ├─ Block 1.1 | ▓▓▓░░░░░░░ 200 ms (33 %) | ▓▓▓▓▓▓▓░░░ 200 ms (66 %) │ └─ Block 1.2 | ▓▓░░░░░░░░ 101 ms (17 %) | ▓▓▓░░░░░░░ 101 ms (33 %) └─ Block 2 | ▓▓▓▓▓░░░░░ 299 ms (49 %) | ▓▓▓▓▓░░░░░ 299 ms (49 %)
Stops measuring the previous time block and starts a new one. Essentially it just calls stop() and start(blockName).
For an example see the start(String) method.
blockName
- the name of the time block to measureImplicit main method for Groovy Scripts
Starts measuring a time block with the given name. The Stopwatch will measure the time duration of the given closure. You can nest the calls to the measure(String, Closure) method.
An alternative is to enclose your code with start(String) and stop() methods.
Example:
def Stopwatch = libs.StopwatchLib.Stopwatch // make a shortcut to the library Stopwatch.measure "Element A", { Stopwatch.measure "Block 1", { Stopwatch.measure "Block 1.1", { // ... your measured code } Stopwatch.measure "Block 1.2", { // ... your measured code } } Stopwatch.measure "Block 2", { // ... your measured code } } Stopwatch.trace
blockName
- the name of the time block to measureclosure
- the closure to measureCalls the method start(String) while converting the given Object to a String. It expects the given Object to be a formula element object, thus you should call it in the following way:
start(this)
elementName
- the formula element ObjectStarts measuring a time block with the given name. The Stopwatch will measure the time duration until the method stop() is called.
You can nest time blocks by calling start(String) one after each other. Each time block must end with a corresponding call to stop().
Instead of calling
start("A"), stop(), start("B"), stop()you can also call
start("A"), lap("B"), stop()Example:
You can also use a more readable syntax with method measure(String, Closure) insteaddef Stopwatch = libs.StopwatchLib.Stopwatch // make a shortcut to the library Stopwatch.start "Element A" Stopwatch.start "Block 1" // creates a nested time block within Element A Stopwatch.start "Block 1.1" // creates a nested time block within Block 1 // ... your measured code Stopwatch.lap "Block 1.2" // ends measuring of Block 1.1 and starts Block 1.2 // ... your measured code Stopwatch.stop // ends measuring of Block 1.2 Stopwatch.start "Block 2" // creates a nested time block within Element A // ... your measured code Stopwatch.stop // ends measuring of Block 2 Stopwatch.stop // ends measuring of Element A Stopwatch.trace
blockName
- the name of the time block to measureStops measuring the time of the time block started with start(String). This method should always come in pair with a prior corresponding call to the start(String) method, or after a lap(String) method is called.
Creates a time report and returns it in a List of Lists. The inner list has always three elements (columns).
If you provide the blockName
parameter, the report will be created only for the specified time block
and its children.
The result looks like this:
The first column contains the name of the measured time block with depicted hierarchy of nesting. The second column displays each time block's duration ratio to the root (1st level) time block. The third column displays each time block's duration ratio to its immediate parent time block.[ [ "STOPWATCH REPORT", "% to Overall", "% to Parent], [ "Element A", "▓▓▓▓▓▓▓▓▓▓ 610 ms (100 %)", "▓▓▓▓▓▓▓▓▓▓ 610 ms (100 %)" ] [ "├─ Block 1", "▓▓▓▓▓░░░░░ 305 ms (50 %)", "▓▓▓▓▓░░░░░ 305 ms (50 %)" ] [ "│ ├─ Block 1.1", "▓▓▓░░░░░░░ 200 ms (33 %)", "▓▓▓▓▓▓▓░░░ 200 ms (66 %) ] [ "│ └─ Block 1.2", "▓▓░░░░░░░░ 101 ms (17 %)", "▓▓▓░░░░░░░ 101 ms (33 %) ] [ "└─ Block 2", "▓▓▓▓▓░░░░░ 299 ms (49 %)", "▓▓▓▓▓░░░░░ 299 ms (49 %) ] ]
If verbose
is true, each branch will also show an information about the child block's duration ratio to its
parent. See toString(boolean) for how this looks like.
verbose
- if true, the branches will also contain information of each block's duration ratio to each of its
hierarchical parent.blockName
- optionally provide the name of the block to report, otherwise the report will be created for all Creates a time report and puts it into a ResultMatrix
. If you provide the blockName
parameter,
the report will be created only for the specified time block and its children.
The result is visually the same as calling the toString(boolean, String) method.
verbose
- if true, the branches will also contain information of each block's duration ratio to each of its
hierarchical parent.blockName
- optionally provide the name of the block to report, otherwise the report will be created for all Creates a time report and returns it in a formatted String
. If you provide the blockName
parameter,
the report will be created only for the specified time block and its children.
The result is visually the same as calling the toString(boolean, String) method.
The result looks like this:
The first column contains the name of the measured time block with depicted hierarchy of nesting. The second column displays each time block's duration ratio to the root (1st level) time block. The third column displays each time block's duration ratio to its immediate parent time block.STOPWATCH REPORT | % to Overall | % to Parent Element A | ▓▓▓▓▓▓▓▓▓▓ 610 ms (100 %) | ▓▓▓▓▓▓▓▓▓▓ 610 ms (100 %) ├─ Block 1 | ▓▓▓▓▓░░░░░ 305 ms (50 %) | ▓▓▓▓▓░░░░░ 305 ms (50 %) │ ├─ Block 1.1 | ▓▓▓░░░░░░░ 200 ms (33 %) | ▓▓▓▓▓▓▓░░░ 200 ms (66 %) │ └─ Block 1.2 | ▓▓░░░░░░░░ 101 ms (17 %) | ▓▓▓░░░░░░░ 101 ms (33 %) └─ Block 2 | ▓▓▓▓▓░░░░░ 299 ms (49 %) | ▓▓▓▓▓░░░░░ 299 ms (49 %)
If verbose
is true, each branch will also show an information about the child block's duration ratio to its
parent, like this:
STOPWATCH REPORT | % to Overall | % to Parent Element A | ▓▓▓▓▓▓▓▓▓▓ 610 ms (100 %) | ▓▓▓▓▓▓▓▓▓▓ 610 ms (100 %) ├─(50 %) Block 1 | ▓▓▓▓▓░░░░░ 305 ms (50 %) | ▓▓▓▓▓░░░░░ 305 ms (50 %) │ (33 %) ├─(50 %) Block 1.1 | ▓▓▓░░░░░░░ 200 ms (33 %) | ▓▓▓▓▓▓▓░░░ 200 ms (66 %) │ (33 %) └─(17 %) Block 1.2 | ▓▓░░░░░░░░ 101 ms (17 %) | ▓▓▓░░░░░░░ 101 ms (33 %) └─(49 %) Block 2 | ▓▓▓▓▓░░░░░ 299 ms (49 %) | ▓▓▓▓▓░░░░░ 299 ms (49 %)
verbose
- if true, the branches will also contain information of each block's duration ratio to each of its
hierarchical parent.blockName
- optionally provide the name of the block to report, otherwise the report will be created for all Creates a time report and prints it using api.trace
. If you provide the blockName
parameter,
the report will be created only for the specified time block and its children.
The result is visually the same as calling the toString(boolean, String) method.
verbose
- if true, the branches will also contain information of each block's duration ratio to each of its
hierarchical parent.blockName
- optionally provide the name of the block to report, otherwise the report will be created for all