Skip to content

Commit cf14a24

Browse files
bmecktrevnorris
authored andcommitted
src: add --track-heap-objects
- This makes v8 add .trace_function_info to the serialized form of snapshots from v8::HeapSnapshot::Serialize - .trace_funciton_info combined with .trace_node in snapshots tells the JS location that allocated a specific object PR-URL: #2135 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
1 parent 23efb05 commit cf14a24

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

doc/iojs.1

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ and servers.
6060

6161
--throw-deprecation throw errors on deprecations
6262

63+
--track-heap-objects track heap object allocations for heap snapshots
64+
6365
--v8-options print v8 command line options
6466

6567

src/node.cc

+32-23
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ static bool trace_deprecation = false;
117117
static bool throw_deprecation = false;
118118
static bool abort_on_uncaught_exception = false;
119119
static bool trace_sync_io = false;
120+
static bool track_heap_objects = false;
120121
static const char* eval_string = nullptr;
121122
static unsigned int preload_module_count = 0;
122123
static const char** preload_modules = nullptr;
@@ -3053,40 +3054,42 @@ static void PrintHelp() {
30533054
" iojs debug script.js [arguments] \n"
30543055
"\n"
30553056
"Options:\n"
3056-
" -v, --version print io.js version\n"
3057-
" -e, --eval script evaluate script\n"
3058-
" -p, --print evaluate script and print result\n"
3059-
" -i, --interactive always enter the REPL even if stdin\n"
3060-
" does not appear to be a terminal\n"
3061-
" -r, --require module to preload (option can be repeated)\n"
3062-
" --no-deprecation silence deprecation warnings\n"
3063-
" --throw-deprecation throw an exception anytime a deprecated "
3057+
" -v, --version print io.js version\n"
3058+
" -e, --eval script evaluate script\n"
3059+
" -p, --print evaluate script and print result\n"
3060+
" -i, --interactive always enter the REPL even if stdin\n"
3061+
" does not appear to be a terminal\n"
3062+
" -r, --require module to preload (option can be repeated)\n"
3063+
" --no-deprecation silence deprecation warnings\n"
3064+
" --throw-deprecation throw an exception anytime a deprecated "
30643065
"function is used\n"
3065-
" --trace-deprecation show stack traces on deprecations\n"
3066-
" --trace-sync-io show stack trace when use of sync IO\n"
3067-
" is detected after the first tick\n"
3068-
" --v8-options print v8 command line options\n"
3066+
" --trace-deprecation show stack traces on deprecations\n"
3067+
" --trace-sync-io show stack trace when use of sync IO\n"
3068+
" is detected after the first tick\n"
3069+
" --track-heap-objects track heap object allocations for heap "
3070+
"snapshots\n"
3071+
" --v8-options print v8 command line options\n"
30693072
#if defined(NODE_HAVE_I18N_SUPPORT)
3070-
" --icu-data-dir=dir set ICU data load path to dir\n"
3071-
" (overrides NODE_ICU_DATA)\n"
3073+
" --icu-data-dir=dir set ICU data load path to dir\n"
3074+
" (overrides NODE_ICU_DATA)\n"
30723075
#if !defined(NODE_HAVE_SMALL_ICU)
3073-
" Note: linked-in ICU data is\n"
3074-
" present.\n"
3076+
" Note: linked-in ICU data is\n"
3077+
" present.\n"
30753078
#endif
30763079
#endif
30773080
"\n"
30783081
"Environment variables:\n"
30793082
#ifdef _WIN32
3080-
"NODE_PATH ';'-separated list of directories\n"
3083+
"NODE_PATH ';'-separated list of directories\n"
30813084
#else
3082-
"NODE_PATH ':'-separated list of directories\n"
3085+
"NODE_PATH ':'-separated list of directories\n"
30833086
#endif
3084-
" prefixed to the module search path.\n"
3085-
"NODE_DISABLE_COLORS Set to 1 to disable colors in the REPL\n"
3087+
" prefixed to the module search path.\n"
3088+
"NODE_DISABLE_COLORS Set to 1 to disable colors in the REPL\n"
30863089
#if defined(NODE_HAVE_I18N_SUPPORT)
3087-
"NODE_ICU_DATA Data path for ICU (Intl object) data\n"
3090+
"NODE_ICU_DATA Data path for ICU (Intl object) data\n"
30883091
#if !defined(NODE_HAVE_SMALL_ICU)
3089-
" (will extend linked-in data)\n"
3092+
" (will extend linked-in data)\n"
30903093
#endif
30913094
#endif
30923095
"\n"
@@ -3187,6 +3190,8 @@ static void ParseArgs(int* argc,
31873190
trace_deprecation = true;
31883191
} else if (strcmp(arg, "--trace-sync-io") == 0) {
31893192
trace_sync_io = true;
3193+
} else if (strcmp(arg, "--track-heap-objects") == 0) {
3194+
track_heap_objects = true;
31903195
} else if (strcmp(arg, "--throw-deprecation") == 0) {
31913196
throw_deprecation = true;
31923197
} else if (strcmp(arg, "--abort-on-uncaught-exception") == 0 ||
@@ -3876,7 +3881,11 @@ Environment* CreateEnvironment(Isolate* isolate,
38763881
static void StartNodeInstance(void* arg) {
38773882
NodeInstanceData* instance_data = static_cast<NodeInstanceData*>(arg);
38783883
Isolate* isolate = Isolate::New();
3879-
// Fetch a reference to the main isolate, so we have a reference to it
3884+
if (track_heap_objects) {
3885+
isolate->GetHeapProfiler()->StartTrackingHeapObjects(true);
3886+
}
3887+
3888+
// Fetch a reference to the main isolate, so we have a reference to it
38803889
// even when we need it to access it from another (debugger) thread.
38813890
if (instance_data->is_main())
38823891
node_isolate = isolate;

0 commit comments

Comments
 (0)