mirror of
https://github.com/nodejs/node.git
synced 2025-05-06 20:08:02 +00:00

This commit adds support for trace-event tracing to Node.js. It provides a mechanism to centralize tracing information generated by V8, Node core, and userspace code. It includes: - A trace writer responsible for serializing traces and cycling the output files so that no individual file becomes to large. - A buffer for aggregating traces to allow for batched flushes. - An agent which initializes the tracing controller and ensures that trace serialization is done on a separate thread. - A set of macros for generating trace events. - Tests and documentation. Author: Raymond Kang <raymondksi@gmail.com> Author: Kelvin Jin <kelvinjin@google.com> Author: Matthew Loring <mattloring@google.com> Author: Jason Ginchereau <jasongin@microsoft.com> PR-URL: https://github.com/nodejs/node/pull/9304 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Josh Gavant <josh.gavant@outlook.com>
36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const cp = require('child_process');
|
|
const fs = require('fs');
|
|
|
|
const CODE = 'for (var i = 0; i < 100000; i++) { "test" + i }';
|
|
const FILE_NAME = 'node_trace.1.log';
|
|
|
|
common.refreshTmpDir();
|
|
process.chdir(common.tmpDir);
|
|
|
|
const proc_no_categories = cp.spawn(process.execPath,
|
|
[ '--trace-events-enabled', '--trace-event-categories', '""', '-e', CODE ]);
|
|
|
|
proc_no_categories.once('exit', common.mustCall(() => {
|
|
assert(!common.fileExists(FILE_NAME));
|
|
|
|
const proc = cp.spawn(process.execPath,
|
|
[ '--trace-events-enabled', '-e', CODE ]);
|
|
|
|
proc.once('exit', common.mustCall(() => {
|
|
assert(common.fileExists(FILE_NAME));
|
|
fs.readFile(FILE_NAME, (err, data) => {
|
|
const traces = JSON.parse(data.toString()).traceEvents;
|
|
assert(traces.length > 0);
|
|
// Values that should be present on all runs to approximate correctness.
|
|
assert(traces.some((trace) => { return trace.pid === proc.pid; }));
|
|
assert(traces.some((trace) => { return trace.cat === 'v8'; }));
|
|
assert(traces.some((trace) => {
|
|
return trace.name === 'V8.ScriptCompiler';
|
|
}));
|
|
});
|
|
}));
|
|
}));
|