gc: Add blockstats
This commit is contained in:
parent
63d64b0778
commit
1866963738
3 changed files with 55 additions and 1 deletions
|
|
@ -405,6 +405,9 @@ impl_gc(apfl_ctx ctx)
|
|||
TRY_FORMAT(ctx, apfl_gc_debug_dump_graph(&ctx->gc, w));
|
||||
} else if (apfl_string_eq(sv, "collect")) {
|
||||
apfl_gc_full(&ctx->gc);
|
||||
} else if (apfl_string_eq(sv, "blockstats")) {
|
||||
struct apfl_io_writer w = apfl_get_output_writer(ctx);
|
||||
TRY_FORMAT(ctx, apfl_gc_debug_blockstats(&ctx->gc, w));
|
||||
} else {
|
||||
apfl_raise_const_error(ctx, "Unknown gc command");
|
||||
}
|
||||
|
|
@ -484,7 +487,7 @@ impl_fopen(apfl_ctx ctx)
|
|||
if (argc > 1) {
|
||||
apfl_get_list_member_by_index(ctx, 0, 1);
|
||||
} else {
|
||||
apfl_push_const_string(ctx, "rb");
|
||||
apfl_push_const_string(ctx," rb");
|
||||
}
|
||||
const char *mode = getcstring(ctx, -1);
|
||||
|
||||
|
|
|
|||
50
src/gc.c
50
src/gc.c
|
|
@ -650,6 +650,56 @@ apfl_gc_debug_dump_graph(struct gc *gc, struct apfl_io_writer w)
|
|||
return true;
|
||||
}
|
||||
|
||||
typedef size_t statuscounts[4];
|
||||
|
||||
static bool
|
||||
blockstat_line(struct apfl_io_writer w, size_t i, statuscounts counts)
|
||||
{
|
||||
FMT_TRY(apfl_format_put_int(w, (int)i));
|
||||
FMT_TRY(apfl_io_write_byte(w, '\t'));
|
||||
FMT_TRY(apfl_format_put_int(w, (int)counts[GC_STATUS_FREE]));
|
||||
FMT_TRY(apfl_io_write_byte(w, '\t'));
|
||||
FMT_TRY(apfl_format_put_int(w, (int)counts[GC_STATUS_BLACK]));
|
||||
FMT_TRY(apfl_io_write_byte(w, '\t'));
|
||||
FMT_TRY(apfl_format_put_int(w, (int)counts[GC_STATUS_GREY]));
|
||||
FMT_TRY(apfl_io_write_byte(w, '\t'));
|
||||
FMT_TRY(apfl_format_put_int(w, (int)counts[GC_STATUS_WHITE]));
|
||||
FMT_TRY(apfl_io_write_byte(w, '\n'));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
apfl_gc_debug_blockstats(struct gc *gc, struct apfl_io_writer w)
|
||||
{
|
||||
statuscounts total = {0, 0, 0, 0};
|
||||
size_t i = 0;
|
||||
|
||||
FMT_TRY(apfl_io_write_string(w, "block#\tfree\tblack\tgrey\twhite\n========================================\n"));
|
||||
|
||||
for (
|
||||
struct gc_block *cur = gc->block;
|
||||
cur != NULL;
|
||||
cur = cur->next
|
||||
) {
|
||||
statuscounts block = {0, 0, 0, 0};
|
||||
|
||||
for (size_t j = 0; j < GC_OBJECTS_PER_BLOCK; j++) {
|
||||
enum gc_status status = cur->objects[j].status;
|
||||
block[status]++;
|
||||
total[status]++;
|
||||
}
|
||||
|
||||
FMT_TRY(blockstat_line(w, i, block));
|
||||
i++;
|
||||
}
|
||||
|
||||
FMT_TRY(apfl_io_write_string(w, "========================================\n"));
|
||||
FMT_TRY(blockstat_line(w, i, total));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
apfl_gc_deinit(struct gc *gc)
|
||||
{
|
||||
|
|
|
|||
1
src/gc.h
1
src/gc.h
|
|
@ -73,6 +73,7 @@ void apfl_gc_init(struct gc *, struct apfl_allocator, gc_roots_getter, void *roo
|
|||
void apfl_gc_deinit(struct gc *);
|
||||
|
||||
bool apfl_gc_debug_dump_graph(struct gc *, struct apfl_io_writer);
|
||||
bool apfl_gc_debug_blockstats(struct gc *, struct apfl_io_writer);
|
||||
|
||||
size_t apfl_gc_tmproots_begin(struct gc *gc);
|
||||
void apfl_gc_tmproots_restore(struct gc *gc, size_t);
|
||||
|
|
|
|||
Loading…
Reference in a new issue