Skip to content

Commit 68d4c0e

Browse files
add empty/dummy fields expected by vscode
1 parent 4a2c593 commit 68d4c0e

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

src/gc-heap-snapshot.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,9 @@ void _record_gc_just_edge(const char *edge_type, size_t from_idx, size_t to_idx,
606606
void final_serialize_heap_snapshot(ios_t *json, ios_t *strings, HeapSnapshot &snapshot, char all_one)
607607
{
608608
// mimicking https://github.com/nodejs/node/blob/5fd7a72e1c4fbaf37d3723c4c81dce35c149dc84/deps/v8/src/profiler/heap-snapshot-generator.cc#L2567-L2567
609+
// also https://github.com/microsoft/vscode-v8-heap-tools/blob/c5b34396392397925ecbb4ecb904a27a2754f2c1/v8-heap-parser/src/decoder.rs#L43-L51
609610
ios_printf(json, "{\"snapshot\":{");
611+
610612
ios_printf(json, "\"meta\":{");
611613
ios_printf(json, "\"node_fields\":[\"type\",\"name\",\"id\",\"self_size\",\"edge_count\",\"trace_node_id\",\"detachedness\"],");
612614
ios_printf(json, "\"node_types\":[");
@@ -617,10 +619,25 @@ void final_serialize_heap_snapshot(ios_t *json, ios_t *strings, HeapSnapshot &sn
617619
ios_printf(json, "\"edge_types\":[");
618620
snapshot.edge_types.print_json_array(json, false);
619621
ios_printf(json, ",");
620-
ios_printf(json, "\"string_or_number\",\"from_node\"]");
622+
ios_printf(json, "\"string_or_number\",\"from_node\"],");
623+
// not used. Required by microsoft/vscode-v8-heap-tools
624+
ios_printf(json, "\"trace_function_info_fields\":[\"function_id\",\"name\",\"script_name\",\"script_id\",\"line\",\"column\"],");
625+
ios_printf(json, "\"trace_node_fields\":[\"id\",\"function_info_index\",\"count\",\"size\",\"children\"],");
626+
ios_printf(json, "\"sample_fields\":[\"timestamp_us\",\"last_assigned_id\"],");
627+
ios_printf(json, "\"location_fields\":[\"object_index\",\"script_id\",\"line\",\"column\"]");
628+
// end not used
621629
ios_printf(json, "},\n"); // end "meta"
630+
622631
ios_printf(json, "\"node_count\":%zu,", snapshot.num_nodes);
623-
ios_printf(json, "\"edge_count\":%zu", snapshot.num_edges);
624-
ios_printf(json, "}\n"); // end "snapshot"
632+
ios_printf(json, "\"edge_count\":%zu,", snapshot.num_edges);
633+
ios_printf(json, "\"trace_function_count\":0"); // not used. Required by microsoft/vscode-v8-heap-tools
634+
ios_printf(json, "},\n"); // end "snapshot"
635+
636+
// not used. Required by microsoft/vscode-v8-heap-tools
637+
ios_printf(json, "\"trace_tree\":[],");
638+
ios_printf(json, "\"samples\":[],");
639+
ios_printf(json, "\"locations\":[]");
640+
// end not used
641+
625642
ios_printf(json, "}");
626643
}

stdlib/Profile/src/heapsnapshot_reassemble.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function assemble_snapshot(in_prefix, io::IO)
9292
node_count = parse(Int, String(@view preamble[pos:endpos]))
9393

9494
pos = last(findnext("edge_count\":", preamble, endpos)) + 1
95-
endpos = findnext(==('}'), preamble, pos) - 1
95+
endpos = findnext(==(','), preamble, pos) - 1
9696
edge_count = parse(Int, String(@view preamble[pos:endpos]))
9797

9898
nodes = Nodes(node_count, edge_count)
@@ -137,7 +137,8 @@ function assemble_snapshot(in_prefix, io::IO)
137137
end
138138

139139
_digits_buf = zeros(UInt8, ndigits(typemax(UInt)))
140-
println(io, @view(preamble[1:end-2]), ",") # remove trailing "}\n", we don't end the snapshot here
140+
println(io, @view(preamble[1:end-1]), ",") # remove trailing "}" to reopen the object
141+
141142
println(io, "\"nodes\":[")
142143
for i in 1:length(nodes)
143144
i > 1 && println(io, ",")

0 commit comments

Comments
 (0)