source: tools/tracereport/misc_report.c @ ee6e802

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivendag_formatrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since ee6e802 was ee6e802, checked in by Shane Alcock <salcock@…>, 5 years ago

Updated copyright blurb on all source files

In some cases, this meant adding copyright blurbs to files that
had never had them before.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 *
3 * Copyright (c) 2007-2016 The University of Waikato, Hamilton, New Zealand.
4 * All rights reserved.
5 *
6 * This file is part of libtrace.
7 *
8 * This code has been developed by the University of Waikato WAND
9 * research group. For further information please see http://www.wand.net.nz/
10 *
11 * libtrace is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * libtrace is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23 *
24 *
25 */
26
27
28#include <inttypes.h>
29#include <stdio.h>
30#include <stdbool.h>
31#include <time.h>
32#include <string.h>
33#include "libtrace.h"
34#include "tracereport.h"
35#include "report.h"
36
37static double starttime;
38static double endtime;
39static bool has_starttime = false;
40static bool has_endtime = false;
41static uint64_t packets = 0;
42
43static uint64_t capture_bytes = 0;
44
45void misc_per_packet(struct libtrace_packet_t *packet)
46{
47        double ts = trace_get_seconds(packet);
48        if (!has_starttime || starttime > ts)
49                starttime = ts;
50        if (!has_endtime || endtime < ts)
51                endtime = ts;
52        has_starttime = has_endtime = true;
53        ++packets;
54        capture_bytes += trace_get_capture_length(packet) + trace_get_framing_length(packet);
55}
56
57static char *ts_to_date(double ts)
58{
59        time_t sec = (time_t)ts;
60        static char ret[1024];
61        strncpy(ret,ctime(&sec),1024-1);
62        ret[strlen(ret)-1]='\0'; /* Get rid of the annoying \n */
63        return ret;
64}
65
66static char *duration(double ts)
67{
68        static char ret[1024];
69        char tmp[1024];
70        ret[0]='\0';
71        if (ts == 0) 
72                return "0 seconds";
73        if (ts>=24*60*60) {
74                snprintf(ret,sizeof(ret),"%i days",(int)(ts/(24*60*60)));
75                ts-=(int)(ts/(24*60*60))*24*60*60;
76        }
77        if (ts>=60*60) {
78                snprintf(tmp,sizeof(tmp),"%s%i hours",
79                                ret[0]?", ":"",
80                                (int)ts/(60*60));
81                strncat(ret,tmp, 1024 - strlen(ret) - 1);
82                ts-=(int)(ts/(60*60))*60*60;
83        }
84        if (ts>=60) {
85                snprintf(tmp,sizeof(tmp),"%s%i minutes",
86                                ret[0]?", ":"",
87                                (int)ts/60);
88                strncat(ret,tmp, 1024 - strlen(ret) - 1);
89                ts-=(int)(ts/60)*60;
90        }
91        if (ts>0) {
92                snprintf(tmp,sizeof(tmp),"%s%.04f seconds",
93                                ret[0]?", ":"",
94                                ts);
95                strncat(ret,tmp, 1024 - strlen(ret) - 1);
96        }
97        return ret;
98}
99
100void misc_report(void)
101{
102        FILE *out = fopen("misc.rpt", "w");
103        if (!out) {
104                perror("fopen");
105                return;
106        }
107        fprintf(out, "Start time: %.04f (%s)\n",starttime,ts_to_date(starttime));
108        fprintf(out, "End time: %.04f (%s)\n",endtime,ts_to_date(endtime));
109        fprintf(out, "Duration: %.04f (%s)\n",endtime-starttime,
110                        duration(endtime-starttime));
111        fprintf(out, "Total Packets: %" PRIu64 "\n",packets);
112        fprintf(out, "Average packet rate: %.02f packets/sec\n",
113                        packets/(endtime-starttime));
114        fprintf(out, "Uncompressed trace size: %" PRIu64 "\n", capture_bytes);
115}
Note: See TracBrowser for help on using the repository browser.