Skip to content

Commit 8764fff

Browse files
committed
fdsdump: add extra statistics to flowProvider
1 parent b429935 commit 8764fff

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/tools/fdsdump/src/common/flowProvider.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ void
2828
FlowProvider::add_file(const std::string &file)
2929
{
3030
m_remains.push_back(file);
31+
32+
unique_file file_obj(fds_file_init(), &fds_file_close);
33+
if (!file_obj) {
34+
throw std::runtime_error("fds_file_init() has failed");
35+
}
36+
37+
int ret;
38+
ret = fds_file_open(file_obj.get(), file.c_str(), FDS_FILE_READ);
39+
if (ret != FDS_OK) {
40+
const std::string err_msg = fds_file_error(file_obj.get());
41+
42+
std::cerr << "fds_file_open('" << file << "') failed: " << err_msg << std::endl;
43+
}
44+
45+
const fds_file_stats *stats = fds_file_stats_get(file_obj.get());
46+
if (stats) {
47+
m_total_flow_count += stats->recs_total;
48+
} else {
49+
std::cerr << "WARNING: " << file << " has no stats" << std::endl;
50+
}
3151
}
3252

3353
void
@@ -88,6 +108,7 @@ FlowProvider::prepare_next_record()
88108
ret = fds_file_read_rec(m_file.get(), &m_flow.rec, NULL);
89109
switch (ret) {
90110
case FDS_OK:
111+
m_processed_flow_count++;
91112
return true;
92113
case FDS_EOC:
93114
return false;
@@ -228,4 +249,11 @@ FlowProvider::next_record()
228249
}
229250
}
230251

252+
void
253+
FlowProvider::reset_counters()
254+
{
255+
m_processed_flow_count = 0;
256+
m_total_flow_count = 0;
257+
}
258+
231259
} // fdsdump

src/tools/fdsdump/src/common/flowProvider.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ class FlowProvider {
5454
Flow *
5555
next_record();
5656

57+
/**
58+
* @brief Reset the read and loaded flow counters
59+
*/
60+
void
61+
reset_counters();
62+
63+
/**
64+
* @brief Get the number of processed flows, i.e. the number of flows in files that we went through
65+
*/
66+
uint64_t get_processed_flow_count() const { return m_processed_flow_count; }
67+
68+
/**
69+
* @brief Get the total number of loaded flows, i.e. the number of flows in files that have been added
70+
*/
71+
uint64_t get_total_flow_count() const { return m_total_flow_count; }
72+
5773
private:
5874
bool prepare_next_file();
5975
bool prepare_next_record();
@@ -70,6 +86,9 @@ class FlowProvider {
7086
bool m_file_ready = false;
7187
bool m_biflow_autoignore = false;
7288

89+
uint64_t m_processed_flow_count = 0;
90+
uint64_t m_total_flow_count = 0;
91+
7392
Flow m_flow;
7493
};
7594

0 commit comments

Comments
 (0)