Skip to content

Commit

Permalink
print types more verbosely in page profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
d-netto committed Feb 9, 2024
1 parent e507785 commit 92f8ffe
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/gc-page-profiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void gc_page_profile_write_to_file(gc_page_profiler_serializer_t *serializer)
gc_page_profile_write_comma(serializer);
gc_page_profile_write_preamble(serializer);
char str[GC_TYPE_STR_MAXLEN];
memset(str, 0, GC_TYPE_STR_MAXLEN);
for (size_t i = 0; i < serializer->typestrs.len; i++) {
const char *name = (const char *)serializer->typestrs.items[i];
if (name == GC_SERIALIZER_EMPTY) {
Expand All @@ -128,6 +129,13 @@ void gc_page_profile_write_to_file(gc_page_profiler_serializer_t *serializer)
gc_page_profile_write_epilogue(serializer);
page_profile_pages_written++;
uv_mutex_unlock(&page_profile_lock);
// clean up
for (size_t i = 0; i < serializer->typestrs.len; i++) {
const char *name = (const char *)serializer->typestrs.items[i];
if (name != GC_SERIALIZER_EMPTY && name != GC_SERIALIZER_GARBAGE) {
free((void *)name);
}
}
}
}

Expand Down
50 changes: 48 additions & 2 deletions src/gc-page-profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
extern "C" {
#endif

#define GC_TYPE_STR_MAXLEN (512)
#define GC_TYPE_STR_MAXLEN (4096)

typedef struct {
arraylist_t typestrs;
Expand Down Expand Up @@ -47,8 +47,54 @@ STATIC_INLINE void gc_page_profile_write_live_obj(gc_page_profiler_serializer_t
int enabled) JL_NOTSAFEPOINT
{
if (__unlikely(enabled)) {
const char *name = jl_typeof_str(jl_valueof(v));
jl_value_t *a = jl_valueof(v);
jl_value_t *t = jl_typeof(a);
ios_t str_;
int ios_need_close = 0;
char *name = (char *)calloc_s(GC_TYPE_STR_MAXLEN);
if (t == (jl_value_t*)jl_get_buff_tag()) {
strcpy(name, "Buffer");
}
else if (jl_is_string(a)) {
strcpy(name, jl_string_data(a));
}
else if (jl_is_symbol(a)) {
strcpy(name, jl_symbol_name((jl_sym_t*)a));
}
else if (jl_is_simplevector(a)) {
strcpy(name, "SimpleVector");
}
else if (jl_is_module(a)) {
strcpy(name, jl_symbol_name_(((jl_module_t*)a)->name));
}
else if (jl_is_task(a)) {
strcpy(name, "Task");
}
else if (jl_is_datatype(a)) {
ios_need_close = 1;
ios_mem(&str_, 0);
JL_STREAM* str = (JL_STREAM*)&str_;
jl_static_show(str, a);
memcpy(name, str_.buf, str_.size);
}
else if (jl_is_array(a)){
ios_need_close = 1;
ios_mem(&str_, 0);
JL_STREAM* str = (JL_STREAM*)&str_;
jl_static_show(str, t);
memcpy(name, str_.buf, str_.size);
}
else {
ios_need_close = 1;
ios_mem(&str_, 0);
JL_STREAM* str = (JL_STREAM*)&str_;
jl_static_show(str, t);
memcpy(name, str_.buf, str_.size);
}
gc_page_serializer_write(serializer, name);
if (ios_need_close) {
ios_close(&str_);
}
}
}
void gc_enable_page_profile(void) JL_NOTSAFEPOINT;
Expand Down
2 changes: 1 addition & 1 deletion src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ jl_ptls_t* gc_all_tls_states;
gc_heapstatus_t gc_heap_stats = {0};
int next_sweep_full = 0;
const uint64_t _jl_buff_tag[3] = {0x4eadc0004eadc000ull, 0x4eadc0004eadc000ull, 0x4eadc0004eadc000ull}; // aka 0xHEADER00
JL_DLLEXPORT uintptr_t jl_get_buff_tag(void)
JL_DLLEXPORT uintptr_t jl_get_buff_tag(void) JL_NOTSAFEPOINT
{
return jl_buff_tag;
}
Expand Down
2 changes: 1 addition & 1 deletion src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ JL_DLLEXPORT jl_value_t *jl_gc_alloc(jl_ptls_t ptls, size_t sz, void *ty);
// defined as uint64_t[3] so that we can get the right alignment of this and a "type tag" on it
const extern uint64_t _jl_buff_tag[3];
#define jl_buff_tag ((uintptr_t)LLT_ALIGN((uintptr_t)&_jl_buff_tag[1],16))
JL_DLLEXPORT uintptr_t jl_get_buff_tag(void);
JL_DLLEXPORT uintptr_t jl_get_buff_tag(void) JL_NOTSAFEPOINT;

typedef void jl_gc_tracked_buffer_t; // For the benefit of the static analyzer
STATIC_INLINE jl_gc_tracked_buffer_t *jl_gc_alloc_buf(jl_ptls_t ptls, size_t sz)
Expand Down

0 comments on commit 92f8ffe

Please sign in to comment.