source: tools/tracereport/drops_report.c @ 5478d3d

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

Fix all outstanding warnings

Implemented trace_get_statistics for formats that were missing it, so
we no longer need to use the deprecated trace_get_dropped_packets anywhere
within libtrace.

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[4423dc7]1#include <inttypes.h>
2#include <stdio.h>
3#include <stdbool.h>
4#include <time.h>
5#include <string.h>
[5478d3d]6#include <stdlib.h>
[4423dc7]7#include "libtrace.h"
8#include "tracereport.h"
9#include "report.h"
10
11static uint64_t received_packets = 0;
12static uint64_t filtered_packets = 0;
13static uint64_t dropped_packets = 0;
14static uint64_t accepted_packets = 0;
15
16static bool has_received=false;
17static bool has_filtered=false;
18static bool has_dropped=false;
19static bool has_accepted=false;
20
21void drops_per_trace(libtrace_t *trace)
22{
[5478d3d]23        libtrace_stat_t *stat;
[4423dc7]24
[5478d3d]25        stat = trace_create_statistics();
26
27        trace_get_statistics(trace, stat);
28
29        if (stat->received_valid) {
30                received_packets+=stat->received;
[4423dc7]31                has_received=true;
32        }
33
[5478d3d]34        if (stat->filtered_valid) {
35                filtered_packets+=stat->filtered;
[4423dc7]36                has_filtered=true;
37        }
38
[5478d3d]39        if (stat->dropped_valid) {
40                dropped_packets+=stat->dropped;
[4423dc7]41                has_dropped=true;
42        }
43
[5478d3d]44        if (stat->accepted_valid) {
45                accepted_packets+=stat->accepted;
[4423dc7]46                has_accepted=true;
47        }
[5478d3d]48        free(stat);
[4423dc7]49}
50
51
52void drops_report(void)
53{
54        FILE *out = fopen("drop.rpt", "w");
55        if (!out) {
56                perror("fopen");
57                return;
58        }
59        if (has_received)
60                fprintf(out, "Received Packets: %" PRIu64 "\n", received_packets);
61        if (has_filtered)
62                fprintf(out, "Filtered Packets: %" PRIu64 "\n", filtered_packets);
63        if (has_dropped)
64                fprintf(out, "Dropped Packets: %" PRIu64 "\n", dropped_packets);
65
66        if (has_accepted)
67                fprintf(out, "Accepted Packets: %" PRIu64 "\n", accepted_packets);
68        fclose(out);
69}
Note: See TracBrowser for help on using the repository browser.