From: Frédéric Marchal Date: Wed, 29 Aug 2012 18:23:39 +0000 (+0200) Subject: Compute and display execution statistics X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0459449fe526367bb6994d59bbf38b2c04aaea43;p=thirdparty%2Fsarg.git Compute and display execution statistics The total run time is displayed along with the number of lines read in the input logs, the number of records kept and the number of users. The time it takes to read the input log files and the time it takes to process the records are computed. --- diff --git a/include/conf.h b/include/conf.h index 15a7a00..c66ecfa 100755 --- a/include/conf.h +++ b/include/conf.h @@ -454,6 +454,12 @@ value means the process should never fails irrespective of the number of errors log files. */ int NumLogTotalErrors; +//! Count the number of lines read from the input log files. +unsigned long int lines_read; +//! Count the number of records kept for the processing. +unsigned long int records_kept; +//! Count the number of users. +unsigned long int nusers; int idate; int download_count; diff --git a/log.c b/log.c index 30bf275..9c63c7b 100644 --- a/log.c +++ b/log.c @@ -59,9 +59,18 @@ int main(int argc,char *argv[]) int LogStatus; bool realt; bool userip; + time_t start_time; + time_t end_time; + time_t read_start_time; + time_t read_end_time; + time_t process_start_time; + time_t process_end_time; + double read_elapsed; + double process_elapsed; static int split=0; static int convert=0; static int output_css=0; + static int show_statis=0; int option_index; static struct option long_options[]= { @@ -72,9 +81,12 @@ int main(int argc,char *argv[]) {"keeplogs",no_argument,NULL,3}, {"split",no_argument,&split,1}, {"splitprefix",required_argument,NULL,'P'}, + {"statistics",no_argument,&show_statis,1}, {0,0,0,0} }; + start_time=time(NULL); + #ifdef HAVE_LOCALE_H setlocale(LC_TIME,""); #endif @@ -248,6 +260,9 @@ int main(int argc,char *argv[]) KeepTempLog=false; NumLogSuccessiveErrors=3; NumLogTotalErrors=50; + lines_read=0UL; + records_kept=0UL; + nusers=0UL; bzero(IncludeUsers, sizeof(IncludeUsers)); bzero(ExcludeString, sizeof(ExcludeString)); @@ -666,7 +681,10 @@ int main(int argc,char *argv[]) init_usertab(UserTabFile); + read_start_time=time(NULL); LogStatus=ReadLogFile(&ReadFilter); + read_end_time=time(NULL); + read_elapsed=(double)read_end_time-(double)read_start_time; free_download(); free_excludecodes(); @@ -697,15 +715,17 @@ int main(int argc,char *argv[]) if(debug) debuga(_("Period: %s\n"),period.text); + process_start_time=time(NULL); if(DataFile[0] != '\0') data_file(tmp); else gerarel(); + process_end_time=time(NULL); + process_elapsed=(double)process_end_time-(double)process_start_time; denied_cleanup(); authfail_cleanup(); - if(!KeepTempLog && strcmp(tmp,"/tmp") != 0) { unlinkdir(tmp,0); } @@ -717,6 +737,20 @@ int main(int argc,char *argv[]) free(userfile); close_usertab(); + end_time=time(NULL); + + if (show_statis) { + double elapsed=(double)end_time-(double)start_time; + debuga(_("Total execution time: %.0lf seconds\n"),elapsed); + if (read_elapsed>0.) { + debuga(_("Lines read: %lu lines in %.0lf seconds (%.0lf lines/s)\n"),lines_read,read_elapsed,(double)lines_read/read_elapsed); + } + if (process_elapsed>0.) { + debuga(_("Processed records: %lu records in %.0lf seconds (%.0lf records/s)\n"),records_kept,process_elapsed,(double)records_kept/process_elapsed); + debuga(_("Users: %lu users in %.0lf seconds (%.0lf users/s)\n"),nusers,process_elapsed,(double)nusers/process_elapsed); + } + } + if(debug) debuga(_("End\n")); diff --git a/readlog.c b/readlog.c index 2f7cb68..a9f636c 100644 --- a/readlog.c +++ b/readlog.c @@ -208,6 +208,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) while ((linebuf=longline_read(fp_in,line))!=NULL) { blen=strlen(linebuf); + lines_read++; recs2++; if (ShowReadStatistics && --OutputNonZero<=0) { @@ -488,6 +489,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) uinfo=userinfo_create(log_entry.User); ufile->user=uinfo; uinfo->id_is_ip=id_is_ip; + nusers++; } else { if (prev_ufile) { prev_ufile->next=ufile->next; @@ -535,6 +537,7 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) debuga(_("Write error in the log file of user %s\n"),log_entry.User); exit(EXIT_FAILURE); } + records_kept++; if (fp_log && current_format!=&ReadSargLog) { fprintf(fp_log, "%s\t%s\t%s\t%s\t%s\t%"PRIu64"\t%s\t%ld\t%s\n",dia,hora,