Skip to content

Commit 27ebaa7

Browse files
authored
Print the detailed type on heap snapshot (#47503)
Fixes #47502
1 parent 3200219 commit 27ebaa7

File tree

2 files changed

+29
-21
lines changed

2 files changed

+29
-21
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
.DS_Store
3434
.idea/*
3535
.vscode/*
36-
36+
*.heapsnapshot
3737
# Buildkite: Ignore the entire .buildkite directory
3838
/.buildkite
3939

src/gc-heap-snapshot.cpp

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ HeapSnapshot *g_snapshot = nullptr;
124124
extern jl_mutex_t heapsnapshot_lock;
125125

126126
void serialize_heap_snapshot(ios_t *stream, HeapSnapshot &snapshot, char all_one);
127-
static inline void _record_gc_edge(const char *node_type, const char *edge_type,
127+
static inline void _record_gc_edge(const char *edge_type,
128128
jl_value_t *a, jl_value_t *b, size_t name_or_index) JL_NOTSAFEPOINT;
129129
void _record_gc_just_edge(const char *edge_type, Node &from_node, size_t to_idx, size_t name_or_idx) JL_NOTSAFEPOINT;
130130
void _add_internal_root(HeapSnapshot *snapshot);
@@ -185,45 +185,56 @@ size_t record_node_to_gc_snapshot(jl_value_t *a) JL_NOTSAFEPOINT
185185

186186
// Insert a new Node
187187
size_t self_size = 0;
188-
std::string type_name;
189188
StringRef name = "<missing>";
190189
StringRef node_type = "object";
191190

192191
jl_datatype_t *type = (jl_datatype_t*)jl_typeof(a);
193192

194193
if (jl_is_string(a)) {
195-
node_type = "string";
194+
node_type = "String";
196195
name = jl_string_data(a);
197196
self_size = jl_string_len(a);
198197
}
199198
else if (jl_is_symbol(a)) {
200-
node_type = "symbol";
199+
node_type = "jl_sym_t";
201200
name = jl_symbol_name((jl_sym_t*)a);
202201
self_size = name.size();
203202
}
204203
else if (jl_is_simplevector(a)) {
205-
node_type = "array";
204+
node_type = "jl_svec_t";
206205
name = "SimpleVector";
207206
self_size = sizeof(jl_svec_t) + sizeof(void*) * jl_svec_len(a);
208207
}
209208
else if (jl_is_module(a)) {
209+
node_type = "jl_module_t";
210210
name = jl_symbol_name_(((_jl_module_t*)a)->name);
211211
self_size = sizeof(jl_module_t);
212212
}
213213
else if (jl_is_task(a)) {
214+
node_type = "jl_task_t";
214215
name = "Task";
215216
self_size = sizeof(jl_task_t);
216217
}
217218
else if (jl_is_datatype(a)) {
218-
type_name = string("Type{") + string(jl_symbol_name_(((_jl_datatype_t*)a)->name->name)) + string("}");
219-
name = StringRef(type_name);
220-
self_size = sizeof(jl_task_t);
219+
ios_need_close = 1;
220+
ios_mem(&str_, 0);
221+
JL_STREAM* str = (JL_STREAM*)&str_;
222+
jl_static_show(str, a);
223+
name = StringRef((const char*)str_.buf, str_.size);
224+
node_type = "jl_datatype_t";
225+
self_size = sizeof(jl_datatype_t);
226+
}
227+
else if (jl_is_array(a)){
228+
ios_need_close = 1;
229+
ios_mem(&str_, 0);
230+
JL_STREAM* str = (JL_STREAM*)&str_;
231+
jl_static_show(str, (jl_value_t*)type);
232+
name = StringRef((const char*)str_.buf, str_.size);
233+
node_type = "jl_array_t";
234+
self_size = sizeof(jl_array_t);
221235
}
222236
else {
223-
self_size = jl_is_array_type(type)
224-
? sizeof(jl_array_t)
225-
: (size_t)jl_datatype_size(type);
226-
237+
self_size = (size_t)jl_datatype_size(type);
227238
// print full type into ios buffer and get StringRef to it.
228239
// The ios is cleaned up below.
229240
ios_need_close = 1;
@@ -371,13 +382,13 @@ void _gc_heap_snapshot_record_frame_to_frame_edge(jl_gcframe_t *from, jl_gcframe
371382

372383
void _gc_heap_snapshot_record_array_edge(jl_value_t *from, jl_value_t *to, size_t index) JL_NOTSAFEPOINT
373384
{
374-
_record_gc_edge("array", "element", from, to, index);
385+
_record_gc_edge("element", from, to, index);
375386
}
376387

377388
void _gc_heap_snapshot_record_object_edge(jl_value_t *from, jl_value_t *to, void *slot) JL_NOTSAFEPOINT
378389
{
379390
string path = _fieldpath_for_slot(from, slot);
380-
_record_gc_edge("object", "property", from, to,
391+
_record_gc_edge("property", from, to,
381392
g_snapshot->names.find_or_create_string_id(path));
382393
}
383394

@@ -395,7 +406,6 @@ void _gc_heap_snapshot_record_module_to_binding(jl_module_t* module, jl_binding_
395406

396407
auto &from_node = g_snapshot->nodes[from_node_idx];
397408
auto &to_node = g_snapshot->nodes[to_node_idx];
398-
from_node.type = g_snapshot->node_types.find_or_create_string_id("object");
399409

400410
_record_gc_just_edge("property", from_node, to_node_idx, g_snapshot->names.find_or_create_string_id("<native>"));
401411
if (value_idx) _record_gc_just_edge("internal", to_node, value_idx, g_snapshot->names.find_or_create_string_id("value"));
@@ -405,7 +415,7 @@ void _gc_heap_snapshot_record_module_to_binding(jl_module_t* module, jl_binding_
405415

406416
void _gc_heap_snapshot_record_internal_array_edge(jl_value_t *from, jl_value_t *to) JL_NOTSAFEPOINT
407417
{
408-
_record_gc_edge("object", "internal", from, to,
418+
_record_gc_edge("internal", from, to,
409419
g_snapshot->names.find_or_create_string_id("<internal>"));
410420
}
411421

@@ -432,19 +442,17 @@ void _gc_heap_snapshot_record_hidden_edge(jl_value_t *from, void* to, size_t byt
432442
}
433443
auto to_node_idx = record_pointer_to_gc_snapshot(to, bytes, alloc_kind);
434444
auto &from_node = g_snapshot->nodes[from_node_idx];
435-
from_node.type = g_snapshot->node_types.find_or_create_string_id("native");
436445

437446
_record_gc_just_edge("hidden", from_node, to_node_idx, name_or_idx);
438447
}
439448

440-
static inline void _record_gc_edge(const char *node_type, const char *edge_type,
441-
jl_value_t *a, jl_value_t *b, size_t name_or_idx) JL_NOTSAFEPOINT
449+
static inline void _record_gc_edge(const char *edge_type, jl_value_t *a,
450+
jl_value_t *b, size_t name_or_idx) JL_NOTSAFEPOINT
442451
{
443452
auto from_node_idx = record_node_to_gc_snapshot(a);
444453
auto to_node_idx = record_node_to_gc_snapshot(b);
445454

446455
auto &from_node = g_snapshot->nodes[from_node_idx];
447-
from_node.type = g_snapshot->node_types.find_or_create_string_id(node_type);
448456

449457
_record_gc_just_edge(edge_type, from_node, to_node_idx, name_or_idx);
450458
}

0 commit comments

Comments
 (0)