Skip to content

Commit 32b9e1a

Browse files
Profile: fix order of fields in heapsnapshot & improve formatting (#55890)
1 parent a5178a7 commit 32b9e1a

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

src/gc-heap-snapshot.cpp

+18-24
Original file line numberDiff line numberDiff line change
@@ -618,38 +618,32 @@ void final_serialize_heap_snapshot(ios_t *json, ios_t *strings, HeapSnapshot &sn
618618
{
619619
// mimicking https://github.com/nodejs/node/blob/5fd7a72e1c4fbaf37d3723c4c81dce35c149dc84/deps/v8/src/profiler/heap-snapshot-generator.cc#L2567-L2567
620620
// also https://github.com/microsoft/vscode-v8-heap-tools/blob/c5b34396392397925ecbb4ecb904a27a2754f2c1/v8-heap-parser/src/decoder.rs#L43-L51
621-
ios_printf(json, "{\"snapshot\":{");
621+
ios_printf(json, "{\"snapshot\":{\n");
622622

623-
ios_printf(json, "\"meta\":{");
624-
ios_printf(json, "\"node_fields\":[\"type\",\"name\",\"id\",\"self_size\",\"edge_count\",\"trace_node_id\",\"detachedness\"],");
625-
ios_printf(json, "\"node_types\":[");
623+
ios_printf(json, " \"meta\":{\n");
624+
ios_printf(json, " \"node_fields\":[\"type\",\"name\",\"id\",\"self_size\",\"edge_count\",\"trace_node_id\",\"detachedness\"],\n");
625+
ios_printf(json, " \"node_types\":[");
626626
snapshot.node_types.print_json_array(json, false);
627627
ios_printf(json, ",");
628-
ios_printf(json, "\"string\", \"number\", \"number\", \"number\", \"number\", \"number\"],");
629-
ios_printf(json, "\"edge_fields\":[\"type\",\"name_or_index\",\"to_node\"],");
630-
ios_printf(json, "\"edge_types\":[");
628+
ios_printf(json, "\"string\", \"number\", \"number\", \"number\", \"number\", \"number\"],\n");
629+
ios_printf(json, " \"edge_fields\":[\"type\",\"name_or_index\",\"to_node\"],\n");
630+
ios_printf(json, " \"edge_types\":[");
631631
snapshot.edge_types.print_json_array(json, false);
632632
ios_printf(json, ",");
633-
ios_printf(json, "\"string_or_number\",\"from_node\"],");
633+
ios_printf(json, "\"string_or_number\",\"from_node\"],\n");
634634
// not used. Required by microsoft/vscode-v8-heap-tools
635-
ios_printf(json, "\"trace_function_info_fields\":[\"function_id\",\"name\",\"script_name\",\"script_id\",\"line\",\"column\"],");
636-
ios_printf(json, "\"trace_node_fields\":[\"id\",\"function_info_index\",\"count\",\"size\",\"children\"],");
637-
ios_printf(json, "\"sample_fields\":[\"timestamp_us\",\"last_assigned_id\"],");
638-
ios_printf(json, "\"location_fields\":[\"object_index\",\"script_id\",\"line\",\"column\"]");
635+
ios_printf(json, " \"trace_function_info_fields\":[\"function_id\",\"name\",\"script_name\",\"script_id\",\"line\",\"column\"],\n");
636+
ios_printf(json, " \"trace_node_fields\":[\"id\",\"function_info_index\",\"count\",\"size\",\"children\"],\n");
637+
ios_printf(json, " \"sample_fields\":[\"timestamp_us\",\"last_assigned_id\"],\n");
638+
ios_printf(json, " \"location_fields\":[\"object_index\",\"script_id\",\"line\",\"column\"]\n");
639639
// end not used
640-
ios_printf(json, "},\n"); // end "meta"
640+
ios_printf(json, " },\n"); // end "meta"
641641

642-
ios_printf(json, "\"node_count\":%zu,", snapshot.num_nodes);
643-
ios_printf(json, "\"edge_count\":%zu,", snapshot.num_edges);
644-
ios_printf(json, "\"trace_function_count\":0"); // not used. Required by microsoft/vscode-v8-heap-tools
645-
ios_printf(json, "},\n"); // end "snapshot"
646-
647-
// not used. Required by microsoft/vscode-v8-heap-tools
648-
ios_printf(json, "\"trace_function_infos\":[],");
649-
ios_printf(json, "\"trace_tree\":[],");
650-
ios_printf(json, "\"samples\":[],");
651-
ios_printf(json, "\"locations\":[]");
652-
// end not used
642+
ios_printf(json, " \"node_count\":%zu,\n", snapshot.num_nodes);
643+
ios_printf(json, " \"edge_count\":%zu,\n", snapshot.num_edges);
644+
ios_printf(json, " \"trace_function_count\":0\n"); // not used. Required by microsoft/vscode-v8-heap-tools
645+
ios_printf(json, "}\n"); // end "snapshot"
653646

647+
// this } is removed by the julia reassembler in Profile
654648
ios_printf(json, "}");
655649
}

stdlib/Profile/src/heapsnapshot_reassemble.jl

+9-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ function assemble_snapshot(in_prefix, io::IO)
155155
_write_decimal_number(io, nodes.edge_count[i], _digits_buf)
156156
print(io, ",0,0")
157157
end
158-
print(io, "],\"edges\":[")
158+
print(io, "],\n")
159+
print(io, "\"edges\":[")
159160
e = 1
160161
for n in 1:length(nodes)
161162
count = nodes.edge_count[n]
@@ -177,6 +178,13 @@ function assemble_snapshot(in_prefix, io::IO)
177178
end
178179
println(io, "],")
179180

181+
# not used. Required by microsoft/vscode-v8-heap-tools
182+
# This order of these fields is required by chrome dev tools otherwise loading fails
183+
println(io, "\"trace_function_infos\":[],")
184+
println(io, "\"trace_tree\":[],")
185+
println(io, "\"samples\":[],")
186+
println(io, "\"locations\":[],")
187+
180188
println(io, "\"strings\":[")
181189
open(string(in_prefix, ".strings"), "r") do strings_io
182190
first = true

0 commit comments

Comments
 (0)