| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 2860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2871 JSON_S("node")) "," | 2871 JSON_S("node")) "," |
| 2872 JSON_S("trace_function_info_fields") ":" JSON_A( | 2872 JSON_S("trace_function_info_fields") ":" JSON_A( |
| 2873 JSON_S("function_id") "," | 2873 JSON_S("function_id") "," |
| 2874 JSON_S("name") "," | 2874 JSON_S("name") "," |
| 2875 JSON_S("script_name") "," | 2875 JSON_S("script_name") "," |
| 2876 JSON_S("script_id") "," | 2876 JSON_S("script_id") "," |
| 2877 JSON_S("line") "," | 2877 JSON_S("line") "," |
| 2878 JSON_S("column")) "," | 2878 JSON_S("column")) "," |
| 2879 JSON_S("trace_node_fields") ":" JSON_A( | 2879 JSON_S("trace_node_fields") ":" JSON_A( |
| 2880 JSON_S("id") "," | 2880 JSON_S("id") "," |
| 2881 JSON_S("function_id") "," | 2881 JSON_S("function_info_index") "," |
| 2882 JSON_S("count") "," | 2882 JSON_S("count") "," |
| 2883 JSON_S("size") "," | 2883 JSON_S("size") "," |
| 2884 JSON_S("children")))); | 2884 JSON_S("children")))); |
| 2885 #undef JSON_S | 2885 #undef JSON_S |
| 2886 #undef JSON_O | 2886 #undef JSON_O |
| 2887 #undef JSON_A | 2887 #undef JSON_A |
| 2888 writer_->AddString(",\"node_count\":"); | 2888 writer_->AddString(",\"node_count\":"); |
| 2889 writer_->AddNumber(snapshot_->entries().length()); | 2889 writer_->AddNumber(snapshot_->entries().length()); |
| 2890 writer_->AddString(",\"edge_count\":"); | 2890 writer_->AddString(",\"edge_count\":"); |
| 2891 writer_->AddNumber(snapshot_->edges().length()); | 2891 writer_->AddNumber(snapshot_->edges().length()); |
| 2892 writer_->AddString(",\"trace_function_count\":"); | 2892 writer_->AddString(",\"trace_function_count\":"); |
| 2893 uint32_t count = 0; | 2893 uint32_t count = 0; |
| 2894 AllocationTracker* tracker = snapshot_->profiler()->allocation_tracker(); | 2894 AllocationTracker* tracker = snapshot_->profiler()->allocation_tracker(); |
| 2895 if (tracker) { | 2895 if (tracker) { |
| 2896 count = tracker->id_to_function_info()->occupancy(); | 2896 count = tracker->function_info_list().length(); |
| 2897 } | 2897 } |
| 2898 writer_->AddNumber(count); | 2898 writer_->AddNumber(count); |
| 2899 } | 2899 } |
| 2900 | 2900 |
| 2901 | 2901 |
| 2902 static void WriteUChar(OutputStreamWriter* w, unibrow::uchar u) { | 2902 static void WriteUChar(OutputStreamWriter* w, unibrow::uchar u) { |
| 2903 static const char hex_chars[] = "0123456789ABCDEF"; | 2903 static const char hex_chars[] = "0123456789ABCDEF"; |
| 2904 w->AddString("\\u"); | 2904 w->AddString("\\u"); |
| 2905 w->AddCharacter(hex_chars[(u >> 12) & 0xf]); | 2905 w->AddCharacter(hex_chars[(u >> 12) & 0xf]); |
| 2906 w->AddCharacter(hex_chars[(u >> 8) & 0xf]); | 2906 w->AddCharacter(hex_chars[(u >> 8) & 0xf]); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2919 | 2919 |
| 2920 void HeapSnapshotJSONSerializer::SerializeTraceNode(AllocationTraceNode* node) { | 2920 void HeapSnapshotJSONSerializer::SerializeTraceNode(AllocationTraceNode* node) { |
| 2921 // The buffer needs space for 4 unsigned ints, 4 commas, [ and \0 | 2921 // The buffer needs space for 4 unsigned ints, 4 commas, [ and \0 |
| 2922 const int kBufferSize = | 2922 const int kBufferSize = |
| 2923 4 * MaxDecimalDigitsIn<sizeof(unsigned)>::kUnsigned // NOLINT | 2923 4 * MaxDecimalDigitsIn<sizeof(unsigned)>::kUnsigned // NOLINT |
| 2924 + 4 + 1 + 1; | 2924 + 4 + 1 + 1; |
| 2925 EmbeddedVector<char, kBufferSize> buffer; | 2925 EmbeddedVector<char, kBufferSize> buffer; |
| 2926 int buffer_pos = 0; | 2926 int buffer_pos = 0; |
| 2927 buffer_pos = utoa(node->id(), buffer, buffer_pos); | 2927 buffer_pos = utoa(node->id(), buffer, buffer_pos); |
| 2928 buffer[buffer_pos++] = ','; | 2928 buffer[buffer_pos++] = ','; |
| 2929 buffer_pos = utoa(node->function_id(), buffer, buffer_pos); | 2929 buffer_pos = utoa(node->function_info_index(), buffer, buffer_pos); |
| 2930 buffer[buffer_pos++] = ','; | 2930 buffer[buffer_pos++] = ','; |
| 2931 buffer_pos = utoa(node->allocation_count(), buffer, buffer_pos); | 2931 buffer_pos = utoa(node->allocation_count(), buffer, buffer_pos); |
| 2932 buffer[buffer_pos++] = ','; | 2932 buffer[buffer_pos++] = ','; |
| 2933 buffer_pos = utoa(node->allocation_size(), buffer, buffer_pos); | 2933 buffer_pos = utoa(node->allocation_size(), buffer, buffer_pos); |
| 2934 buffer[buffer_pos++] = ','; | 2934 buffer[buffer_pos++] = ','; |
| 2935 buffer[buffer_pos++] = '['; | 2935 buffer[buffer_pos++] = '['; |
| 2936 buffer[buffer_pos++] = '\0'; | 2936 buffer[buffer_pos++] = '\0'; |
| 2937 writer_->AddString(buffer.start()); | 2937 writer_->AddString(buffer.start()); |
| 2938 | 2938 |
| 2939 Vector<AllocationTraceNode*> children = node->children(); | 2939 Vector<AllocationTraceNode*> children = node->children(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2961 | 2961 |
| 2962 | 2962 |
| 2963 void HeapSnapshotJSONSerializer::SerializeTraceNodeInfos() { | 2963 void HeapSnapshotJSONSerializer::SerializeTraceNodeInfos() { |
| 2964 AllocationTracker* tracker = snapshot_->profiler()->allocation_tracker(); | 2964 AllocationTracker* tracker = snapshot_->profiler()->allocation_tracker(); |
| 2965 if (!tracker) return; | 2965 if (!tracker) return; |
| 2966 // The buffer needs space for 6 unsigned ints, 6 commas, \n and \0 | 2966 // The buffer needs space for 6 unsigned ints, 6 commas, \n and \0 |
| 2967 const int kBufferSize = | 2967 const int kBufferSize = |
| 2968 6 * MaxDecimalDigitsIn<sizeof(unsigned)>::kUnsigned // NOLINT | 2968 6 * MaxDecimalDigitsIn<sizeof(unsigned)>::kUnsigned // NOLINT |
| 2969 + 6 + 1 + 1; | 2969 + 6 + 1 + 1; |
| 2970 EmbeddedVector<char, kBufferSize> buffer; | 2970 EmbeddedVector<char, kBufferSize> buffer; |
| 2971 HashMap* id_to_function_info = tracker->id_to_function_info(); | 2971 const List<AllocationTracker::FunctionInfo*>& list = |
| 2972 tracker->function_info_list(); |
| 2972 bool first_entry = true; | 2973 bool first_entry = true; |
| 2973 for (HashMap::Entry* p = id_to_function_info->Start(); | 2974 for (int i = 0; i < list.length(); i++) { |
| 2974 p != NULL; | 2975 AllocationTracker::FunctionInfo* info = list[i]; |
| 2975 p = id_to_function_info->Next(p)) { | |
| 2976 SnapshotObjectId id = | |
| 2977 static_cast<SnapshotObjectId>(reinterpret_cast<intptr_t>(p->key)); | |
| 2978 AllocationTracker::FunctionInfo* info = | |
| 2979 reinterpret_cast<AllocationTracker::FunctionInfo* >(p->value); | |
| 2980 int buffer_pos = 0; | 2976 int buffer_pos = 0; |
| 2981 if (first_entry) { | 2977 if (first_entry) { |
| 2982 first_entry = false; | 2978 first_entry = false; |
| 2983 } else { | 2979 } else { |
| 2984 buffer[buffer_pos++] = ','; | 2980 buffer[buffer_pos++] = ','; |
| 2985 } | 2981 } |
| 2986 buffer_pos = utoa(id, buffer, buffer_pos); | 2982 buffer_pos = utoa(info->function_id, buffer, buffer_pos); |
| 2987 buffer[buffer_pos++] = ','; | 2983 buffer[buffer_pos++] = ','; |
| 2988 buffer_pos = utoa(GetStringId(info->name), buffer, buffer_pos); | 2984 buffer_pos = utoa(GetStringId(info->name), buffer, buffer_pos); |
| 2989 buffer[buffer_pos++] = ','; | 2985 buffer[buffer_pos++] = ','; |
| 2990 buffer_pos = utoa(GetStringId(info->script_name), buffer, buffer_pos); | 2986 buffer_pos = utoa(GetStringId(info->script_name), buffer, buffer_pos); |
| 2991 buffer[buffer_pos++] = ','; | 2987 buffer[buffer_pos++] = ','; |
| 2992 // The cast is safe because script id is a non-negative Smi. | 2988 // The cast is safe because script id is a non-negative Smi. |
| 2993 buffer_pos = utoa(static_cast<unsigned>(info->script_id), buffer, | 2989 buffer_pos = utoa(static_cast<unsigned>(info->script_id), buffer, |
| 2994 buffer_pos); | 2990 buffer_pos); |
| 2995 buffer[buffer_pos++] = ','; | 2991 buffer[buffer_pos++] = ','; |
| 2996 buffer_pos = SerializePosition(info->line, buffer, buffer_pos); | 2992 buffer_pos = SerializePosition(info->line, buffer, buffer_pos); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3065 writer_->AddString("\"<dummy>\""); | 3061 writer_->AddString("\"<dummy>\""); |
| 3066 for (int i = 1; i < sorted_strings.length(); ++i) { | 3062 for (int i = 1; i < sorted_strings.length(); ++i) { |
| 3067 writer_->AddCharacter(','); | 3063 writer_->AddCharacter(','); |
| 3068 SerializeString(sorted_strings[i]); | 3064 SerializeString(sorted_strings[i]); |
| 3069 if (writer_->aborted()) return; | 3065 if (writer_->aborted()) return; |
| 3070 } | 3066 } |
| 3071 } | 3067 } |
| 3072 | 3068 |
| 3073 | 3069 |
| 3074 } } // namespace v8::internal | 3070 } } // namespace v8::internal |
| OLD | NEW |