|
| 1 | +/** |
| 2 | + * @file |
| 3 | + * @author Michal Sedlak <[email protected]> |
| 4 | + * @brief Statistics tracking and reporting |
| 5 | + * @date 2025 |
| 6 | + * |
| 7 | + * Copyright(c) 2025 CESNET z.s.p.o. |
| 8 | + * SPDX-License-Identifier: BSD-3-Clause |
| 9 | + */ |
| 10 | + |
| 11 | +#pragma once |
| 12 | + |
| 13 | +#include "common.h" |
| 14 | +#include <cstdint> |
| 15 | +#include <ctime> |
| 16 | + |
| 17 | +class Plugin; // Forward declaration of Plugin class. |
| 18 | + |
| 19 | +/** |
| 20 | + * @class Stats |
| 21 | + * @brief A class for tracking and reporting statistics related to data processing. |
| 22 | + * |
| 23 | + * The Stats class is responsible for maintaining counters and timestamps |
| 24 | + * to track the progress of data processing and periodically printing |
| 25 | + * statistics in a throttled manner. |
| 26 | + */ |
| 27 | +class Stats { |
| 28 | +public: |
| 29 | + /** |
| 30 | + * @brief Constructs a Stats object. |
| 31 | + * |
| 32 | + * @param logger A Logger instance for logging statistics. |
| 33 | + * @param plugin A reference to the Plugin instance associated with this Stats object. |
| 34 | + */ |
| 35 | + Stats(Logger logger, Plugin& plugin); |
| 36 | + |
| 37 | + /** |
| 38 | + * @brief Adds a specified number of records to the processed count. |
| 39 | + * |
| 40 | + * @param count The number of records to add. |
| 41 | + */ |
| 42 | + void add_recs(uint64_t count); |
| 43 | + |
| 44 | + /** |
| 45 | + * @brief Adds a specified number of rows to the written count. |
| 46 | + * |
| 47 | + * @param count The number of rows to add. |
| 48 | + */ |
| 49 | + void add_rows(uint64_t count); |
| 50 | + |
| 51 | + /** |
| 52 | + * @brief Adds a specified number of records to the dropped count. |
| 53 | + * |
| 54 | + * @param count The number of records to add. |
| 55 | + */ |
| 56 | + void add_dropped(uint64_t count); |
| 57 | + |
| 58 | + /** |
| 59 | + * @brief Prints the statistics if sufficient time has passed since the last print. |
| 60 | + */ |
| 61 | + void print_stats_throttled(time_t now); |
| 62 | + |
| 63 | +private: |
| 64 | + Logger m_logger; ///< Logger instance for logging statistics. |
| 65 | + Plugin &m_plugin; ///< Reference to the associated Plugin instance. |
| 66 | + uint64_t m_rows_written_total = 0; ///< Total number of rows written. |
| 67 | + uint64_t m_recs_processed_total = 0; ///< Total number of records processed. |
| 68 | + uint64_t m_recs_processed_since_last = 0; ///< Records processed since the last statistics print. |
| 69 | + uint64_t m_recs_dropped_total = 0; ///< Total number of records dropped. |
| 70 | + time_t m_start_time = 0; ///< Start time of the statistics tracking. |
| 71 | + time_t m_last_stats_print_time = 0; ///< Time of the last statistics print. |
| 72 | +}; |
0 commit comments