Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom TimeUnits in StopWatch #25813

Closed
wants to merge 5 commits into from

Conversation

ak98neon
Copy link

@ak98neon ak98neon commented Sep 24, 2020

Add TimeUnit support in StopWatch util class.

  • Provide StopWatch#getLastTime and StopWatch#getTotalTime
  • Modify the print format for tasks / include default TimeUnit in nanoseconds

See #25803

provide getLastTime, getTotalTime, modifie print format for tasks include default TimeUnit in nanoseconds
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 24, 2020
@sbrannen sbrannen linked an issue Sep 25, 2020 that may be closed by this pull request
@sbrannen sbrannen added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement labels Sep 25, 2020
@sbrannen sbrannen added this to the General Backlog milestone Sep 25, 2020
@snicoll snicoll removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 10, 2021
@msangel
Copy link

msangel commented Sep 11, 2022

Precisely what I was looking for. I don't know how many nanoseconds are in one second, so this will simplify my life.

@ak98neon ak98neon requested review from choi1135 and yun-yun and removed request for choi1135 October 20, 2022 19:38
@ventulus95
Copy link

The function itself is implemented, but it hasn't passed the CI yet. So won't this PR be merged in the foreseeable future? It is very useful for debugging and I would like to use it in a version, so when will this PR be merged? @ak98neon

@snicoll
Copy link
Member

snicoll commented May 2, 2023

@ventulus95 it's in the general backlog so there's no commitment on our end. That said, I am not sure we should implement it this way. We could reuse Duration which sounds a more rich concept for what you're trying to do.

@jhoeller
Copy link
Contributor

jhoeller commented Aug 7, 2023

I don't see the need for a new group of TimeUnit-based accessors and see them as rather confusing next to our existing getLaskTaskTimeX and getTotalTimeX accessors, in particular if the parameterless variant returns the time in a unit based on a StopWatch instance property.

That said, I do see the point with prettyPrint. The pre-5.2 representation with milliseconds was arguably more useful than the present implementation is. This can be addressed through an overloaded prettyPrint(TimeUnit) method which I'm inclined to introduce under #25803.

That aside, there is the question of Duration-returning time accessors... and of ChronoUnit for prettyPrint if java.time alignment is more appropriate than java.util.concurrent alignment. Either way, this is worth a broader revision for 6.1.

@jhoeller jhoeller closed this Aug 7, 2023
@jhoeller jhoeller added the status: superseded An issue that has been superseded by another label Aug 7, 2023
@jhoeller jhoeller removed this from the General Backlog milestone Aug 7, 2023
@jhoeller
Copy link
Contributor

jhoeller commented Aug 7, 2023

See #25803 (comment) for a summary of the 6.1 revision. This ended up preferring TimeUnit based accessors over Duration since the double precision is rather important here. Note that there is no instance-level TimeUnit setting, just a TimeUnit method parameter for specific accessors.

Thanks for the pull request and the specific proposal! This turned into very useful inspiration, I hope the end result is appropriate for your purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: superseded An issue that has been superseded by another type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support custom TimeUnits in StopWatch
9 participants