From 2c3e41754fde2dfb0821cfff3938dc3d7339b010 Mon Sep 17 00:00:00 2001 From: Bradley Meck Date: Mon, 10 Aug 2015 11:32:39 -0500 Subject: [PATCH 1/4] add cpu-profile flag --- doc/iojs.1 | 2 ++ src/node.cc | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/doc/iojs.1 b/doc/iojs.1 index 0512d5e75cdd37..691c4e450464ea 100644 --- a/doc/iojs.1 +++ b/doc/iojs.1 @@ -62,6 +62,8 @@ and servers. --track-heap-objects track heap object allocations for heap snapshots + --profile-cpu begin cpu profiler during start up + --v8-options print v8 command line options diff --git a/src/node.cc b/src/node.cc index c272139e5518cd..3ed7333a43c377 100644 --- a/src/node.cc +++ b/src/node.cc @@ -119,6 +119,8 @@ static bool throw_deprecation = false; static bool abort_on_uncaught_exception = false; static bool trace_sync_io = false; static bool track_heap_objects = false; +static bool profile_cpu = false; +static const char* profile_title = ""; static const char* eval_string = nullptr; static unsigned int preload_module_count = 0; static const char** preload_modules = nullptr; @@ -3105,6 +3107,7 @@ static void PrintHelp() { " is detected after the first tick\n" " --track-heap-objects track heap object allocations for heap " "snapshots\n" + " --profile-cpu being cpu profile during start up\n" " --v8-options print v8 command line options\n" #if defined(NODE_HAVE_I18N_SUPPORT) " --icu-data-dir=dir set ICU data load path to dir\n" @@ -3227,6 +3230,8 @@ static void ParseArgs(int* argc, trace_deprecation = true; } else if (strcmp(arg, "--trace-sync-io") == 0) { trace_sync_io = true; + } else if (strcmp(arg, "--profile-cpu") == 0) { + profile_cpu = true; } else if (strcmp(arg, "--track-heap-objects") == 0) { track_heap_objects = true; } else if (strcmp(arg, "--throw-deprecation") == 0) { @@ -3927,6 +3932,10 @@ static void StartNodeInstance(void* arg) { isolate->GetHeapProfiler()->StartTrackingHeapObjects(true); } + if (profile_cpu) { + isolate->GetCpuProfiler()->StartProfiling(String::NewFromUtf8(isolate, profile_title), true); + } + // Fetch a reference to the main isolate, so we have a reference to it // even when we need it to access it from another (debugger) thread. if (instance_data->is_main()) From 1660a7d9a667907b58fe6ef5757f8e6bbd2a85e9 Mon Sep 17 00:00:00 2001 From: Bradley Meck Date: Mon, 10 Aug 2015 12:07:23 -0500 Subject: [PATCH 2/4] move cpu profile location due to handle scope --- src/node.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/node.cc b/src/node.cc index 3ed7333a43c377..1a2fb9afdf2cd1 100644 --- a/src/node.cc +++ b/src/node.cc @@ -3932,10 +3932,6 @@ static void StartNodeInstance(void* arg) { isolate->GetHeapProfiler()->StartTrackingHeapObjects(true); } - if (profile_cpu) { - isolate->GetCpuProfiler()->StartProfiling(String::NewFromUtf8(isolate, profile_title), true); - } - // Fetch a reference to the main isolate, so we have a reference to it // even when we need it to access it from another (debugger) thread. if (instance_data->is_main()) @@ -3945,6 +3941,12 @@ static void StartNodeInstance(void* arg) { Isolate::Scope isolate_scope(isolate); HandleScope handle_scope(isolate); Local context = Context::New(isolate); + + // CpuProfiler requires HandleScope + if (profile_cpu) { + isolate->GetCpuProfiler()->StartProfiling(String::NewFromUtf8(isolate, profile_title), true); + } + Environment* env = CreateEnvironment(isolate, context, instance_data); Context::Scope context_scope(context); if (instance_data->is_main()) From 600ac7417ae80c5ec2c8e4bd2ff066309e10bb79 Mon Sep 17 00:00:00 2001 From: Bradley Meck Date: Tue, 11 Aug 2015 19:42:18 -0400 Subject: [PATCH 3/4] add --profile-cpu command line flag --- doc/iojs.1 | 2 +- src/node.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/iojs.1 b/doc/iojs.1 index 691c4e450464ea..418b057b4b0b31 100644 --- a/doc/iojs.1 +++ b/doc/iojs.1 @@ -62,7 +62,7 @@ and servers. --track-heap-objects track heap object allocations for heap snapshots - --profile-cpu begin cpu profiler during start up + --profile-cpu begin cpu profiling during start up --v8-options print v8 command line options diff --git a/src/node.cc b/src/node.cc index 1a2fb9afdf2cd1..5df18fdb89a11e 100644 --- a/src/node.cc +++ b/src/node.cc @@ -3107,7 +3107,7 @@ static void PrintHelp() { " is detected after the first tick\n" " --track-heap-objects track heap object allocations for heap " "snapshots\n" - " --profile-cpu being cpu profile during start up\n" + " --profile-cpu being cpu profiling during start up\n" " --v8-options print v8 command line options\n" #if defined(NODE_HAVE_I18N_SUPPORT) " --icu-data-dir=dir set ICU data load path to dir\n" From 4343fdf4cc5eab87f1182c26ba856fca15187460 Mon Sep 17 00:00:00 2001 From: Bradley Meck Date: Wed, 12 Aug 2015 08:07:31 -0400 Subject: [PATCH 4/4] remove unsued char*, better docs on --profile-cpu --- doc/iojs.1 | 2 +- src/node.cc | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/iojs.1 b/doc/iojs.1 index 418b057b4b0b31..0f28e6f02beb94 100644 --- a/doc/iojs.1 +++ b/doc/iojs.1 @@ -62,7 +62,7 @@ and servers. --track-heap-objects track heap object allocations for heap snapshots - --profile-cpu begin cpu profiling during start up + --profile-cpu silently begin cpu profiler during start up --v8-options print v8 command line options diff --git a/src/node.cc b/src/node.cc index 5df18fdb89a11e..4d686789d7c22d 100644 --- a/src/node.cc +++ b/src/node.cc @@ -120,7 +120,6 @@ static bool abort_on_uncaught_exception = false; static bool trace_sync_io = false; static bool track_heap_objects = false; static bool profile_cpu = false; -static const char* profile_title = ""; static const char* eval_string = nullptr; static unsigned int preload_module_count = 0; static const char** preload_modules = nullptr; @@ -3107,7 +3106,7 @@ static void PrintHelp() { " is detected after the first tick\n" " --track-heap-objects track heap object allocations for heap " "snapshots\n" - " --profile-cpu being cpu profiling during start up\n" + " --profile-cpu silently begin cpu profiler during start up\n" " --v8-options print v8 command line options\n" #if defined(NODE_HAVE_I18N_SUPPORT) " --icu-data-dir=dir set ICU data load path to dir\n" @@ -3943,8 +3942,9 @@ static void StartNodeInstance(void* arg) { Local context = Context::New(isolate); // CpuProfiler requires HandleScope + // addons can pick up the results with StopProfiling(...) using same title if (profile_cpu) { - isolate->GetCpuProfiler()->StartProfiling(String::NewFromUtf8(isolate, profile_title), true); + isolate->GetCpuProfiler()->StartProfiling(String::Empty(isolate), true); } Environment* env = CreateEnvironment(isolate, context, instance_data);