-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: save the performance milestone time origin in the AliasedArray
Previously we cache the time origin for the milestones in the user land, and refresh it at pre-execution. As result the time origin gets serialized into the snapshot and is therefore not deterministic. Now we store it in the milestone array as an internal value and reset the milestones at serialization time instead of deserialization time. This improves the determinism of the snapshot. Drive-by: remove the unused MarkMilestone() binding. PR-URL: #48708 Refs: nodejs/build#3043 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
- Loading branch information
1 parent
ac34e75
commit 4ee4718
Showing
5 changed files
with
60 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
'use strict'; | ||
|
||
const binding = internalBinding('performance'); | ||
const { | ||
constants: { | ||
NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN, | ||
}, | ||
milestones, | ||
getTimeOrigin, | ||
} = binding; | ||
} = internalBinding('performance'); | ||
|
||
// TODO(joyeecheung): we may want to warn about access to | ||
// this during snapshot building. | ||
let timeOrigin = getTimeOrigin(); | ||
function getTimeOrigin() { | ||
// Do not cache this to prevent it from being serialized into the | ||
// snapshot. | ||
return milestones[NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN] / 1e6; | ||
} | ||
|
||
// Returns the time relative to the process start time in milliseconds. | ||
function now() { | ||
const hr = process.hrtime(); | ||
return (hr[0] * 1000 + hr[1] / 1e6) - timeOrigin; | ||
return (hr[0] * 1000 + hr[1] / 1e6) - getTimeOrigin(); | ||
} | ||
|
||
// Returns the milestone relative to the process start time in milliseconds. | ||
function getMilestoneTimestamp(milestoneIdx) { | ||
const ns = milestones[milestoneIdx]; | ||
if (ns === -1) | ||
return ns; | ||
return ns / 1e6 - timeOrigin; | ||
} | ||
|
||
function refreshTimeOrigin() { | ||
timeOrigin = getTimeOrigin(); | ||
return ns / 1e6 - getTimeOrigin(); | ||
} | ||
|
||
module.exports = { | ||
now, | ||
getMilestoneTimestamp, | ||
refreshTimeOrigin, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters