-
Notifications
You must be signed in to change notification settings - Fork 916
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
base: main
Are you sure you want to change the base?
Conversation
|
@@ -266,7 +266,7 @@ private void doEnd( | |||
|
|||
private static long getNanos(@Nullable Instant time) { | |||
if (time == null) { | |||
return System.nanoTime(); | |||
time = Instant.now(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
No description provided.