X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=statemc.c;h=dda412d067ce6993c6d3e10f718f27ba77629ed4;hb=ee2469ff17e79b9e3308b51701cb282fdd289f95;hp=b995957cdebdb4fd0529845fffea87d9dbe96c83;hpb=80a281cd6a86e33fd030a265331f59d1366541b2;p=innduct.git diff --git a/statemc.c b/statemc.c index b995957..dda412d 100644 --- a/statemc.c +++ b/statemc.c @@ -31,6 +31,8 @@ StateMachineState sms; int until_flush; InputFile *main_input_file, *flushing_input_file, *backlog_input_file; +Counts backlog_counts; +int backlog_counts_report; FILE *defer; /* initialisation to 0 is good */ @@ -216,30 +218,32 @@ static int inputfile_is_done(InputFile *ipf) { return 1; } -static void notice_processed(InputFile *ipf, int completed, - const char *what, const char *spec) { - if (!ipf) return; /* allows preterminate to be lazy */ +static void notice_processed_counts(Counts *counts, int completed, + InputFile *ipf_xtra, const char *what) { #define RCI_NOTHING(x) /* nothing */ #define RCI_TRIPLE_FMT(x) " " #x "=" RCI_TRIPLE_FMT_BASE -#define RCI_TRIPLE_VALS(x) , RCI_TRIPLE_VALS_BASE(ipf->counts, [RC_##x]) +#define RCI_TRIPLE_VALS(x) , RCI_TRIPLE_VALS_BASE(counts->results, [RC_##x]) -#define CNT(art,rc) (ipf->counts[art_##art][RC_##rc]) +#define CNT(art,rc) (counts->results[art_##art][RC_##rc]) + + assert(!completed || ipf_xtra); char *inprog= completed ? xasprintf("%s","") /* GCC produces a stupid warning for printf("") ! */ - : xasprintf(" inprogress=%ld", ipf->inprogress); - char *autodefer= ipf->autodefer >= 0 - ? xasprintf(" autodeferred=%ld", ipf->autodefer) + : xasprintf(" inprogress=%ld", ipf_xtra->inprogress); + char *autodefer= ipf_xtra && ipf_xtra->autodefer >= 0 + ? xasprintf(" autodeferred=%ld", ipf_xtra->autodefer) : xasprintf("%s",""); - info("%s %s%s read=%d (+bl=%d,+err=%d)%s%s" + info("%s %s read=%d (+bl=%d,+err=%d)%s%s" " missing=%d offered=%d (ch=%d,nc=%d) accepted=%d (ch=%d,nc=%d)" RESULT_COUNTS(RCI_NOTHING, RCI_TRIPLE_FMT) , - completed?"completed":"processed", what, spec, - ipf->readcount_ok, ipf->readcount_blank, ipf->readcount_err, - inprog, autodefer, ipf->count_nooffer_missing, + completed?"completed":"processed", what, + counts->events[read_ok], counts->events[read_blank], + counts->events[read_err], + inprog, autodefer, counts->events[nooffer_missing], CNT(Unchecked,sent) + CNT(Unsolicited,sent) , CNT(Unchecked,sent), CNT(Unsolicited,sent), CNT(Wanted,accepted) + CNT(Unsolicited,accepted) @@ -247,9 +251,7 @@ static void notice_processed(InputFile *ipf, int completed, RESULT_COUNTS(RCI_NOTHING, RCI_TRIPLE_VALS) ); - memset(ipf->counts, 0, sizeof(ipf->counts)); - ipf->readcount_ok= ipf->readcount_blank= - ipf->readcount_err= ipf->count_nooffer_missing= 0; + memset(counts, 0, sizeof(*counts)); free(inprog); free(autodefer); @@ -257,17 +259,32 @@ static void notice_processed(InputFile *ipf, int completed, #undef CNT } +static void notice_processed_inputfile(InputFile *ipf, int completed, + const char *what) { + if (!ipf) return; /* allows showstats to be lazy */ + notice_processed_counts(&ipf->counts, completed, ipf, what); +} + +static void backlog_accumulate_counts(InputFile *ipf) { + int i,j; + if (!ipf) return; + + for (i=0; icounts.results[i][j]; + + for (i=0; icounts.events[i]; + + memset(&ipf->counts, 0, sizeof(ipf->counts)); + backlog_counts_report= 1; +} + void statemc_check_backlog_done(void) { InputFile *ipf= backlog_input_file; if (!inputfile_is_done(ipf)) return; - const char *slash= strrchr(ipf->path, '/'); - const char *leaf= slash ? slash+1 : ipf->path; - const char *under= strchr(slash, '_'); - const char *rest= under ? under+1 : leaf; - if (!strncmp(rest,"backlog",7)) rest += 7; - notice_processed(ipf,1,"backlog ",rest); - + backlog_accumulate_counts(ipf); close_input_file(ipf); if (unlink(ipf->path)) { if (errno != ENOENT) @@ -288,7 +305,7 @@ void statemc_check_flushing_done(void) { assert(sms==sm_SEPARATED || sms==sm_DROPPING); - notice_processed(ipf,1,"feedfile",""); + notice_processed_inputfile(ipf,1,"feedfile"); close_defer(); @@ -481,11 +498,20 @@ void spawn_inndcomm_flush(const char *why) { /* Moved => Flushing */ void preterminate(void) { if (in_child) return; - notice_processed(main_input_file,0,"feedfile",""); - notice_processed(flushing_input_file,0,"flushing",""); - if (backlog_input_file) - notice_processed(backlog_input_file,0, "backlog file ", - backlog_input_file->path); + showstats(); +} + +void showstats(void) { + notice_processed_inputfile(main_input_file, 0, "feedfile"); + notice_processed_inputfile(flushing_input_file, 0, "flushing"); + + backlog_accumulate_counts(backlog_input_file); + if (backlog_counts_report) { + notice_processed_counts(&backlog_counts, 0, + backlog_input_file, "backlogs"); + backlog_counts_report= 0; + } + until_stats_log= stats_log_periods; } static int signal_self_pipe[2];