-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding stats logging to pelikan_twemcache (#213)
* make stats log related changes in twemcache * Squashed 'deps/ccommon/' changes from f5efe29..4acc53a 4acc53a Stats to file (#186) 2168fec minimize osx build config (#185) 42b24de Simplify rust options, specify fewer output targets (#183) c9fa905 update CMakeRust used to latest version, tweaks to make build work (#184) 2ef0163 Reorder dependency includes in cmake, don't parallel build (#182) a6a54d9 remove endian-specific logic from str*cmp (#177) 4c0668b epoll_create* ignores size hint in newer kernels, switch to new API (#179) c9c5ee5 improve cc_bstring string literal and cstring names (#176) 0184d73 Add unit tests for buffer, fix buf/dbuf bugs and refactor (#174) d7dab43 create a .cargo/config so intellij uses the same target dir as cmake (#173) e710712 use accept4 for tcp_accept when available (#171) 21ba10e Remove cargo lock for shared lib, closes #169 (#172) 24660f1 update style guide (#170) 17baf1e Per thread logging (#168) git-subtree-dir: deps/ccommon git-subtree-split: 4acc53a * fix compile * Squashed 'deps/ccommon/' changes from 4acc53a..05eb03e 05eb03e fix inconsistent naming and bump version (#187) git-subtree-dir: deps/ccommon git-subtree-split: 05eb03e * Squashed 'deps/ccommon/' changes from 05eb03e..a4c0334 a4c0334 add linebreak to stats_log() (#188) git-subtree-dir: deps/ccommon git-subtree-split: a4c0334 * use finer grain proc time * update metric description
- Loading branch information
Yao Yue
authored
Jan 17, 2019
1 parent
0c0caa7
commit 94b1912
Showing
14 changed files
with
157 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <cc_metric.h> | ||
#include <cc_option.h> | ||
|
||
|
||
#define STATS_LOG_FILE NULL /* default log file */ | ||
#define STATS_LOG_NBUF 0 /* default log buf size */ | ||
|
||
/* name type default description */ | ||
#define STATS_LOG_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 { | ||
STATS_LOG_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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
set(SOURCE | ||
${SOURCE} | ||
stats/cc_metric.c | ||
stats/cc_stats_log.c | ||
PARENT_SCOPE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#include <cc_stats_log.h> | ||
|
||
#include <cc_debug.h> | ||
#include <cc_log.h> | ||
#include <cc_metric.h> | ||
|
||
#define STATS_LOG_MODULE_NAME "util::stats_log" | ||
#define STATS_LOG_FMT "%s: %s, " | ||
#define PRINT_BUF_LEN 64 | ||
|
||
static struct logger *slog = NULL; | ||
static bool stats_log_init = false; | ||
|
||
static char buf[PRINT_BUF_LEN]; | ||
|
||
|
||
void | ||
stats_log_setup(stats_log_options_st *options) | ||
{ | ||
size_t log_nbuf = STATS_LOG_NBUF; | ||
char *filename = STATS_LOG_FILE; | ||
|
||
log_info("set up the %s module", STATS_LOG_MODULE_NAME); | ||
|
||
if (stats_log_init) { | ||
log_warn("%s has already been setup, overwrite", STATS_LOG_MODULE_NAME); | ||
if (slog != NULL) { | ||
log_destroy(&slog); | ||
} | ||
} | ||
|
||
if (options != NULL) { | ||
filename = option_str(&options->stats_log_file); | ||
log_nbuf = option_uint(&options->stats_log_nbuf); | ||
} | ||
|
||
if (filename != NULL) { | ||
slog = log_create(filename, log_nbuf); | ||
if (slog == NULL) { | ||
log_warn("Could not create logger"); | ||
} | ||
} | ||
|
||
stats_log_init = true; | ||
} | ||
|
||
void | ||
stats_log_teardown(void) | ||
{ | ||
log_info("tear down the %s module", STATS_LOG_MODULE_NAME); | ||
|
||
if (!stats_log_init) { | ||
log_warn("%s has never been setup", STATS_LOG_MODULE_NAME); | ||
} | ||
|
||
if (slog != NULL) { | ||
log_destroy(&slog); | ||
} | ||
|
||
stats_log_init = false; | ||
} | ||
|
||
void | ||
stats_log(struct metric metrics[], unsigned int nmetric) | ||
{ | ||
unsigned int i; | ||
|
||
if (slog == NULL) { | ||
return; | ||
} | ||
|
||
for (i = 0; i < nmetric; i++, metrics++) { | ||
int len = 0; | ||
|
||
len = metric_print(buf, PRINT_BUF_LEN, STATS_LOG_FMT, metrics); | ||
log_write(slog, buf, len); | ||
} | ||
log_write(slog, CRLF, CRLF_LEN); | ||
} | ||
|
||
void | ||
stats_log_flush(void) | ||
{ | ||
if (slog == NULL) { | ||
return; | ||
} | ||
log_flush(slog); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters