38
38
#include " req-wrap.h"
39
39
#include " req-wrap-inl.h"
40
40
#include " string_bytes.h"
41
+ #include " tracing/agent.h"
41
42
#include " util.h"
42
43
#include " uv.h"
43
44
#if NODE_USE_V8_PLATFORM
@@ -150,6 +151,8 @@ static node_module* modpending;
150
151
static node_module* modlist_builtin;
151
152
static node_module* modlist_linked;
152
153
static node_module* modlist_addon;
154
+ static bool trace_enabled = false ;
155
+ static const char * trace_enabled_categories = nullptr ;
153
156
154
157
#if defined(NODE_HAVE_I18N_SUPPORT)
155
158
// Path to ICU data (for i18n / Intl)
@@ -186,6 +189,7 @@ static uv_async_t dispatch_debug_messages_async;
186
189
187
190
static Mutex node_isolate_mutex;
188
191
static v8::Isolate* node_isolate;
192
+ static tracing::Agent* tracing_agent;
189
193
190
194
static node::DebugOptions debug_options;
191
195
@@ -194,6 +198,7 @@ static struct {
194
198
void Initialize (int thread_pool_size) {
195
199
platform_ = v8::platform::CreateDefaultPlatform (thread_pool_size);
196
200
V8::InitializePlatform (platform_);
201
+ tracing::TraceEventHelper::SetCurrentPlatform (platform_);
197
202
}
198
203
199
204
void PumpMessageLoop (Isolate* isolate) {
@@ -3368,6 +3373,9 @@ void SetupProcessObject(Environment* env,
3368
3373
3369
3374
void SignalExit (int signo) {
3370
3375
uv_tty_reset_mode ();
3376
+ if (trace_enabled) {
3377
+ tracing_agent->Stop ();
3378
+ }
3371
3379
#ifdef __FreeBSD__
3372
3380
// FreeBSD has a nasty bug, see RegisterSignalHandler for details
3373
3381
struct sigaction sa;
@@ -3463,64 +3471,70 @@ static void PrintHelp() {
3463
3471
" node debug script.js [arguments] \n "
3464
3472
" \n "
3465
3473
" Options:\n "
3466
- " -v, --version print Node.js version\n "
3467
- " -e, --eval script evaluate script\n "
3468
- " -p, --print evaluate script and print result\n "
3469
- " -c, --check syntax check script without executing\n "
3470
- " -i, --interactive always enter the REPL even if stdin\n "
3471
- " does not appear to be a terminal\n "
3472
- " -r, --require module to preload (option can be repeated)\n "
3473
- " --no-deprecation silence deprecation warnings\n "
3474
- " --trace-deprecation show stack traces on deprecations\n "
3475
- " --throw-deprecation throw an exception anytime a deprecated "
3474
+ " -v, --version print Node.js version\n "
3475
+ " -e, --eval script evaluate script\n "
3476
+ " -p, --print evaluate script and print result\n "
3477
+ " -c, --check syntax check script without executing\n "
3478
+ " -i, --interactive always enter the REPL even if stdin\n "
3479
+ " does not appear to be a terminal\n "
3480
+ " -r, --require module to preload (option can be "
3481
+ " repeated)\n "
3482
+ " --no-deprecation silence deprecation warnings\n "
3483
+ " --trace-deprecation show stack traces on deprecations\n "
3484
+ " --throw-deprecation throw an exception anytime a deprecated "
3476
3485
" function is used\n "
3477
- " --no-warnings silence all process warnings\n "
3478
- " --trace-warnings show stack traces on process warnings\n "
3479
- " --trace-sync-io show stack trace when use of sync IO\n "
3480
- " is detected after the first tick\n "
3481
- " --track-heap-objects track heap object allocations for heap "
3486
+ " --no-warnings silence all process warnings\n "
3487
+ " --trace-warnings show stack traces on process warnings\n "
3488
+ " --trace-sync-io show stack trace when use of sync IO\n "
3489
+ " is detected after the first tick\n "
3490
+ " --trace-events-enabled track trace events\n "
3491
+ " --trace-event-categories comma separated list of trace event\n "
3492
+ " categories to record\n "
3493
+ " --track-heap-objects track heap object allocations for heap "
3482
3494
" snapshots\n "
3483
- " --prof-process process v8 profiler output generated\n "
3484
- " using --prof\n "
3485
- " --zero-fill-buffers automatically zero-fill all newly allocated\n "
3486
- " Buffer and SlowBuffer instances\n "
3487
- " --v8-options print v8 command line options\n "
3488
- " --v8-pool-size=num set v8's thread pool size\n "
3495
+ " --prof-process process v8 profiler output generated\n "
3496
+ " using --prof\n "
3497
+ " --zero-fill-buffers automatically zero-fill all newly "
3498
+ " allocated\n "
3499
+ " Buffer and SlowBuffer instances\n "
3500
+ " --v8-options print v8 command line options\n "
3501
+ " --v8-pool-size=num set v8's thread pool size\n "
3489
3502
#if HAVE_OPENSSL
3490
- " --tls-cipher-list=val use an alternative default TLS cipher list\n "
3503
+ " --tls-cipher-list=val use an alternative default TLS cipher "
3504
+ " list\n "
3491
3505
#if NODE_FIPS_MODE
3492
- " --enable-fips enable FIPS crypto at startup\n "
3493
- " --force-fips force FIPS crypto (cannot be disabled)\n "
3506
+ " --enable-fips enable FIPS crypto at startup\n "
3507
+ " --force-fips force FIPS crypto (cannot be disabled)\n "
3494
3508
#endif /* NODE_FIPS_MODE */
3495
- " --openssl-config=path load OpenSSL configuration file from the\n "
3496
- " specified path\n "
3509
+ " --openssl-config=path load OpenSSL configuration file from the\n "
3510
+ " specified path\n "
3497
3511
#endif /* HAVE_OPENSSL */
3498
3512
#if defined(NODE_HAVE_I18N_SUPPORT)
3499
- " --icu-data-dir=dir set ICU data load path to dir\n "
3500
- " (overrides NODE_ICU_DATA)\n "
3513
+ " --icu-data-dir=dir set ICU data load path to dir\n "
3514
+ " (overrides NODE_ICU_DATA)\n "
3501
3515
#if !defined(NODE_HAVE_SMALL_ICU)
3502
- " note: linked-in ICU data is\n "
3503
- " present.\n "
3516
+ " note: linked-in ICU data is\n "
3517
+ " present.\n "
3504
3518
#endif
3505
- " --preserve-symlinks preserve symbolic links when resolving\n "
3506
- " and caching modules.\n "
3519
+ " --preserve-symlinks preserve symbolic links when resolving\n "
3520
+ " and caching modules.\n "
3507
3521
#endif
3508
3522
" \n "
3509
3523
" Environment variables:\n "
3510
3524
#ifdef _WIN32
3511
- " NODE_PATH ';'-separated list of directories\n "
3525
+ " NODE_PATH ';'-separated list of directories\n "
3512
3526
#else
3513
- " NODE_PATH ':'-separated list of directories\n "
3527
+ " NODE_PATH ':'-separated list of directories\n "
3514
3528
#endif
3515
- " prefixed to the module search path.\n "
3516
- " NODE_DISABLE_COLORS set to 1 to disable colors in the REPL\n "
3529
+ " prefixed to the module search path.\n "
3530
+ " NODE_DISABLE_COLORS set to 1 to disable colors in the REPL\n "
3517
3531
#if defined(NODE_HAVE_I18N_SUPPORT)
3518
- " NODE_ICU_DATA data path for ICU (Intl object) data\n "
3532
+ " NODE_ICU_DATA data path for ICU (Intl object) data\n "
3519
3533
#if !defined(NODE_HAVE_SMALL_ICU)
3520
- " (will extend linked-in data)\n "
3534
+ " (will extend linked-in data)\n "
3521
3535
#endif
3522
3536
#endif
3523
- " NODE_REPL_HISTORY path to the persistent REPL history file\n "
3537
+ " NODE_REPL_HISTORY path to the persistent REPL history file\n "
3524
3538
" \n "
3525
3539
" Documentation can be found at https://nodejs.org/\n " );
3526
3540
}
@@ -3626,6 +3640,16 @@ static void ParseArgs(int* argc,
3626
3640
trace_deprecation = true ;
3627
3641
} else if (strcmp (arg, " --trace-sync-io" ) == 0 ) {
3628
3642
trace_sync_io = true ;
3643
+ } else if (strcmp (arg, " --trace-events-enabled" ) == 0 ) {
3644
+ trace_enabled = true ;
3645
+ } else if (strcmp (arg, " --trace-event-categories" ) == 0 ) {
3646
+ const char * categories = argv[index + 1 ];
3647
+ if (categories == nullptr ) {
3648
+ fprintf (stderr, " %s: %s requires an argument\n " , argv[0 ], arg);
3649
+ exit (9 );
3650
+ }
3651
+ args_consumed += 1 ;
3652
+ trace_enabled_categories = categories;
3629
3653
} else if (strcmp (arg, " --track-heap-objects" ) == 0 ) {
3630
3654
track_heap_objects = true ;
3631
3655
} else if (strcmp (arg, " --throw-deprecation" ) == 0 ) {
@@ -4454,10 +4478,20 @@ int Start(int argc, char** argv) {
4454
4478
#endif
4455
4479
4456
4480
v8_platform.Initialize (v8_thread_pool_size);
4481
+ // Enable tracing when argv has --trace-events-enabled.
4482
+ if (trace_enabled) {
4483
+ fprintf (stderr, " Warning: Trace event is an experimental feature "
4484
+ " and could change at any time.\n " );
4485
+ tracing_agent = new tracing::Agent ();
4486
+ tracing_agent->Start (v8_platform.platform_ , trace_enabled_categories);
4487
+ }
4457
4488
V8::Initialize ();
4458
4489
v8_initialized = true ;
4459
4490
const int exit_code =
4460
4491
Start (uv_default_loop (), argc, argv, exec_argc, exec_argv);
4492
+ if (trace_enabled) {
4493
+ tracing_agent->Stop ();
4494
+ }
4461
4495
v8_initialized = false ;
4462
4496
V8::Dispose ();
4463
4497
0 commit comments