Changeset 568


Ignore:
Timestamp:
02/09/06 03:55:26 (7 years ago)
Author:
bcj3
Message:

Added measurement of the length of each trace file because I needed to know how long some traces were. Time of the first packet minus time of the last packet is the duration of the trace.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/libtrace2/examples/count/tracestats.c

    r397 r568  
    7272        uint64_t count = 0; 
    7373        uint64_t bytes = 0; 
     74        struct timeval starttime, packettime; 
     75 
     76        starttime.tv_sec = 0; 
     77        starttime.tv_usec = 0; 
    7478 
    7579        fprintf(stderr,"%s:\n",uri); 
     
    8286                        break; 
    8387                } 
     88 
     89                packettime = trace_get_timeval(&packet); 
     90                /*  
     91                 * save the time of the first packet we see so that we can later 
     92                 * do some maths and work out how long this trace was 
     93                 */ 
     94                if(starttime.tv_sec == 0 && starttime.tv_usec == 0) 
     95                { 
     96                    starttime.tv_sec = packettime.tv_sec; 
     97                    starttime.tv_usec = packettime.tv_usec; 
     98                } 
    8499 
    85100                for(i=0;i<filter_count;++i) { 
     
    94109        } 
    95110 
     111 
    96112        for(i=0;i<filter_count;++i) { 
    97113                printf("%30s:\t%12"PRIu64"\t%12"PRIu64"\t%7.03f\n",filters[i].expr,filters[i].count,filters[i].bytes,filters[i].count*100.0/count); 
     
    102118        totcount+=count; 
    103119        totbytes+=bytes; 
     120         
     121        /* subtract the time of the first packet from the time of the last packet we saw */ 
     122        timersub(&packettime, &starttime, &packettime);  
     123        printf("Total Duration: %d.%06d seconds\n", (int)packettime.tv_sec, (int)packettime.tv_usec); 
    104124 
    105125        trace_destroy(trace); 
Note: See TracChangeset for help on using the changeset viewer.