Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile on start #2354

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/iojs.1
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
11 changes: 11 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -3936,6 +3940,13 @@ static void StartNodeInstance(void* arg) {
Isolate::Scope isolate_scope(isolate);
HandleScope handle_scope(isolate);
Local<Context> context = Context::New(isolate);

// CpuProfiler requires HandleScope
// addons can pick up the results with StopProfiling(...) using same title
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please capitalize and punctuate the comment.

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())
Expand Down