]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - topsites.c
Keep global statistics in memory and use them to check computation
[thirdparty/sarg.git] / topsites.c
index 950efdbcc8b0147f678bf02cab5099fb0aced268..7bc54a06af92aa31fd7dfdb23d8ee2fc36525840 100644 (file)
 #include "include/conf.h"
 #include "include/defs.h"
 
+#ifdef ENABLE_DOUBLE_CHECK_DATA
+extern struct globalstatstruct globstat;
+#endif
+
 void topsites(void)
 {
        FILE *fp_in, *fp_ou;
@@ -49,6 +53,11 @@ void topsites(void)
        long long int tnbytes=0;
        long long int tntime=0;
        long long int twork1=0, twork2=0, twork3=0;
+#ifdef ENABLE_DOUBLE_CHECK_DATA
+       long long int ttnacc=0;
+       long long int ttnbytes=0;
+       long long int ttntime=0;
+#endif
        int regs=0;
        int cstatus;
        int url_len;
@@ -136,12 +145,13 @@ void topsites(void)
                tnacc+=item.nacc;
                tnbytes+=item.nbytes;
                tntime+=item.nelap;
+#ifdef ENABLE_DOUBLE_CHECK_DATA
+               ttnacc+=item.nacc;
+               ttnbytes+=item.nbytes;
+               ttntime+=item.nelap;
+#endif
        }
        fclose(fp_in);
-       if (unlink(general2)) {
-               debuga(_("Cannot delete %s - %s\n"),general2,strerror(errno));
-               exit(EXIT_FAILURE);
-       }
        longline_destroy(&line);
 
        if (ourl) {
@@ -155,6 +165,18 @@ void topsites(void)
 
        fclose(fp_ou);
 
+#ifdef ENABLE_DOUBLE_CHECK_DATA
+       if (ttnacc!=globstat.nacc || ttnbytes!=globstat.nbytes || ttntime!=globstat.elap) {
+               debuga(_("Total statistics mismatch when reading %s to produce the top sites\n"),general2);
+               exit(EXIT_FAILURE);
+       }
+#endif
+
+       if (unlink(general2)) {
+               debuga(_("Cannot delete %s - %s\n"),general2,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
+
        if((TopsitesSort & TOPSITE_SORT_CONNECT) != 0) {
                sortf="-k 1,1 -k 2,2";
        } else if((TopsitesSort & TOPSITE_SORT_BYTES) != 0) {