Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
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
103 changes: 70 additions & 33 deletions lib/perf_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,51 +165,88 @@ function getMilestoneTimestamp(milestoneIdx) {
return ns / 1e6 - timeOrigin;
}

const PerformanceNodeTimingProps = {
enumerable: true,
configurable: true
};
class PerformanceNodeTiming extends PerformanceEntry {
get name() {
return 'node';
}
constructor() {
super();

get entryType() {
return 'node';
}
ObjectDefineProperties(this, {
name: {
...PerformanceNodeTimingProps,
value: 'node'
},

get startTime() {
return 0;
}
entryType: {
...PerformanceNodeTimingProps,
value: 'node'
},

get duration() {
return now() - timeOrigin;
}
startTime: {
...PerformanceNodeTimingProps,
value: 0
},

get nodeStart() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_NODE_START);
}
duration: {
...PerformanceNodeTimingProps,
get() {
return now() - timeOrigin;
}
},

get v8Start() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_V8_START);
}
nodeStart: {
...PerformanceNodeTimingProps,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_NODE_START);
}
},

get environment() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
}
v8Start: {
...PerformanceNodeTimingProps,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_V8_START);
}
},

get loopStart() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_START);
}
environment: {
...PerformanceNodeTimingProps,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
}
},

get loopExit() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_EXIT);
}
loopStart: {
...PerformanceNodeTimingProps,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_START);
}
},

get bootstrapComplete() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);
}
loopExit: {
...PerformanceNodeTimingProps,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_EXIT);
}
},

get idleTime() {
return loopIdleTime();
}
bootstrapComplete: {
...PerformanceNodeTimingProps,
get() {
return getMilestoneTimestamp(
NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);
}
},

idleTime: {
...PerformanceNodeTimingProps,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: I would just include the properties directly here (rather than use the repeated `...PerformanceNodeTimingProps) even if they're going to be duplicated just to save an unnecessary performance cost.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, do you think V8 keeps a reference to the initializing object when using the spread operator?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is ECMA specified in fact

get() {
return loopIdleTime();
}
}
});
}
[kInspect]() {
return {
name: 'node',
Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-performance-eventlooputil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 t = Date.now();
const elu1 = eventLoopUtilization();
Expand Down