Index: runtime/bin/main.cc |
diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc |
index 7505ad1c252bce5910c4c79fb80b5ffddbb201a5..5e72cc3ee2d574504dc099ac9a5652d9a0d1ed1a 100644 |
--- a/runtime/bin/main.cc |
+++ b/runtime/bin/main.cc |
@@ -32,6 +32,15 @@ extern const uint8_t* snapshot_buffer; |
static File* perf_events_symbols_file = NULL; |
+// Global state that indicates whether heap tracing is on. |
+static bool heap_trace = false; |
+ |
+ |
+// Global state that indicates the file name prefix to use for heap |
+// trace output files. |
+static const char* heap_trace_file_prefix = "dart_heap_trace"; |
+ |
+ |
// Global state that indicates whether pprof symbol information is |
// to be generated or not. |
static const char* generate_pprof_symbols_filename = NULL; |
@@ -180,6 +189,20 @@ static bool ProcessPprofOption(const char* filename) { |
} |
+static bool ProcessHeapTraceOption(const char* heap_trace_option) { |
+ heap_trace = true; |
+ return true; |
+} |
+ |
+ |
+static bool ProcessHeapTraceFilePrefixOption( |
+ const char* heap_trace_file_prefix_option) { |
+ ASSERT(heap_trace_file_prefix_option != NULL); |
+ heap_trace_file_prefix = heap_trace_file_prefix_option; |
+ return true; |
+} |
+ |
+ |
static bool ProcessScriptSnapshotOption(const char* filename) { |
if (filename != NULL && strlen(filename) != 0) { |
use_script_snapshot = true; |
@@ -207,6 +230,8 @@ static struct { |
{ "--debug", ProcessDebugOption }, |
{ "--generate_perf_events_symbols", ProcessPerfEventsOption }, |
{ "--generate_pprof_symbols=", ProcessPprofOption }, |
+ { "--heap_trace", ProcessHeapTraceOption }, |
+ { "--heap_trace_file_prefix=", ProcessHeapTraceFilePrefixOption }, |
{ "--use_script_snapshot=", ProcessScriptSnapshotOption }, |
{ NULL, NULL } |
}; |
@@ -232,6 +257,34 @@ static void WriteToPerfEventsFile(const char* buffer, int64_t num_bytes) { |
perf_events_symbols_file->WriteFully(buffer, num_bytes); |
} |
+ |
+// This function used by the heap trace to open new trace files, one |
+// file per isolate. |
+static void* OpenHeapTraceFile(const char* name) { |
+ File* file = File::Open(name, File::kWriteTruncate); |
+ ASSERT(file != NULL); |
+ return reinterpret_cast<void*>(file); |
+} |
+ |
+ |
+// Function used by the heap trace to write to trace files. |
+static void WriteToHeapTraceFile(const void* buffer, |
+ intptr_t num_bytes, |
+ void* stream) { |
+ ASSERT(stream != NULL); |
+ File* file_stream = reinterpret_cast<File*>(stream); |
+ bool bytes_written = file_stream->WriteFully(buffer, num_bytes); |
+ ASSERT(bytes_written); |
+} |
+ |
+ |
+// Function used by the heap trace to close trace files. |
+static void CloseHeapTraceFile(void* stream) { |
+ File* file_stream = reinterpret_cast<File*>(stream); |
+ delete file_stream; // Closes the file. |
+} |
+ |
+ |
// Convert all the arguments to UTF8. On Windows, the arguments are |
// encoded in the current code page and not UTF8. |
// |
@@ -298,6 +351,13 @@ static int ParseArguments(int argc, |
Dart_InitPprofSupport(); |
} |
+ if (heap_trace) { |
+ Dart_InitHeapTrace(&OpenHeapTraceFile, |
+ &WriteToHeapTraceFile, |
+ &CloseHeapTraceFile, |
+ heap_trace_file_prefix); |
+ } |
+ |
// Get the script name. |
if (i < argc) { |
*script_name = argv[i]; |