chiark / gitweb /
Accumulate backlog counts rather than reporting every file
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 29 May 2010 13:34:08 +0000 (14:34 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Sat, 29 May 2010 13:34:08 +0000 (14:34 +0100)
innduct.h
statemc.c

index d6dc8dd033c6516b26cfdc68785cb3efac50aabc..fc04d8a6688d93ba10c65d352e5ccc57f54077ff 100644 (file)
--- a/innduct.h
+++ b/innduct.h
@@ -497,6 +497,8 @@ extern int until_stats_log;
 extern StateMachineState sms;
 extern int until_flush;
 extern InputFile *main_input_file, *flushing_input_file, *backlog_input_file;
+extern Counts backlog_counts;
+extern int backlog_counts_report;
 extern FILE *defer;
 extern int until_connect, until_backlog_nextscan;
 extern double accept_proportion;
index 172bbe8afabf040ac91a9b114267b6b4a920e278..78912e72893eae5d73de865539e77598dbc41df6 100644 (file)
--- 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,9 +218,8 @@ 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, const char *what) {
 
 #define RCI_NOTHING(x) /* nothing */
 #define RCI_TRIPLE_FMT(x) " " #x "=" RCI_TRIPLE_FMT_BASE
@@ -229,15 +230,15 @@ static void notice_processed(InputFile *ipf, int completed,
   char *inprog= completed
     ? xasprintf("%s","") /* GCC produces a stupid warning for printf("") ! */
     : xasprintf(" inprogress=%ld", ipf->inprogress);
-  char *autodefer= ipf->autodefer >= 0
+  char *autodefer= ipf && ipf->autodefer >= 0
     ? xasprintf(" autodeferred=%ld", ipf->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,
+       completed?"completed":"processed", what,
        ipf->counts.events[read_ok], ipf->counts.events[read_blank],
          ipf->counts.events[read_err],
        inprog, autodefer, ipf->counts.events[nooffer_missing],
@@ -256,17 +257,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; i<art_MaxState; i++)
+    for (j=0; j<RCI_max; j++)
+      backlog_counts.results[i][j] += ipf->counts.results[i][j];
+
+  for (i=0; i<ECI_max; i++)
+    backlog_counts.events[i] += ipf->counts.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)
@@ -287,7 +303,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();
 
@@ -484,11 +500,15 @@ 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_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;
 }