source: tools/tracereport/misc_report.c @ 80d23bb

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 80d23bb was 954a329, checked in by Shane Alcock <salcock@…>, 14 years ago

Added uncompressed trace size to the misc-report in tracereport
Fixed incorrect byte-ordering of wire length in legacyeth

  • Property mode set to 100644
File size: 2.1 KB
Line 
1#include <inttypes.h>
2#include <stdio.h>
3#include <stdbool.h>
4#include <time.h>
5#include <string.h>
6#include "libtrace.h"
7#include "tracereport.h"
8#include "report.h"
9
10static double starttime;
11static double endtime;
12static bool has_starttime = false;
13static bool has_endtime = false;
14static uint64_t packets = 0;
15
16static uint64_t capture_bytes = 0;
17
18void misc_per_packet(struct libtrace_packet_t *packet)
19{
20        double ts = trace_get_seconds(packet);
21        if (!has_starttime || starttime > ts)
22                starttime = ts;
23        if (!has_endtime || endtime < ts)
24                endtime = ts;
25        has_starttime = has_endtime = true;
26        ++packets;
27        capture_bytes += trace_get_capture_length(packet) + trace_get_framing_length(packet);
28}
29
30static char *ts_to_date(double ts)
31{
32        time_t sec = (time_t)ts;
33        static char ret[1024];
34        strcpy(ret,ctime(&sec));
35        ret[strlen(ret)-1]='\0'; /* Get rid of the annoying \n */
36        return ret;
37}
38
39static char *duration(double ts)
40{
41        static char ret[1024];
42        char tmp[1024];
43        ret[0]='\0';
44        if (ts == 0) 
45                return "0 seconds";
46        if (ts>=24*60*60) {
47                snprintf(ret,sizeof(ret),"%i days",(int)(ts/(24*60*60)));
48                ts-=(int)(ts/(24*60*60))*24*60*60;
49        }
50        if (ts>=60*60) {
51                snprintf(tmp,sizeof(tmp),"%s%i hours",
52                                ret[0]?", ":"",
53                                (int)ts/(60*60));
54                strcat(ret,tmp);
55                ts-=(int)(ts/(60*60))*60*60;
56        }
57        if (ts>=60) {
58                snprintf(tmp,sizeof(tmp),"%s%i minutes",
59                                ret[0]?", ":"",
60                                (int)ts/60);
61                strcat(ret,tmp);
62                ts-=(int)(ts/60)*60;
63        }
64        if (ts>0) {
65                snprintf(tmp,sizeof(tmp),"%s%.04f seconds",
66                                ret[0]?", ":"",
67                                ts);
68                strcat(ret,tmp);
69        }
70        return ret;
71}
72
73void misc_report(void)
74{
75        FILE *out = fopen("misc.rpt", "w");
76        if (!out) {
77                perror("fopen");
78                return;
79        }
80        fprintf(out, "Start time: %.04f (%s)\n",starttime,ts_to_date(starttime));
81        fprintf(out, "End time: %.04f (%s)\n",endtime,ts_to_date(endtime));
82        fprintf(out, "Duration: %.04f (%s)\n",endtime-starttime,
83                        duration(endtime-starttime));
84        fprintf(out, "Total Packets: %" PRIu64 "\n",packets);
85        fprintf(out, "Average packet rate: %.02f packets/sec\n",
86                        packets/(endtime-starttime));
87        fprintf(out, "Uncompressed trace size: %" PRIu64 "\n", capture_bytes);
88}
Note: See TracBrowser for help on using the repository browser.