amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
One user-space repair task per eligible HWE debug-diag / compile-deploy base
ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content
filter. Each ships a public spec with a check-to-basis table, at least two
defects with single-fix fixtures, a symptom-masking fixture and an alternative
correct implementation. Claude re-checked all 320: structure, the HWE quality
items and trace6 Docker calibration receipts against current digests
(320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120
ad-hoc family names; the next batch maps them to the canonical list.
The batch's 1,256-line progress log stays in its factory report and the
36-local branch batch15-hwe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 01:55:56 +08:00

78 lines
2.6 KiB
C

#include "stats.h"
#include <limits.h>
#include <string.h>
void stats_init(Stats *stats)
{
memset(stats, 0, sizeof(*stats));
}
int stats_add(Stats *stats, const Observation *out)
{
if (stats == NULL || out == NULL) return -1;
if (stats->jobs == UINT_MAX) return -1;
if (stats->total_reads > ULONG_MAX - out->reads) return -1;
if (stats->total_checkpoints > ULONG_MAX - out->checkpoints) return -1;
if (out->outcome > 1) return -1;
stats->jobs += 1;
if (out->outcome) stats->ready += 1;
else stats->exhausted += 1;
if (out->reads == 0 || out->reads > 256) return -1;
if (stats->read_histogram[out->reads] == UINT_MAX) return -1;
stats->read_histogram[out->reads] += 1;
stats->total_reads += out->reads;
stats->total_checkpoints += out->checkpoints;
if (out->reads > stats->max_reads) {
stats->max_reads = out->reads;
stats->max_reads_id = out->id;
}
return 0;
}
unsigned stats_percentile(const Stats *stats, unsigned numerator)
{
unsigned target;
if (stats == NULL || stats->jobs == 0 || numerator < 1 || numerator > 100) return 0;
target = (stats->jobs * numerator + 99) / 100;
unsigned cumulative = 0;
unsigned reads;
for (reads = 1; reads <= 256; ++reads) {
cumulative += stats->read_histogram[reads];
if (cumulative >= target) return reads;
}
return 0;
}
static int histogram_valid(const Stats *stats)
{
unsigned jobs = 0;
unsigned long reads = 0;
unsigned at;
for (at = 1; at <= 256; ++at) {
jobs += stats->read_histogram[at];
reads += (unsigned long)at * stats->read_histogram[at];
}
if (jobs != stats->jobs) return 0;
if (reads != stats->total_reads) return 0;
return 1;
}
int stats_write(FILE *stream, const Stats *stats)
{
if (stats == NULL || stream == NULL) return -1;
if (stats->jobs == 0) return -1;
if (!histogram_valid(stats)) return -1;
if (stats->ready > stats->jobs) return -1;
if (stats->exhausted > stats->jobs) return -1;
if (stats->ready + stats->exhausted != stats->jobs) return -1;
if (stats->total_reads < stats->jobs) return -1;
if (stats->total_checkpoints + stats->jobs != stats->total_reads) return -1;
if (stats->max_reads == 0 || stats->max_reads > stats->total_reads) return -1;
if (fprintf(stream, "SUMMARY %u %u %u %lu %lu %u %u %u %u\n",
stats->jobs, stats->ready, stats->exhausted,
stats->total_reads, stats->total_checkpoints,
stats->max_reads, stats->max_reads_id,
stats_percentile(stats, 50), stats_percentile(stats, 90)) < 0) return -1;
return 0;
}