diff --git a/userspace/falco/stats_writer.cpp b/userspace/falco/stats_writer.cpp index 9aa2922d..8d6dee4a 100644 --- a/userspace/falco/stats_writer.cpp +++ b/userspace/falco/stats_writer.cpp @@ -246,7 +246,7 @@ void stats_writer::worker() noexcept { // this helps waiting for the first tick tick = stats_writer::get_ticker(); - if(first_tick != tick) { + if(m_first_run || first_tick != tick) { if(last_tick != tick) { m_total_samples++; } @@ -274,6 +274,7 @@ void stats_writer::worker() noexcept { "stats_writer (worker): " + std::string(e.what()) + "\n"); } } + m_first_run = false; } } @@ -638,7 +639,7 @@ void stats_writer::collector::collect(const std::shared_ptr& inspector, #endif /* Collect stats / metrics once per ticker period. */ auto tick = stats_writer::get_ticker(); - if(tick != m_last_tick) { + if(m_first_run || tick != m_last_tick) { m_last_tick = tick; auto now = std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()) @@ -659,7 +660,10 @@ void stats_writer::collector::collect(const std::shared_ptr& inspector, num_evts, now, stats_snapshot_time_delta_sec); - get_metrics_output_fields_additional(output_fields, stats_snapshot_time_delta_sec); + if(!m_first_run) { + get_metrics_output_fields_additional(output_fields, stats_snapshot_time_delta_sec); + } + m_first_run = false; /* Send message in the queue */ stats_writer::msg msg; diff --git a/userspace/falco/stats_writer.h b/userspace/falco/stats_writer.h index 0dd0a7ff..53c7f45b 100644 --- a/userspace/falco/stats_writer.h +++ b/userspace/falco/stats_writer.h @@ -82,6 +82,7 @@ public: double stats_snapshot_time_delta_sec); std::shared_ptr m_writer; + bool m_first_run = true; stats_writer::ticker_t m_last_tick = 0; uint64_t m_last_now = 0; uint64_t m_last_n_evts = 0; @@ -144,6 +145,7 @@ private: inline void push(const stats_writer::msg& m); bool m_initialized = false; + bool m_first_run = true; uint64_t m_total_samples = 0; std::thread m_worker; std::ofstream m_file_output;