mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 15:32:15 +00:00

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: https://github.com/nodejs/node/pull/48708 Refs: https://github.com/nodejs/build/issues/3043 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
34 lines
787 B
JavaScript
34 lines
787 B
JavaScript
'use strict';
|
|
|
|
const {
|
|
constants: {
|
|
NODE_PERFORMANCE_MILESTONE_TIME_ORIGIN,
|
|
},
|
|
milestones,
|
|
} = internalBinding('performance');
|
|
|
|
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) - 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 - getTimeOrigin();
|
|
}
|
|
|
|
module.exports = {
|
|
now,
|
|
getMilestoneTimestamp,
|
|
};
|