]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Don't show the input log reading percentage
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Fri, 10 Aug 2012 18:10:31 +0000 (20:10 +0200)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Fri, 10 Aug 2012 18:10:31 +0000 (20:10 +0200)
The show_read_percent option shows the percent of the input log file
reading independently of show_read_statistics. It allows for a progress
indicator without having to read the input log file twice.

getconf.c
include/conf.h
log.c
readlog.c
sarg.conf

index 65b8769edc679aeed719909b52dc8ac32e9882e4..b4cfba5a53ecbd4ef06f4832ad6f6f8d1c01eb5a 100644 (file)
--- a/getconf.c
+++ b/getconf.c
@@ -608,6 +608,8 @@ static void parmtest(char *buf)
 
        if (getparam_bool("show_read_statistics",buf,&ShowReadStatistics)>0) return;
 
+       if (getparam_bool("show_read_percent",buf,&ShowReadPercent)>0) return;
+
        if (getparam_list("topuser_fields",SET_LIST(topuserfields_values),buf,&TopUserFields)>0) return;
 
        if (getparam_bool("bytes_in_sites_users_report",buf,&BytesInSitesUsersReport)>0) return;
index 81e000839a8d538f37f98165387ebbb54f281f28..950b7da7b2ca54a677ef62262f7d82273b65a4bf 100755 (executable)
@@ -372,7 +372,15 @@ char DataFile[MAXLEN];
 char DataFileDelimiter[3];
 unsigned long int DataFileFields;
 unsigned long int DataFileUrl;
+//! if \c true, show the number of lines read from the input log file during the reading of the file.
 bool ShowReadStatistics;
+/*!
+If \c true, the read statistics also includes the percent of the number of lines read.
+
+Beware that it requires two readings of the input log file. It is not possible if the
+input log file is stdin or a pipe.
+*/
+bool ShowReadPercent;
 char IndexSortOrder[5];
 char DansGuardianConf[MAXLEN];
 bool DansguardianFilterOutDate;
diff --git a/log.c b/log.c
index 494532e5db897523c4597f9e7666cd6eb12dfdce..de59db5921d93b5af0040eb7711047909f9fc069 100644 (file)
--- a/log.c
+++ b/log.c
@@ -162,6 +162,7 @@ int main(int argc,char *argv[])
        DataFileFields=DATA_FIELD_USER | DATA_FIELD_DATE | DATA_FIELD_TIME | DATA_FIELD_URL | DATA_FIELD_CONNECT |
              DATA_FIELD_BYTES | DATA_FIELD_IN_CACHE | DATA_FIELD_OUT_CACHE | DATA_FIELD_ELAPSED;
        ShowReadStatistics=true;
+       ShowReadPercent=false;
        strcpy(IndexSortOrder,"D");
        ShowSargInfo=true;
        ShowSargLogo=true;
index 07ec46fb286de8dc65ab43f89708aab9a09b3f91..f65f1da219212fbf8f6a58b3b84b16505e29f14a 100644 (file)
--- a/readlog.c
+++ b/readlog.c
@@ -182,15 +182,15 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                ilf=ILF_Unknown;
                download_flag=false;
 
+               recs1=0UL;
+               recs2=0UL;
+
                // pre-read the file only if we have to show stats
-               if (ShowReadStatistics && !from_stdin && !from_pipe) {
+               if (ShowReadStatistics && ShowReadPercent && !from_stdin && !from_pipe) {
                        size_t nread,i;
                        bool skipcr=false;
                        char tmp4[MAXLEN];
 
-                       recs1=0UL;
-                       recs2=0UL;
-
                        while ((nread=fread(tmp4,1,sizeof(tmp4),fp_in))>0) {
                                for (i=0 ; i<nread ; i++)
                                        if (skipcr) {
@@ -252,9 +252,13 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                        }
 
                        recs2++;
-                       if( ShowReadStatistics && !from_stdin && !from_pipe && --OutputNonZero<=0) {
-                               double perc = recs2 * 100. / recs1 ;
-                               printf(_("SARG: Records in file: %lu, reading: %3.2lf%%"),recs2,perc);
+                       if (ShowReadStatistics && --OutputNonZero<=0) {
+                               if (recs1>0) {
+                                       double perc = recs2 * 100. / recs1 ;
+                                       printf(_("SARG: Records in file: %lu, reading: %3.2lf%%"),recs2,perc);
+                               } else {
+                                       printf(_("SARG: Records in file: %lu"),recs2);
+                               }
                                putchar('\r');
                                fflush (stdout);
                                OutputNonZero = REPORT_EVERY_X_LINES ;
@@ -884,8 +888,12 @@ int ReadLogFile(struct ReadLogDataStruct *Filter)
                                pclose(fp_in);
                        else {
                                fclose(fp_in);
-                               if( ShowReadStatistics )
-                                       printf(_("SARG: Records in file: %lu, reading: %3.2f%%\n"),recs1, (float) 100 );
+                               if (ShowReadStatistics) {
+                                       if (ShowReadPercent)
+                                               printf(_("SARG: Records in file: %lu, reading: %3.2f%%\n"),recs2, (float) 100 );
+                                       else
+                                               printf(_("SARG: Records in file: %lu\n"),recs2);
+                               }
                        }
                }
        }
index 9b3ccc6b3c555845f74764d596de907c072b9d23..5206fc7787df0c5ae719a1e998146ad6fa58badd 100644 (file)
--- a/sarg.conf
+++ b/sarg.conf
 #show_successful_message yes
 
 # TAG: show_read_statistics yes|no
-#      Shows some reading statistics.
+#      Shows how many lines have been read from the current input log file.
 #
-#show_read_statistics yes
+#show_read_statistics no
+
+# TAG: show_read_percent yes|no
+#      Shows how many percents have been read from the current input log file.
+#
+#      Beware that this feature requires to read the input log file once to
+#      count the number of lines and then a second time to actually parse it.
+#      You can save some time by disabling it.
+#
+#show_read_percent no
 
 # TAG: topuser_fields
 #      Which fields must be in Topuser report.