3838#include " req-wrap.h"
3939#include " req-wrap-inl.h"
4040#include " string_bytes.h"
41+ #include " tracing/agent.h"
4142#include " util.h"
4243#include " uv.h"
4344#if NODE_USE_V8_PLATFORM
@@ -150,6 +151,8 @@ static node_module* modpending;
150151static node_module* modlist_builtin;
151152static node_module* modlist_linked;
152153static node_module* modlist_addon;
154+ static bool trace_enabled = false ;
155+ static const char * trace_enabled_categories = nullptr ;
153156
154157#if defined(NODE_HAVE_I18N_SUPPORT)
155158// Path to ICU data (for i18n / Intl)
@@ -186,6 +189,7 @@ static uv_async_t dispatch_debug_messages_async;
186189
187190static Mutex node_isolate_mutex;
188191static v8::Isolate* node_isolate;
192+ static tracing::Agent* tracing_agent;
189193
190194static node::DebugOptions debug_options;
191195
@@ -194,6 +198,7 @@ static struct {
194198 void Initialize (int thread_pool_size) {
195199 platform_ = v8::platform::CreateDefaultPlatform (thread_pool_size);
196200 V8::InitializePlatform (platform_);
201+ tracing::TraceEventHelper::SetCurrentPlatform (platform_);
197202 }
198203
199204 void PumpMessageLoop (Isolate* isolate) {
@@ -3368,6 +3373,9 @@ void SetupProcessObject(Environment* env,
33683373
33693374void SignalExit (int signo) {
33703375 uv_tty_reset_mode ();
3376+ if (trace_enabled) {
3377+ tracing_agent->Stop ();
3378+ }
33713379#ifdef __FreeBSD__
33723380 // FreeBSD has a nasty bug, see RegisterSignalHandler for details
33733381 struct sigaction sa;
@@ -3463,64 +3471,70 @@ static void PrintHelp() {
34633471 " node debug script.js [arguments] \n "
34643472 " \n "
34653473 " 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 "
34763485 " 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 "
34823494 " 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 "
34893502#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 "
34913505#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 "
34943508#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 "
34973511#endif /* HAVE_OPENSSL */
34983512#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 "
35013515#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 "
35043518#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 "
35073521#endif
35083522 " \n "
35093523 " Environment variables:\n "
35103524#ifdef _WIN32
3511- " NODE_PATH ';'-separated list of directories\n "
3525+ " NODE_PATH ';'-separated list of directories\n "
35123526#else
3513- " NODE_PATH ':'-separated list of directories\n "
3527+ " NODE_PATH ':'-separated list of directories\n "
35143528#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 "
35173531#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 "
35193533#if !defined(NODE_HAVE_SMALL_ICU)
3520- " (will extend linked-in data)\n "
3534+ " (will extend linked-in data)\n "
35213535#endif
35223536#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 "
35243538 " \n "
35253539 " Documentation can be found at https://nodejs.org/\n " );
35263540}
@@ -3626,6 +3640,16 @@ static void ParseArgs(int* argc,
36263640 trace_deprecation = true ;
36273641 } else if (strcmp (arg, " --trace-sync-io" ) == 0 ) {
36283642 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;
36293653 } else if (strcmp (arg, " --track-heap-objects" ) == 0 ) {
36303654 track_heap_objects = true ;
36313655 } else if (strcmp (arg, " --throw-deprecation" ) == 0 ) {
@@ -4454,10 +4478,20 @@ int Start(int argc, char** argv) {
44544478#endif
44554479
44564480 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+ }
44574488 V8::Initialize ();
44584489 v8_initialized = true ;
44594490 const int exit_code =
44604491 Start (uv_default_loop (), argc, argv, exec_argc, exec_argv);
4492+ if (trace_enabled) {
4493+ tracing_agent->Stop ();
4494+ }
44614495 v8_initialized = false ;
44624496 V8::Dispose ();
44634497
0 commit comments