diff --git a/doc/iojs.1 b/doc/iojs.1 index 0512d5e75cdd37..0f28e6f02beb94 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 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 c272139e5518cd..4d686789d7c22d 100644 --- a/src/node.cc +++ b/src/node.cc @@ -119,6 +119,7 @@ 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* eval_string = nullptr; static unsigned int preload_module_count = 0; static const char** preload_modules = nullptr; @@ -3105,6 +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 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" @@ -3227,6 +3229,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) { @@ -3936,6 +3940,13 @@ static void StartNodeInstance(void* arg) { Isolate::Scope isolate_scope(isolate); HandleScope handle_scope(isolate); 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::Empty(isolate), true); + } + Environment* env = CreateEnvironment(isolate, context, instance_data); Context::Scope context_scope(context); if (instance_data->is_main())