Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
vm,trace_events: add node.vm.script trace events category
Add basic trace events for node_contextify. These generally align very well with V8.ScriptCompile and V8.ScriptExecute trace events and provide good additional context. For instance, using the node.vm.script trace category at startup allows us to see exactly how long compilation and init of each of our core modules adds to the startup time. PR-URL: #20728 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
- Loading branch information
Showing
with
80 additions
and 0 deletions.
- +2 −0 doc/api/tracing.md
- +36 −0 src/node_contextify.cc
- +42 −0 test/parallel/test-trace-events-vm.js
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const tmpdir = require('../common/tmpdir'); | ||
|
||
const names = [ | ||
'ContextifyScript::New', | ||
'RunInThisContext', | ||
'RunInContext' | ||
]; | ||
|
||
if (process.argv[2] === 'child') { | ||
const vm = require('vm'); | ||
vm.runInNewContext('1 + 1'); | ||
} else { | ||
tmpdir.refresh(); | ||
process.chdir(tmpdir.path); | ||
|
||
const proc = cp.fork(__filename, | ||
[ 'child' ], { | ||
execArgv: [ | ||
'--trace-event-categories', | ||
'node.vm.script' | ||
] | ||
}); | ||
|
||
proc.once('exit', common.mustCall(() => { | ||
const file = path.join(tmpdir.path, 'node_trace.1.log'); | ||
|
||
assert(common.fileExists(file)); | ||
fs.readFile(file, common.mustCall((err, data) => { | ||
const traces = JSON.parse(data.toString()).traceEvents; | ||
traces.forEach((trace) => { | ||
assert.strictEqual(trace.pid, proc.pid); | ||
assert(names.includes(trace.name)); | ||
}); | ||
})); | ||
})); | ||
} |