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

#13295: Instrumenter.getNanos() returns non-epoch timestamp. #13535

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wdengw
Copy link

@wdengw wdengw commented Mar 17, 2025

No description provided.

@wdengw wdengw requested a review from a team as a code owner March 17, 2025 04:01
Copy link

linux-foundation-easycla bot commented Mar 17, 2025

CLA Not Signed

@@ -266,7 +266,7 @@ private void doEnd(

private static long getNanos(@Nullable Instant time) {
if (time == null) {
return System.nanoTime();
time = Instant.now();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time measurements should use a monotonic time source, Instant.now is not monotonic

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a return statement. It is to replace the null input arguement with the same Instant object with current time, then goes to line 272 to calculate the a monotonic time.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you have misunderstood what monotonic means here. The problem with using the "wall clock" time for like Instant.now for measuring elapsed time is that it is affected by system time adjustments. If system time is adjusted either by user or ntp between start or stop then stop can be before start which would result in a negative duration. Monotonic time only goes forward and is not adjusted.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If system time is adjusted either by user or ntp between start or stop, then your same argument applies to line 272, where the input argument time is not null. Are we saying that we should not use the input argument time as all? If so, the whole logic in this getNanos() should be changed accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants