|
| 1 | + |
| 2 | +#include <iostream> |
| 3 | + |
| 4 | +#include "common/flowProvider.hpp" |
| 5 | + |
| 6 | +#include "mode.hpp" |
| 7 | +#include "printer.hpp" |
| 8 | + |
| 9 | +namespace fdsdump { |
| 10 | +namespace statistics { |
| 11 | + |
| 12 | +static void stats_merge( |
| 13 | + fds_file_stats &dst, |
| 14 | + const fds_file_stats &src) |
| 15 | +{ |
| 16 | + dst.recs_total += src.recs_total; |
| 17 | + dst.recs_bf_total += src.recs_bf_total; |
| 18 | + dst.recs_opts_total += src.recs_opts_total; |
| 19 | + dst.bytes_total += src.bytes_total; |
| 20 | + dst.pkts_total += src.pkts_total; |
| 21 | + dst.recs_tcp += src.recs_tcp; |
| 22 | + dst.recs_udp += src.recs_udp; |
| 23 | + dst.recs_icmp += src.recs_icmp; |
| 24 | + dst.recs_other += src.recs_other; |
| 25 | + dst.recs_bf_tcp += src.recs_bf_tcp; |
| 26 | + dst.recs_bf_udp += src.recs_bf_udp; |
| 27 | + dst.recs_bf_icmp += src.recs_bf_icmp; |
| 28 | + dst.recs_bf_other += src.recs_bf_other; |
| 29 | + dst.bytes_tcp += src.bytes_tcp; |
| 30 | + dst.bytes_udp += src.bytes_udp; |
| 31 | + dst.bytes_icmp += src.bytes_icmp; |
| 32 | + dst.bytes_other += src.bytes_other; |
| 33 | + dst.pkts_tcp += src.pkts_tcp; |
| 34 | + dst.pkts_udp += src.pkts_udp; |
| 35 | + dst.pkts_icmp += src.pkts_icmp; |
| 36 | + dst.pkts_other += src.pkts_other; |
| 37 | +} |
| 38 | + |
| 39 | +void |
| 40 | +mode_statistics(const shared_iemgr &iemgr, const Options &opts) |
| 41 | +{ |
| 42 | + auto printer = printer_factory(opts.get_output_specifier()); |
| 43 | + const FileList &file_names = opts.get_input_files(); |
| 44 | + unique_file file {nullptr, &fds_file_close}; |
| 45 | + fds_file_stats stats {}; |
| 46 | + |
| 47 | + file.reset(fds_file_init()); |
| 48 | + if (!file) { |
| 49 | + throw std::runtime_error("fds_file_init() has failed"); |
| 50 | + } |
| 51 | + |
| 52 | + for (const auto &file_name : file_names) { |
| 53 | + const uint32_t flags = FDS_FILE_READ | FDS_FILE_NOASYNC; |
| 54 | + const fds_file_stats *file_stats; |
| 55 | + int ret; |
| 56 | + |
| 57 | + ret = fds_file_open(file.get(), file_name.c_str(), flags); |
| 58 | + if (ret != FDS_OK) { |
| 59 | + const std::string err_msg = fds_file_error(file.get()); |
| 60 | + std::cerr << "fds_file_open('" << file_name << "') failed: " << err_msg << std::endl; |
| 61 | + continue; |
| 62 | + } |
| 63 | + |
| 64 | + file_stats = fds_file_stats_get(file.get()); |
| 65 | + if (!file_stats) { |
| 66 | + std::cerr << "fds_file_stats_get('" << file_name << "') failed" << std::endl; |
| 67 | + continue; |
| 68 | + } |
| 69 | + |
| 70 | + stats_merge(stats, *file_stats); |
| 71 | + } |
| 72 | + |
| 73 | + printer->print_prologue(); |
| 74 | + printer->print_stats(stats); |
| 75 | + printer->print_epilogue(); |
| 76 | + |
| 77 | + (void) iemgr; |
| 78 | + return; |
| 79 | +} |
| 80 | + |
| 81 | +} // statistics |
| 82 | +} // fdsdump |
0 commit comments