Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
perf_hooks: make nodeTiming a first-class object
Render all properties of nodeTiming enumerable
so JSON.stringify and Object.keys can access them

Refs: #35977
  • Loading branch information
mmomtchev committed Nov 6, 2020
commit 778f60b7626f0a715ae4071cdb944165251028e9
37 changes: 22 additions & 15 deletions lib/perf_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,82 +165,89 @@ function getMilestoneTimestamp(milestoneIdx) {
return ns / 1e6 - timeOrigin;
}

const PerformanceNodeTimingProps = {
enumerable: true,
configurable: true
};
class PerformanceNodeTiming extends PerformanceEntry {
constructor() {
super();

ObjectDefineProperties(this, {
name: {
...PerformanceNodeTimingProps,
enumerable: true,
configurable: true,
value: 'node'
},
Comment thread
addaleax marked this conversation as resolved.

entryType: {
...PerformanceNodeTimingProps,
enumerable: true,
configurable: true,
value: 'node'
},

startTime: {
...PerformanceNodeTimingProps,
enumerable: true,
configurable: true,
value: 0
},

duration: {
...PerformanceNodeTimingProps,
enumerable: true,
configurable: true,
get() {
return now() - timeOrigin;
}
},

nodeStart: {
...PerformanceNodeTimingProps,
enumerable: true,
configurable: true,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_NODE_START);
}
},

v8Start: {
...PerformanceNodeTimingProps,
enumerable: true,
configurable: true,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_V8_START);
}
},

environment: {
...PerformanceNodeTimingProps,
enumerable: true,
configurable: true,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
}
},

loopStart: {
...PerformanceNodeTimingProps,
enumerable: true,
configurable: true,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_START);
}
},

loopExit: {
...PerformanceNodeTimingProps,
enumerable: true,
configurable: true,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_EXIT);
}
},

bootstrapComplete: {
...PerformanceNodeTimingProps,
enumerable: true,
configurable: true,
get() {
return getMilestoneTimestamp(
NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);
}
},

idleTime: {
...PerformanceNodeTimingProps,
enumerable: true,
configurable: true,
get() {
return loopIdleTime();
}
Expand Down