Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf_hooks: make nodeTiming a first-class object #35977

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
105 changes: 72 additions & 33 deletions lib/perf_hooks.js
Expand Up @@ -166,50 +166,89 @@ function getMilestoneTimestamp(milestoneIdx) {
}

class PerformanceNodeTiming extends PerformanceEntry {
get name() {
return 'node';
}
constructor() {
super();

get entryType() {
return 'node';
}
ObjectDefineProperties(this, {
name: {
enumerable: true,
get() {
return 'node';
}
},
addaleax marked this conversation as resolved.
Show resolved Hide resolved

get startTime() {
return 0;
}
entryType: {
enumerable: true,
get() {
return 'node';
}
},

get duration() {
return now() - timeOrigin;
}
startTime: {
enumerable: true,
get() {
return 0;
}
},

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

get v8Start() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_V8_START);
}
nodeStart: {
enumerable: true,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_NODE_START);
}
},

get environment() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
}
v8Start: {
enumerable: true,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_V8_START);
}
},

get loopStart() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_START);
}
environment: {
enumerable: true,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_ENVIRONMENT);
}
},

get loopExit() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_EXIT);
}
loopStart: {
enumerable: true,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_START);
}
},

get bootstrapComplete() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);
}
loopExit: {
enumerable: true,
get() {
return getMilestoneTimestamp(NODE_PERFORMANCE_MILESTONE_LOOP_EXIT);
}
},

get idleTime() {
return loopIdleTime();
}
bootstrapComplete: {
enumerable: true,
get() {
return getMilestoneTimestamp(
NODE_PERFORMANCE_MILESTONE_BOOTSTRAP_COMPLETE);
}
},

idleTime: {
enumerable: true,
get() {
return loopIdleTime();
}
}
});
}
[kInspect]() {
return {
name: 'node',
Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-performance-eventlooputil.js
Expand Up @@ -22,6 +22,12 @@ if (nodeTiming.loopStart === -1) {
{ idle: 0, active: 0, utilization: 0 });
}

for (const p of ['name', 'entryType', 'startTime', 'duration',
'nodeStart', 'v8Start', 'environment', 'loopStart', 'loopExit',
'bootstrapComplete', 'idleTime'])
assert.ok(typeof JSON.parse(JSON.stringify(nodeTiming))[p] ===
typeof nodeTiming[p]);

mmomtchev marked this conversation as resolved.
Show resolved Hide resolved
setTimeout(mustCall(function r() {
const t = Date.now();
const elu1 = eventLoopUtilization();
Expand Down