Index: src/heap-snapshot-generator.cc |
diff --git a/src/heap-snapshot-generator.cc b/src/heap-snapshot-generator.cc |
index 5864ad9b43fb9e82cf55b8e35a0bd0a3749d3ee7..ce9d705cd5e5730a2424a5ac87963474bd623191 100644 |
--- a/src/heap-snapshot-generator.cc |
+++ b/src/heap-snapshot-generator.cc |
@@ -2743,6 +2743,11 @@ void HeapSnapshotJSONSerializer::SerializeImpl() { |
if (writer_->aborted()) return; |
writer_->AddString("],\n"); |
+ writer_->AddString("\"samples\":["); |
+ SerializeSamples(); |
+ if (writer_->aborted()) return; |
+ writer_->AddString("],\n"); |
+ |
writer_->AddString("\"strings\":["); |
SerializeStrings(); |
if (writer_->aborted()) return; |
@@ -2939,7 +2944,10 @@ void HeapSnapshotJSONSerializer::SerializeSnapshot() { |
JSON_S("function_info_index") "," |
JSON_S("count") "," |
JSON_S("size") "," |
- JSON_S("children")))); |
+ JSON_S("children")) "," |
+ JSON_S("sample_fields") ":" JSON_A( |
+ JSON_S("timstamp_ms") "," |
+ JSON_S("next_object_id")))); |
#undef JSON_S |
#undef JSON_O |
#undef JSON_A |
@@ -2954,6 +2962,10 @@ void HeapSnapshotJSONSerializer::SerializeSnapshot() { |
count = tracker->function_info_list().length(); |
} |
writer_->AddNumber(count); |
+ writer_->AddString(",\"sample_count\":"); |
+ const List<HeapObjectsMap::TimeInterval>& samples = |
+ snapshot_->profiler()->heap_object_map()->samples(); |
+ writer_->AddNumber(samples.length()); |
} |
@@ -3057,6 +3069,38 @@ void HeapSnapshotJSONSerializer::SerializeTraceNodeInfos() { |
} |
+void HeapSnapshotJSONSerializer::SerializeSamples() { |
+ const List<HeapObjectsMap::TimeInterval>& samples = |
+ snapshot_->profiler()->heap_object_map()->samples(); |
+ if (samples.is_empty()) return; |
+ base::TimeTicks start_time = samples[0].timestamp; |
+ // The buffer needs space for 2 unsigned ints, 2 commas, \n and \0 |
+ const int kBufferSize = |
+ 2 * MaxDecimalDigitsIn<sizeof( |
+ base::TimeDelta().InMilliseconds())>::kUnsigned // NOLINT |
alph
2015/03/19 14:05:27
one is timedelta, another is id. these are two dif
yurys
2015/03/19 14:13:26
Done.
|
+ + |
+ 2 + 1 + 1; |
+ EmbeddedVector<char, kBufferSize> buffer; |
+ bool first_entry = true; |
+ for (int i = 0; i < samples.length(); i++) { |
+ HeapObjectsMap::TimeInterval& sample = samples[i]; |
+ int buffer_pos = 0; |
+ if (first_entry) { |
alph
2015/03/19 14:05:27
i != 0
yurys
2015/03/19 14:13:26
Done.
|
+ first_entry = false; |
+ } else { |
+ buffer[buffer_pos++] = ','; |
+ } |
+ base::TimeDelta time_delta = sample.timestamp - start_time; |
+ buffer_pos = utoa(time_delta.InMilliseconds(), buffer, buffer_pos); |
alph
2015/03/19 14:05:27
Let's use microseconds as we do in cpu profiler to
yurys
2015/03/19 14:13:26
Done.
|
+ buffer[buffer_pos++] = ','; |
+ buffer_pos = utoa(sample.id, buffer, buffer_pos); |
+ buffer[buffer_pos++] = '\n'; |
+ buffer[buffer_pos++] = '\0'; |
+ writer_->AddString(buffer.start()); |
+ } |
+} |
+ |
+ |
void HeapSnapshotJSONSerializer::SerializeString(const unsigned char* s) { |
writer_->AddCharacter('\n'); |
writer_->AddCharacter('\"'); |