X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=innduct.git;a=blobdiff_plain;f=statemc.c;h=3ce00f483a6d35e6e825ec538b832a1571778120;hp=172bbe8afabf040ac91a9b114267b6b4a920e278;hb=b350fb6533f6855e54050aec6d69cfd0e27e239e;hpb=62a5c8052810dc6e5716c1e1e3bf63294a350167 diff --git a/statemc.c b/statemc.c index 172bbe8..3ce00f4 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 */ @@ -188,8 +190,12 @@ int trigger_flush_ok(const char *why) { case sm_SEPARATED: case sm_DROPPING: - warn("abandoning old feedfile after flush (%s), autodeferring", - why ? why : "took too long to complete"); + if (conns.count) + warn("abandoning old feedfile after flush (%s), autodeferring", + why ? why : "took too long to complete"); + else + info("autodeferring after flush (%s)", + why ? why : "no connections"); assert(flushing_input_file); autodefer_input_file(flushing_input_file); return 1; @@ -216,31 +222,30 @@ 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.results, [RC_##x]) +#define RCI_TRIPLE_VALS(x) , RCI_TRIPLE_VALS_BASE(counts->results, [RC_##x]) -#define CNT(art,rc) (ipf->counts.results[art_##art][RC_##rc]) +#define CNT(art,rc) (counts->results[art_##art][RC_##rc]) - 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) + char *inprog= ipf_xtra && !completed + ? xasprintf(" inprogress=%ld", ipf_xtra->inprogress) + : xasprintf("%s",""); /* GCC produces a stupid warning for printf("") ! */ + 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" + notice("%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->counts.events[read_ok], ipf->counts.events[read_blank], - ipf->counts.events[read_err], - inprog, autodefer, ipf->counts.events[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) @@ -248,7 +253,7 @@ static void notice_processed(InputFile *ipf, int completed, RESULT_COUNTS(RCI_NOTHING, RCI_TRIPLE_VALS) ); - memset(&ipf->counts, 0, sizeof(ipf->counts)); + memset(counts, 0, sizeof(*counts)); free(inprog); free(autodefer); @@ -256,17 +261,33 @@ 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); - + dbg("backlog file %p %s complete", ipf, ipf->path); + backlog_accumulate_counts(ipf); close_input_file(ipf); if (unlink(ipf->path)) { if (errno != ENOENT) @@ -287,7 +308,7 @@ void statemc_check_flushing_done(void) { assert(sms==sm_SEPARATED || sms==sm_DROPPING); - notice_processed(ipf,1,"feedfile",""); + notice_processed_inputfile(ipf,1,"batch"); close_defer(); @@ -484,11 +505,16 @@ void preterminate(void) { } void showstats(void) { - 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); + notice_conns_stats(); + 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; }