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

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("timestamp_us") ","
2950 JSON_S("last_assigned_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();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
3021 void HeapSnapshotJSONSerializer::SerializeTraceNodeInfos() { 3029 void HeapSnapshotJSONSerializer::SerializeTraceNodeInfos() {
3022 AllocationTracker* tracker = snapshot_->profiler()->allocation_tracker(); 3030 AllocationTracker* tracker = snapshot_->profiler()->allocation_tracker();
3023 if (!tracker) return; 3031 if (!tracker) return;
3024 // The buffer needs space for 6 unsigned ints, 6 commas, \n and \0 3032 // The buffer needs space for 6 unsigned ints, 6 commas, \n and \0
3025 const int kBufferSize = 3033 const int kBufferSize =
3026 6 * MaxDecimalDigitsIn<sizeof(unsigned)>::kUnsigned // NOLINT 3034 6 * MaxDecimalDigitsIn<sizeof(unsigned)>::kUnsigned // NOLINT
3027 + 6 + 1 + 1; 3035 + 6 + 1 + 1;
3028 EmbeddedVector<char, kBufferSize> buffer; 3036 EmbeddedVector<char, kBufferSize> buffer;
3029 const List<AllocationTracker::FunctionInfo*>& list = 3037 const List<AllocationTracker::FunctionInfo*>& list =
3030 tracker->function_info_list(); 3038 tracker->function_info_list();
3031 bool first_entry = true;
3032 for (int i = 0; i < list.length(); i++) { 3039 for (int i = 0; i < list.length(); i++) {
3033 AllocationTracker::FunctionInfo* info = list[i]; 3040 AllocationTracker::FunctionInfo* info = list[i];
3034 int buffer_pos = 0; 3041 int buffer_pos = 0;
3035 if (first_entry) { 3042 if (i > 0) {
3036 first_entry = false;
3037 } else {
3038 buffer[buffer_pos++] = ','; 3043 buffer[buffer_pos++] = ',';
3039 } 3044 }
3040 buffer_pos = utoa(info->function_id, buffer, buffer_pos); 3045 buffer_pos = utoa(info->function_id, buffer, buffer_pos);
3041 buffer[buffer_pos++] = ','; 3046 buffer[buffer_pos++] = ',';
3042 buffer_pos = utoa(GetStringId(info->name), buffer, buffer_pos); 3047 buffer_pos = utoa(GetStringId(info->name), buffer, buffer_pos);
3043 buffer[buffer_pos++] = ','; 3048 buffer[buffer_pos++] = ',';
3044 buffer_pos = utoa(GetStringId(info->script_name), buffer, buffer_pos); 3049 buffer_pos = utoa(GetStringId(info->script_name), buffer, buffer_pos);
3045 buffer[buffer_pos++] = ','; 3050 buffer[buffer_pos++] = ',';
3046 // The cast is safe because script id is a non-negative Smi. 3051 // The cast is safe because script id is a non-negative Smi.
3047 buffer_pos = utoa(static_cast<unsigned>(info->script_id), buffer, 3052 buffer_pos = utoa(static_cast<unsigned>(info->script_id), buffer,
3048 buffer_pos); 3053 buffer_pos);
3049 buffer[buffer_pos++] = ','; 3054 buffer[buffer_pos++] = ',';
3050 buffer_pos = SerializePosition(info->line, buffer, buffer_pos); 3055 buffer_pos = SerializePosition(info->line, buffer, buffer_pos);
3051 buffer[buffer_pos++] = ','; 3056 buffer[buffer_pos++] = ',';
3052 buffer_pos = SerializePosition(info->column, buffer, buffer_pos); 3057 buffer_pos = SerializePosition(info->column, buffer, buffer_pos);
3053 buffer[buffer_pos++] = '\n'; 3058 buffer[buffer_pos++] = '\n';
3054 buffer[buffer_pos++] = '\0'; 3059 buffer[buffer_pos++] = '\0';
3055 writer_->AddString(buffer.start()); 3060 writer_->AddString(buffer.start());
3056 } 3061 }
3057 } 3062 }
3058 3063
3059 3064
3065 void HeapSnapshotJSONSerializer::SerializeSamples() {
3066 const List<HeapObjectsMap::TimeInterval>& samples =
3067 snapshot_->profiler()->heap_object_map()->samples();
3068 if (samples.is_empty()) return;
3069 base::TimeTicks start_time = samples[0].timestamp;
3070 // The buffer needs space for 2 unsigned ints, 2 commas, \n and \0
3071 const int kBufferSize = MaxDecimalDigitsIn<sizeof(
3072 base::TimeDelta().InMicroseconds())>::kUnsigned +
3073 MaxDecimalDigitsIn<sizeof(samples[0].id)>::kUnsigned +
3074 2 + 1 + 1;
3075 EmbeddedVector<char, kBufferSize> buffer;
3076 for (int i = 0; i < samples.length(); i++) {
3077 HeapObjectsMap::TimeInterval& sample = samples[i];
3078 int buffer_pos = 0;
3079 if (i > 0) {
3080 buffer[buffer_pos++] = ',';
3081 }
3082 base::TimeDelta time_delta = sample.timestamp - start_time;
3083 buffer_pos = utoa(time_delta.InMicroseconds(), buffer, buffer_pos);
3084 buffer[buffer_pos++] = ',';
3085 buffer_pos = utoa(sample.last_assigned_id(), buffer, buffer_pos);
3086 buffer[buffer_pos++] = '\n';
3087 buffer[buffer_pos++] = '\0';
3088 writer_->AddString(buffer.start());
3089 }
3090 }
3091
3092
3060 void HeapSnapshotJSONSerializer::SerializeString(const unsigned char* s) { 3093 void HeapSnapshotJSONSerializer::SerializeString(const unsigned char* s) {
3061 writer_->AddCharacter('\n'); 3094 writer_->AddCharacter('\n');
3062 writer_->AddCharacter('\"'); 3095 writer_->AddCharacter('\"');
3063 for ( ; *s != '\0'; ++s) { 3096 for ( ; *s != '\0'; ++s) {
3064 switch (*s) { 3097 switch (*s) {
3065 case '\b': 3098 case '\b':
3066 writer_->AddString("\\b"); 3099 writer_->AddString("\\b");
3067 continue; 3100 continue;
3068 case '\f': 3101 case '\f':
3069 writer_->AddString("\\f"); 3102 writer_->AddString("\\f");
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
3119 writer_->AddString("\"<dummy>\""); 3152 writer_->AddString("\"<dummy>\"");
3120 for (int i = 1; i < sorted_strings.length(); ++i) { 3153 for (int i = 1; i < sorted_strings.length(); ++i) {
3121 writer_->AddCharacter(','); 3154 writer_->AddCharacter(',');
3122 SerializeString(sorted_strings[i]); 3155 SerializeString(sorted_strings[i]);
3123 if (writer_->aborted()) return; 3156 if (writer_->aborted()) return;
3124 } 3157 }
3125 } 3158 }
3126 3159
3127 3160
3128 } } // namespace v8::internal 3161 } } // 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