]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Compute and display execution statistics
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 29 Aug 2012 18:23:39 +0000 (20:23 +0200)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Wed, 29 Aug 2012 18:23:39 +0000 (20:23 +0200)
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.

include/conf.h
log.c
readlog.c

index 15a7a00a5802a96f577e70b61f1e6ba48691e3a0..c66ecfa4c9959070e86b79603a76cba54f92de38 100755 (executable)
@@ -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 30bf27524379a16d8c758b87e1e6521abd50ede8..9c63c7b735875f91f9be233456a3b1464eb60f51 100644 (file)
--- 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"));
 
index 2f7cb68c83f4d92e4b8a6f05a98a044130d0a283..a9f636ce37f339aeb35cbb172529179f807983a8 100644 (file)
--- 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,