e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen#ifndef STATS_METRICS_H
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen#define STATS_METRICS_H
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenstruct stats_settings;
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenstruct metric_field {
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen const char *field_key;
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen struct stats_dist *stats;
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen};
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenstruct metric {
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen const char *name;
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen /* Timing for how long the event existed */
5f08b0309190ec818d46bfe0e497468b30714a93Timo Sirainen struct stats_dist *duration_stats;
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen unsigned int fields_count;
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen struct metric_field *fields;
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen};
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenstruct stats_metrics *stats_metrics_init(const struct stats_settings *set);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenvoid stats_metrics_deinit(struct stats_metrics **metrics);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen
9c675f5e259c19f9fdc40808439479131b32421eTimo Sirainen/* Reset all metrics */
9c675f5e259c19f9fdc40808439479131b32421eTimo Sirainenvoid stats_metrics_reset(struct stats_metrics *metrics);
9c675f5e259c19f9fdc40808439479131b32421eTimo Sirainen
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen/* Returns event filter created from the stats_settings. */
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenstruct event_filter *
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenstats_metrics_get_event_filter(struct stats_metrics *metrics);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen/* Update metrics with given event. */
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenvoid stats_metrics_event(struct stats_metrics *metrics, struct event *event);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen/* Iterate through all the tracked metrics. */
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenstruct stats_metrics_iter *
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenstats_metrics_iterate_init(struct stats_metrics *metrics);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenconst struct metric *stats_metrics_iterate(struct stats_metrics_iter *iter);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainenvoid stats_metrics_iterate_deinit(struct stats_metrics_iter **iter);
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen
e9068f1c3326de0265d0ef542a0d7723f5f01bc8Timo Sirainen#endif