From 4acc53ac7710ec907e94679c2104500fa47ac878 Mon Sep 17 00:00:00 2001 From: Yao Yue Date: Wed, 16 Jan 2019 19:13:11 -0800 Subject: [PATCH] Stats to file (#186) * add support for logging stats (in CSV format with each entry as name:value) to a file --- include/cc_stats_log.h | 38 +++++++++++++++++ src/cc_debug.c | 1 - src/stats/CMakeLists.txt | 1 + src/stats/cc_stats_log.c | 88 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 include/cc_stats_log.h create mode 100644 src/stats/cc_stats_log.c diff --git a/include/cc_stats_log.h b/include/cc_stats_log.h new file mode 100644 index 000000000..265358be3 --- /dev/null +++ b/include/cc_stats_log.h @@ -0,0 +1,38 @@ +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + + +#define STATS_LOG_FILE NULL /* default log file */ +#define STATS_LOG_NBUF 0 /* default log buf size */ + +/* name type default description */ +#define STATSLOG_OPTION(ACTION) \ + ACTION( stats_log_file, OPTION_TYPE_STR, NULL, "file storing stats" )\ + ACTION( stats_log_nbuf, OPTION_TYPE_UINT, STATS_LOG_NBUF, "stats log buf size" ) + +typedef struct { + STATSLOG_OPTION(OPTION_DECLARE) +} stats_log_options_st; + + +/* dump stats as CSV records into a log file, this allows metrics to be captured + * locally without setting up an observability infrastructure + */ +void stats_log_setup(stats_log_options_st *options); +void stats_log_teardown(void); + +void stats_log(struct metric metrics[], unsigned int nmetric); + +void stats_log_flush(void); + + +#ifdef __cplusplus +} +#endif + diff --git a/src/cc_debug.c b/src/cc_debug.c index 7c766260b..c0fd85a78 100644 --- a/src/cc_debug.c +++ b/src/cc_debug.c @@ -20,7 +20,6 @@ #include #include #include -#include