feat(stat): use cputime for all timing related functions #1901
+55
−53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
It's always baffled me why the 3 timings at the top of the
Profile
tab didn't match the individual timings of the profiles in the more detailed breakdown in the lower section. Decided to dive into this a bit and realized that cputime was being used for the main 3, but relative timings from one stage to the next were usingvim.uv.hrtime() - <prev_snapshot>
.These are two different types of timings. I may have some changes soon that attempt to remedy this, but if the cputime() function is using the ffi
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, ...)
from the OS, it measures only the cpu time of the process, not the wall time from process start to the time of the call. Unfortunately this means the cputime measurement doesn't reflect actual elapsed time. When you mix and match these two, the times don't add up.This PR aims to unify the times in the profile output so all the shown elapsed times are sourced by the same method. It moves
cputime()
tolazy.core.util
and changes the stats'times[]
to store nanoseconds instead of milliseconds.