I use spring-core:5.2.9.RELEASE
.
When I invoke StopWatch#prettyPrint
,
StopWatch '': running time = 9624841500 ns
---------------------------------------------
ns % Task name
---------------------------------------------
1202450400 012% createRandoms
8422391100 088% write
I want StopWatch
to provide setTimeUnit(java.util.concurrent.TimeUnit)
, getLastTime(TimeUnit)
and getTotalTime(TimeUnit)
; the return type of these methods is double
.
For example,
StopWatch stopWatch = new StopWatch();
stopWatch.setTimeUnit(TimeUnit.MINUTES); // If not set, StopWatch is applied default TimeUnit.
stopWatch.start();
/* working... */
stopWatch.stop();
getTotalTime(TimeUnit.SECONDS); // 9.6248415
getTotalTime(); // 0.160414025 / Without param, it depends on StopWatch#timeUnit
System.out.println(stopWatch.prettyPrint());
is like ...
StopWatch '': running time = 0.160414025 min
---------------------------------------------
min % Task name
---------------------------------------------
0.02004084 012% createRandoms
0.140373185 088% write
Thanks!
Comment From: sbrannen
Thanks for creating this issue.
I can see that this might be useful in some use cases, but this enhancement does not currently have high priority for us. Thus, I have assigned it to the General Backlog to allow this issue to gain interest from the community.
Comment From: teddylear
@sbrannen It alright if I work on this issue?
Comment From: sbrannen
@sbrannen It alright if I work on this issue?
Thanks for the offer, but @ak98neon already submitted PR #25813.
Comment From: jhoeller
I ended up switching the default time unit for String renderings to seconds with decimal points in nanosecond precision since the scale is easier to see then, while retaining the same precision level as in the 5.2 revision.
Custom renderings with specific time units can be requested through prettyPrint(TimeUnit)
, and custom time values can be obtained via getTotalTime(TimeUnit)
and TaskInfo.getTime(TimeUnit)
with double
precision. The prettyPrint
table automatically adapts to the scale of the total time reported, rendering the specific task times at the same scale.
The getLaskTaskX
methods have been deprecated in favor of nested lastTaskInfo().getX
calls. A seconds accessor was missing there, so this was inconsistent anyway, and the new TimeUnit-based accessor is only available on TaskInfo
now. Note that there is no instance-level TimeUnit
setting, just a TimeUnit
method parameter for specific accessors.