source: tools/tracereport/dir_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: 2.2 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 <netdb.h>
29#include <inttypes.h>
30#include <lt_inttypes.h>
31#include <stdio.h>
32#include "libtrace.h"
33#include "tracereport.h"
34#include "report.h"
35
36static uint64_t dir_bytes[8];
37static uint64_t dir_packets[8];
38
39void dir_per_packet(struct libtrace_packet_t *packet)
40{
41        if (trace_get_direction(packet)==-1)
42                return;
43        dir_bytes[trace_get_direction(packet)]+=trace_get_wire_length(packet);
44        ++dir_packets[trace_get_direction(packet)];
45}
46
47void dir_report(void)
48{
49        int i;
50        FILE *out = fopen("dir.rpt", "w");
51        if (!out) {
52                perror("fopen");
53                return;
54        }
55        fprintf(out, "%-20s \t%12s\t%12s\n","DIRECTION","BYTES","PACKETS");
56        for(i=0;i<8;++i) {
57                if (!dir_packets[i])
58                        continue;
59                switch(i) {
60                        case TRACE_DIR_INCOMING: fprintf(out, "%20s:\t%12" PRIu64 "\t%12" PRIu64 "\n",
61                                        "Incoming",dir_bytes[i],dir_packets[i]);
62                                break;
63                        case TRACE_DIR_OUTGOING: fprintf(out, "%20s:\t%12" PRIu64 "\t%12" PRIu64 "\n",
64                                        "Outgoing",dir_bytes[i],dir_packets[i]);
65                                break;
66                        case TRACE_DIR_OTHER: fprintf(out, "%20s:\t%12" PRIu64 "\t%12" PRIu64 "\n",
67                                        "Other",dir_bytes[i],dir_packets[i]);
68                                break;
69                        default: fprintf(out, "%20i:\t%12" PRIu64 "\t%12" PRIu64 "\n",
70                                        i,dir_bytes[i],dir_packets[i]);
71                                break;
72                }
73        }
74        fclose(out);
75}
Note: See TracBrowser for help on using the repository browser.