From: Frédéric Marchal Date: Fri, 10 Aug 2012 18:10:31 +0000 (+0200) Subject: Don't show the input log reading percentage X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2f4787e6cc496ebd38cf27b4d6a2bb8d172ca7c2;p=thirdparty%2Fsarg.git Don't show the input log reading percentage 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. --- diff --git a/getconf.c b/getconf.c index 65b8769..b4cfba5 100644 --- 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; diff --git a/include/conf.h b/include/conf.h index 81e0008..950b7da 100755 --- a/include/conf.h +++ b/include/conf.h @@ -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 494532e..de59db5 100644 --- 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; diff --git a/readlog.c b/readlog.c index 07ec46f..f65f1da 100644 --- 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 ; i0) { + 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); + } } } } diff --git a/sarg.conf b/sarg.conf index 9b3ccc6..5206fc7 100644 --- a/sarg.conf +++ b/sarg.conf @@ -465,9 +465,18 @@ #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.