File tree Expand file tree Collapse file tree 5 files changed +57
-0
lines changed Expand file tree Collapse file tree 5 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -40,6 +40,8 @@ The available categories are:
4040 measures and marks.
4141 * ` node.perf.timerify ` : Enables capture of only Performance API timerify
4242 measurements.
43+ * ` node.process.sync ` : Enables capture of trace data for the sync APIs of
44+ process module.
4345* ` node.promises.rejections ` : Enables capture of trace data tracking the number
4446 of unhandled Promise rejections and handled-after-rejections.
4547* ` node.vm.script ` : Enables capture of trace data for the ` node:vm ` module's
Original file line number Diff line number Diff line change @@ -190,6 +190,7 @@ DispatchResponse TracingAgent::getCategories(
190190 categories_list->addItem (" node.perf" );
191191 categories_list->addItem (" node.perf.timerify" );
192192 categories_list->addItem (" node.perf.usertiming" );
193+ categories_list->addItem (" node.process.sync" );
193194 categories_list->addItem (" node.promises.rejections" );
194195 categories_list->addItem (" node.threadpoolwork.async" );
195196 categories_list->addItem (" node.threadpoolwork.sync" );
Original file line number Diff line number Diff line change 2424#include " env-inl.h"
2525#include " node_internals.h"
2626#include " string_bytes.h"
27+ #include " tracing/trace_event.h"
2728#include " util-inl.h"
2829
2930#include < cstring>
@@ -514,8 +515,21 @@ Maybe<bool> SyncProcessRunner::TryInitializeAndRunLoop(Local<Value> options) {
514515 }
515516 }
516517 }
518+ if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED (
519+ TRACING_CATEGORY_NODE2 (process, sync)) != 0 ) {
520+ TRACE_EVENT_BEGIN1 (TRACING_CATEGORY_NODE2 (process, sync),
521+ " spawnSync" ,
522+ " file" ,
523+ TRACE_STR_COPY (uv_process_options_.file ));
524+ }
517525
518526 r = uv_run (uv_loop_, UV_RUN_DEFAULT);
527+
528+ if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED (
529+ TRACING_CATEGORY_NODE2 (process, sync)) != 0 ) {
530+ TRACE_EVENT_END0 (TRACING_CATEGORY_NODE2 (process, sync), " spawnSync" );
531+ }
532+
519533 if (r < 0 )
520534 // We can't handle uv_run failure.
521535 ABORT ();
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ async function test() {
5858 'node.perf' ,
5959 'node.perf.timerify' ,
6060 'node.perf.usertiming' ,
61+ 'node.process.sync' ,
6162 'node.promises.rejections' ,
6263 'node.threadpoolwork.async' ,
6364 'node.threadpoolwork.sync' ,
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ require ( '../common' ) ;
3+ const assert = require ( 'assert' ) ;
4+ const cp = require ( 'child_process' ) ;
5+ const fs = require ( 'fs' ) ;
6+ const path = require ( 'path' ) ;
7+ const tmpdir = require ( '../common/tmpdir' ) ;
8+
9+ if ( process . env . isChild === '1' ) {
10+ cp . execFileSync ( 'node' , [ '-e' , '' ] ) ;
11+ cp . execSync ( 'node' , [ '-e' , '' ] ) ;
12+ cp . spawnSync ( 'node' , [ '-e' , '' ] ) ;
13+ return ;
14+ }
15+
16+ tmpdir . refresh ( ) ;
17+ const FILE_NAME = path . join ( tmpdir . path , 'node_trace.1.log' ) ;
18+
19+ cp . spawnSync ( process . execPath ,
20+ [
21+ '--trace-events-enabled' ,
22+ '--trace-event-categories' , 'node.process.sync' ,
23+ __filename ,
24+ ] ,
25+ {
26+ cwd : tmpdir . path ,
27+ env : {
28+ ...process . env ,
29+ isChild : '1' ,
30+ } ,
31+ } ) ;
32+
33+ assert ( fs . existsSync ( FILE_NAME ) ) ;
34+ const data = fs . readFileSync ( FILE_NAME ) ;
35+ const traces = JSON . parse ( data . toString ( ) ) . traceEvents ;
36+ assert ( traces . length > 0 ) ;
37+ const count = traces . filter ( ( item ) => item . name === 'spawnSync' ) . length ;
38+ // Two begin, Two end
39+ assert . strictEqual ( count === 3 * 2 , true ) ;
You can’t perform that action at this time.
0 commit comments