[no ci] fix

This commit is contained in:
张皓晟 2025-11-23 16:17:41 +08:00
parent 061206f13e
commit d11967293f
2 changed files with 27 additions and 15 deletions

View File

@ -41,7 +41,7 @@ static void ManagedHeap__fire_debug_callback(ManagedHeap* self, ManagedHeapSwpet
c11_sbuf__ctor(&buf); c11_sbuf__ctor(&buf);
const clock_t CLOCKS_PER_MS = CLOCKS_PER_SEC / 1000; const clock_t CLOCKS_PER_MS = CLOCKS_PER_SEC / 1000;
const char* DIVIDER = "------------------------------"; const char* DIVIDER = "------------------------------------------------------------\n";
clock_t start = out_info->start / CLOCKS_PER_MS; clock_t start = out_info->start / CLOCKS_PER_MS;
clock_t mark_ms = (out_info->mark_end - out_info->start) / CLOCKS_PER_MS; clock_t mark_ms = (out_info->mark_end - out_info->start) / CLOCKS_PER_MS;
@ -58,21 +58,24 @@ static void ManagedHeap__fire_debug_callback(ManagedHeap* self, ManagedHeapSwpet
pk_sprintf(&buf, "large_freed: %d\n", out_info->large_freed); pk_sprintf(&buf, "large_freed: %d\n", out_info->large_freed);
c11_sbuf__write_cstr(&buf, DIVIDER); c11_sbuf__write_cstr(&buf, DIVIDER);
char line_buf[256]; if(out_info->small_freed != 0 || out_info->large_freed != 0) {
for(int i = 0; i < out_info->types_length; i++) { char line_buf[256];
const char* type_name = py_tpname(i); for(int i = 0; i < out_info->types_length; i++) {
int s_freed = out_info->small_types[i]; const char* type_name = py_tpname(i);
int l_freed = out_info->large_types[i]; int s_freed = out_info->small_types[i];
if(s_freed == 0 && l_freed == 0) continue; int l_freed = out_info->large_types[i];
snprintf(line_buf, if(s_freed == 0 && l_freed == 0) continue;
sizeof(line_buf), snprintf(line_buf,
"[%-24s] small: %6d large: %6d\n", sizeof(line_buf),
type_name, "[%-24s] small: %6d large: %6d\n",
s_freed, type_name,
l_freed); s_freed,
c11_sbuf__write_cstr(&buf, line_buf); l_freed);
c11_sbuf__write_cstr(&buf, line_buf);
}
c11_sbuf__write_cstr(&buf, DIVIDER);
} }
c11_sbuf__write_cstr(&buf, DIVIDER);
pk_sprintf(&buf, "auto_thres.before: %d\n", out_info->auto_thres.before); pk_sprintf(&buf, "auto_thres.before: %d\n", out_info->auto_thres.before);
pk_sprintf(&buf, "auto_thres.after: %d\n", out_info->auto_thres.after); pk_sprintf(&buf, "auto_thres.after: %d\n", out_info->auto_thres.after);
pk_sprintf(&buf, "auto_thres.upper: %d\n", out_info->auto_thres.upper); pk_sprintf(&buf, "auto_thres.upper: %d\n", out_info->auto_thres.upper);
@ -141,6 +144,11 @@ int ManagedHeap__collect(ManagedHeap* self) {
int freed = ManagedHeap__sweep(self, out_info); int freed = ManagedHeap__sweep(self, out_info);
if(out_info) out_info->swpet_end = clock(); if(out_info) out_info->swpet_end = clock();
if(out_info) {
out_info->auto_thres.before = self->gc_threshold;
out_info->auto_thres.after = self->gc_threshold;
}
if(self->debug_callback) { if(self->debug_callback) {
ManagedHeap__fire_debug_callback(self, out_info); ManagedHeap__fire_debug_callback(self, out_info);
ManagedHeapSwpetInfo__delete(out_info); ManagedHeapSwpetInfo__delete(out_info);

View File

@ -1,5 +1,9 @@
import gc import gc
from pkpy import setup_gc_debug_callback
setup_gc_debug_callback(print)
gc.collect()
def create_garbage(): def create_garbage():
a = [(1,2) for i in range(10000)] a = [(1,2) for i in range(10000)]
return a return a