Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: src/heap-snapshot-generator.cc

Issue 1019813004: Save heap object tracking data in heap snapshot (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap-snapshot-generator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/heap-snapshot-generator-inl.h" 7 #include "src/heap-snapshot-generator-inl.h"
8 8
9 #include "src/allocation-tracker.h" 9 #include "src/allocation-tracker.h"
10 #include "src/code-stubs.h" 10 #include "src/code-stubs.h"
(...skipping 2725 matching lines...) Expand 10 before | Expand all | Expand 10 after
2736 2736
2737 writer_->AddString("\"trace_function_infos\":["); 2737 writer_->AddString("\"trace_function_infos\":[");
2738 SerializeTraceNodeInfos(); 2738 SerializeTraceNodeInfos();
2739 if (writer_->aborted()) return; 2739 if (writer_->aborted()) return;
2740 writer_->AddString("],\n"); 2740 writer_->AddString("],\n");
2741 writer_->AddString("\"trace_tree\":["); 2741 writer_->AddString("\"trace_tree\":[");
2742 SerializeTraceTree(); 2742 SerializeTraceTree();
2743 if (writer_->aborted()) return; 2743 if (writer_->aborted()) return;
2744 writer_->AddString("],\n"); 2744 writer_->AddString("],\n");
2745 2745
2746 writer_->AddString("\"samples\":[");
2747 SerializeSamples();
2748 if (writer_->aborted()) return;
2749 writer_->AddString("],\n");
2750
2746 writer_->AddString("\"strings\":["); 2751 writer_->AddString("\"strings\":[");
2747 SerializeStrings(); 2752 SerializeStrings();
2748 if (writer_->aborted()) return; 2753 if (writer_->aborted()) return;
2749 writer_->AddCharacter(']'); 2754 writer_->AddCharacter(']');
2750 writer_->AddCharacter('}'); 2755 writer_->AddCharacter('}');
2751 writer_->Finalize(); 2756 writer_->Finalize();
2752 } 2757 }
2753 2758
2754 2759
2755 int HeapSnapshotJSONSerializer::GetStringId(const char* s) { 2760 int HeapSnapshotJSONSerializer::GetStringId(const char* s) {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
2932 JSON_S("name") "," 2937 JSON_S("name") ","
2933 JSON_S("script_name") "," 2938 JSON_S("script_name") ","
2934 JSON_S("script_id") "," 2939 JSON_S("script_id") ","
2935 JSON_S("line") "," 2940 JSON_S("line") ","
2936 JSON_S("column")) "," 2941 JSON_S("column")) ","
2937 JSON_S("trace_node_fields") ":" JSON_A( 2942 JSON_S("trace_node_fields") ":" JSON_A(
2938 JSON_S("id") "," 2943 JSON_S("id") ","
2939 JSON_S("function_info_index") "," 2944 JSON_S("function_info_index") ","
2940 JSON_S("count") "," 2945 JSON_S("count") ","
2941 JSON_S("size") "," 2946 JSON_S("size") ","
2942 JSON_S("children")))); 2947 JSON_S("children")) ","
2948 JSON_S("sample_fields") ":" JSON_A(
2949 JSON_S("timstamp_ms") ","
2950 JSON_S("next_object_id"))));
2943 #undef JSON_S 2951 #undef JSON_S
2944 #undef JSON_O 2952 #undef JSON_O
2945 #undef JSON_A 2953 #undef JSON_A
2946 writer_->AddString(",\"node_count\":"); 2954 writer_->AddString(",\"node_count\":");
2947 writer_->AddNumber(snapshot_->entries().length()); 2955 writer_->AddNumber(snapshot_->entries().length());
2948 writer_->AddString(",\"edge_count\":"); 2956 writer_->AddString(",\"edge_count\":");
2949 writer_->AddNumber(snapshot_->edges().length()); 2957 writer_->AddNumber(snapshot_->edges().length());
2950 writer_->AddString(",\"trace_function_count\":"); 2958 writer_->AddString(",\"trace_function_count\":");
2951 uint32_t count = 0; 2959 uint32_t count = 0;
2952 AllocationTracker* tracker = snapshot_->profiler()->allocation_tracker(); 2960 AllocationTracker* tracker = snapshot_->profiler()->allocation_tracker();
2953 if (tracker) { 2961 if (tracker) {
2954 count = tracker->function_info_list().length(); 2962 count = tracker->function_info_list().length();
2955 } 2963 }
2956 writer_->AddNumber(count); 2964 writer_->AddNumber(count);
2965 writer_->AddString(",\"sample_count\":");
2966 const List<HeapObjectsMap::TimeInterval>& samples =
2967 snapshot_->profiler()->heap_object_map()->samples();
2968 writer_->AddNumber(samples.length());
2957 } 2969 }
2958 2970
2959 2971
2960 static void WriteUChar(OutputStreamWriter* w, unibrow::uchar u) { 2972 static void WriteUChar(OutputStreamWriter* w, unibrow::uchar u) {
2961 static const char hex_chars[] = "0123456789ABCDEF"; 2973 static const char hex_chars[] = "0123456789ABCDEF";
2962 w->AddString("\\u"); 2974 w->AddString("\\u");
2963 w->AddCharacter(hex_chars[(u >> 12) & 0xf]); 2975 w->AddCharacter(hex_chars[(u >> 12) & 0xf]);
2964 w->AddCharacter(hex_chars[(u >> 8) & 0xf]); 2976 w->AddCharacter(hex_chars[(u >> 8) & 0xf]);
2965 w->AddCharacter(hex_chars[(u >> 4) & 0xf]); 2977 w->AddCharacter(hex_chars[(u >> 4) & 0xf]);
2966 w->AddCharacter(hex_chars[u & 0xf]); 2978 w->AddCharacter(hex_chars[u & 0xf]);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
3050 buffer_pos = SerializePosition(info->line, buffer, buffer_pos); 3062 buffer_pos = SerializePosition(info->line, buffer, buffer_pos);
3051 buffer[buffer_pos++] = ','; 3063 buffer[buffer_pos++] = ',';
3052 buffer_pos = SerializePosition(info->column, buffer, buffer_pos); 3064 buffer_pos = SerializePosition(info->column, buffer, buffer_pos);
3053 buffer[buffer_pos++] = '\n'; 3065 buffer[buffer_pos++] = '\n';
3054 buffer[buffer_pos++] = '\0'; 3066 buffer[buffer_pos++] = '\0';
3055 writer_->AddString(buffer.start()); 3067 writer_->AddString(buffer.start());
3056 } 3068 }
3057 } 3069 }
3058 3070
3059 3071
3072 void HeapSnapshotJSONSerializer::SerializeSamples() {
3073 const List<HeapObjectsMap::TimeInterval>& samples =
3074 snapshot_->profiler()->heap_object_map()->samples();
3075 if (samples.is_empty()) return;
3076 base::TimeTicks start_time = samples[0].timestamp;
3077 // The buffer needs space for 2 unsigned ints, 2 commas, \n and \0
3078 const int kBufferSize =
3079 2 * MaxDecimalDigitsIn<sizeof(
3080 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.
3081 +
3082 2 + 1 + 1;
3083 EmbeddedVector<char, kBufferSize> buffer;
3084 bool first_entry = true;
3085 for (int i = 0; i < samples.length(); i++) {
3086 HeapObjectsMap::TimeInterval& sample = samples[i];
3087 int buffer_pos = 0;
3088 if (first_entry) {
alph 2015/03/19 14:05:27 i != 0
yurys 2015/03/19 14:13:26 Done.
3089 first_entry = false;
3090 } else {
3091 buffer[buffer_pos++] = ',';
3092 }
3093 base::TimeDelta time_delta = sample.timestamp - start_time;
3094 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.
3095 buffer[buffer_pos++] = ',';
3096 buffer_pos = utoa(sample.id, buffer, buffer_pos);
3097 buffer[buffer_pos++] = '\n';
3098 buffer[buffer_pos++] = '\0';
3099 writer_->AddString(buffer.start());
3100 }
3101 }
3102
3103
3060 void HeapSnapshotJSONSerializer::SerializeString(const unsigned char* s) { 3104 void HeapSnapshotJSONSerializer::SerializeString(const unsigned char* s) {
3061 writer_->AddCharacter('\n'); 3105 writer_->AddCharacter('\n');
3062 writer_->AddCharacter('\"'); 3106 writer_->AddCharacter('\"');
3063 for ( ; *s != '\0'; ++s) { 3107 for ( ; *s != '\0'; ++s) {
3064 switch (*s) { 3108 switch (*s) {
3065 case '\b': 3109 case '\b':
3066 writer_->AddString("\\b"); 3110 writer_->AddString("\\b");
3067 continue; 3111 continue;
3068 case '\f': 3112 case '\f':
3069 writer_->AddString("\\f"); 3113 writer_->AddString("\\f");
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
3119 writer_->AddString("\"<dummy>\""); 3163 writer_->AddString("\"<dummy>\"");
3120 for (int i = 1; i < sorted_strings.length(); ++i) { 3164 for (int i = 1; i < sorted_strings.length(); ++i) {
3121 writer_->AddCharacter(','); 3165 writer_->AddCharacter(',');
3122 SerializeString(sorted_strings[i]); 3166 SerializeString(sorted_strings[i]);
3123 if (writer_->aborted()) return; 3167 if (writer_->aborted()) return;
3124 } 3168 }
3125 } 3169 }
3126 3170
3127 3171
3128 } } // namespace v8::internal 3172 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap-snapshot-generator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698