mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-01-15 01:29:11 +08:00
nicer json output
This commit is contained in:
parent
07c0ed12a9
commit
3130d55796
15
src/heap.c
15
src/heap.c
@ -587,21 +587,19 @@ static bool mi_heap_print_json_visit(const mi_heap_t* heap, const mi_heap_area_t
|
||||
varg->area_count++;
|
||||
varg->block_count = 0;
|
||||
_mi_fprintf(varg->out, varg->out_arg,
|
||||
"\"page\": %zu, \"start\": 0x%p, \"block_size\": %zu, \"used_size\": %zu,\n \"reserved\": %zu, \"committed\": %zu,",
|
||||
"\"page\": %zu, \"start\": 0x%p, \"block_size\": %zu, \"used_size\": %zu,\n \"reserved\": %zu, \"committed\": %zu, \"blocks\": [\n",
|
||||
varg->area_count, area->blocks, area->block_size, area->used, area->reserved, area->committed);
|
||||
_mi_fprintf(varg->out, varg->out_arg, " \"blocks\": [\n");
|
||||
}
|
||||
else {
|
||||
_mi_fprintf(varg->out, varg->out_arg, varg->block_count==0 ? " {" : " ,{");
|
||||
varg->block_count++;
|
||||
_mi_fprintf(varg->out, varg->out_arg,
|
||||
"\"block\": 0x%p, \"valid\": %s, \"size\": %zu, \"usable_size\": %zu, \"allocated_size\": %zu,\n ",
|
||||
info->block, info->valid ? "true" : "false", info->size, info->usable_size, info->allocated_size);
|
||||
"%s\"block\": 0x%p, \"valid\": %s, \"size\": %zu, \"usable_size\": %zu, \"allocated_size\": %zu,\n ",
|
||||
(varg->block_count==0 ? " {" : " ,{"), info->block, info->valid ? "true" : "false", info->size, info->usable_size, info->allocated_size);
|
||||
varg->block_count++;
|
||||
int lineno;
|
||||
const char* fname;
|
||||
void* ret = mi_source_unpack(info->source, &fname, &lineno);
|
||||
if (fname!=NULL) _mi_fprintf(varg->out, varg->out_arg, "\"source\": \"%s:%i\" }\n", fname, lineno);
|
||||
else if (ret != NULL) _mi_fprintf(varg->out, varg->out_arg, "\"source\": \"(%p)\" }\n", ret);
|
||||
else if (ret != NULL) _mi_fprintf(varg->out, varg->out_arg, "\"source\": \"0x%p\" }\n", ret);
|
||||
else _mi_fprintf(varg->out, varg->out_arg, "\"source\": \"\" }\n");
|
||||
}
|
||||
return true;
|
||||
@ -610,8 +608,7 @@ static bool mi_heap_print_json_visit(const mi_heap_t* heap, const mi_heap_area_t
|
||||
void mi_heap_print_json(mi_heap_t* heap, mi_output_fun* out, void* arg) {
|
||||
if (heap==NULL) heap = mi_heap_get_default();
|
||||
mi_print_json_t info = { 0, 0, out, arg };
|
||||
_mi_fprintf(info.out, info.out_arg, "{ \"heap\": 0x%p, \"thread_id\": 0x%zx, \"page_count\": %zu, \"block_padding\": %zu", heap, heap->thread_id, heap->page_count, mi_extra_padding(heap) );
|
||||
_mi_fprintf(info.out, info.out_arg, ", \"pages\": [\n");
|
||||
_mi_fprintf(info.out, info.out_arg, "{ \"heap\": 0x%p, \"thread_id\": 0x%zx, \"page_count\": %zu, \"block_padding\": %zu, \"pages\": [\n", heap, heap->thread_id, heap->page_count, mi_extra_padding(heap) );
|
||||
mi_heap_visit_blocks(heap, true, &mi_heap_print_json_visit, &info);
|
||||
_mi_fprintf(info.out, info.out_arg, info.area_count==0 ? "]\n" : " ] }\n] }\n");
|
||||
}
|
||||
|
@ -24,9 +24,10 @@ int main() {
|
||||
// block_overflow1();
|
||||
// block_overflow2();
|
||||
// dangling_ptr_write();
|
||||
void* (*fun_mimalloc)(size_t) = &mi_malloc;
|
||||
|
||||
void* p1 = malloc(78);
|
||||
void* p2 = malloc(24);
|
||||
void* p2 = fun_mimalloc(24);
|
||||
free(p1);
|
||||
p1 = mi_malloc(8);
|
||||
//char* s = strdup("hello\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user