source: tools/tracereport/dir_report.c @ 28df3e6

4.0.1-hotfixescachetimestampsdevelopdpdk-ndagetsilivegetfragoffhelplibtrace4ndag_formatpfringrc-4.0.1rc-4.0.2rc-4.0.3rc-4.0.4ringdecrementfixringperformanceringtimestampfixes
Last change on this file since 28df3e6 was 3b49843, checked in by Perry Lorier <perry@…>, 15 years ago

Don't segfault if there is no direction information

  • Property mode set to 100644
File size: 949 bytes
Line 
1#include <netdb.h>
2#include <inttypes.h>
3#include <lt_inttypes.h>
4#include <stdio.h>
5#include "libtrace.h"
6#include "tracereport.h"
7
8static uint64_t dir_bytes[8];
9static uint64_t dir_packets[8];
10
11void dir_per_packet(struct libtrace_packet_t *packet)
12{
13        if (trace_get_direction(packet)==-1)
14                return;
15        dir_bytes[trace_get_direction(packet)]+=trace_get_wire_length(packet);
16        ++dir_packets[trace_get_direction(packet)];
17}
18
19void dir_report(void)
20{
21        int i;
22        printf("# Direction\n");
23        printf("%-20s \t%12s\t%12s\n","Direction","bytes","packets");
24        for(i=0;i<8;++i) {
25                if (!dir_packets[i])
26                        continue;
27                switch(i) {
28                        case 0: printf("%20s:\t%12" PRIu64 "\t%12" PRIu64 "\n",
29                                        "in",dir_bytes[i],dir_packets[i]);
30                                break;
31                        case 1: printf("%20s:\t%12" PRIu64 "\t%12" PRIu64 "\n",
32                                        "out",dir_bytes[i],dir_packets[i]);
33                                break;
34                        default: printf("%20i:\t%12" PRIu64 "\t%12" PRIu64 "\n",
35                                        i,dir_bytes[i],dir_packets[i]);
36                                break;
37                }
38        }
39}
Note: See TracBrowser for help on using the repository browser.