mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
perf_hooks: make nodeTiming a first-class object
Render all properties of nodeTiming enumerable so JSON.stringify and Object.keys can access them Fixes: https://github.com/nodejs/node/issues/35936 PR-URL: https://github.com/nodejs/node/pull/35977 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
committed by
Antoine du Hamel
parent
bea9857450
commit
feff38501a
@@ -166,50 +166,94 @@ function getMilestoneTimestamp(milestoneIdx) {
|
||||
}
|
||||
|
||||
class PerformanceNodeTiming extends PerformanceEntry {
|
||||
get name() {
|
||||
return 'node';
|
||||
}
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
get entryType() {
|
||||
return 'node';
|
||||
}
|
||||
ObjectDefineProperties(this, {
|
||||
name: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
value: 'node'
|
||||
},
|
||||
|
||||
get startTime() {
|
||||
return 0;
|
||||
}
|
||||
entryType: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
value: 'node'
|
||||
},
|
||||
|
||||
get duration() {
|
||||
return now() - timeOrigin;
|
||||
}
|
||||
startTime: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
value: 0
|
||||
},
|
||||
|
||||
get nodeStart() {
|
||||
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_NODE_START);
|
||||
}
|
||||
duration: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get() {
|
||||
return now() - timeOrigin;
|
||||
}
|
||||
},
|
||||
|
||||
get v8Start() {
|
||||
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_V8_START);
|
||||
}
|
||||
nodeStart: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get() {
|
||||
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_NODE_START);
|
||||
}
|
||||
},
|
||||
|
||||
get environment() {
|
||||
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
|
||||
}
|
||||
v8Start: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get() {
|
||||
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_V8_START);
|
||||
}
|
||||
},
|
||||
|
||||
get loopStart() {
|
||||
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_START);
|
||||
}
|
||||
environment: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get() {
|
||||
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
|
||||
}
|
||||
},
|
||||
|
||||
get loopExit() {
|
||||
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_EXIT);
|
||||
}
|
||||
loopStart: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get() {
|
||||
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_START);
|
||||
}
|
||||
},
|
||||
|
||||
get bootstrapComplete() {
|
||||
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);
|
||||
}
|
||||
loopExit: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get() {
|
||||
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_EXIT);
|
||||
}
|
||||
},
|
||||
|
||||
get idleTime() {
|
||||
return loopIdleTime();
|
||||
}
|
||||
bootstrapComplete: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get() {
|
||||
return getMilestoneTimestamp(
|
||||
NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);
|
||||
}
|
||||
},
|
||||
|
||||
idleTime: {
|
||||
enumerable: true,
|
||||
configurable: true,
|
||||
get() {
|
||||
return loopIdleTime();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
[kInspect]() {
|
||||
return {
|
||||
name: 'node',
|
||||
|
||||
@@ -22,6 +22,13 @@ if (nodeTiming.loopStart === -1) {
|
||||
{ idle: 0, active: 0, utilization: 0 });
|
||||
}
|
||||
|
||||
const nodeTimingProps = ['name', 'entryType', 'startTime', 'duration',
|
||||
'nodeStart', 'v8Start', 'environment', 'loopStart',
|
||||
'loopExit', 'bootstrapComplete', 'idleTime'];
|
||||
for (const p of nodeTimingProps)
|
||||
assert.ok(typeof JSON.parse(JSON.stringify(nodeTiming))[p] ===
|
||||
typeof nodeTiming[p]);
|
||||
|
||||
setTimeout(mustCall(function r() {
|
||||
const elu1 = eventLoopUtilization();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user