diff options
author | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2015-11-02 15:57:34 +0100 |
---|---|---|
committer | Holger Hans Peter Freyther <holger@moiji-mobile.com> | 2015-11-02 15:57:34 +0100 |
commit | d7b0577d7d30139491b5cfeffb467440f9e88818 (patch) | |
tree | 0666fa8f415a47e8f5645dd87ad8844251251c6a /src/rate_ctr.c | |
parent | c84851bccc2e5e60536afa474a5f13134a3b79c9 (diff) | |
parent | 8f0374f7521376bdb721e821047e8a6a4a727283 (diff) |
Merge branch 'jerlbeck/wip/stats'
* This adds a new counter type (to measure time or delay)
* A statsd reporting backend. This can be fed into graphite
or similar tools.
* A periodic log backend for performance values
Diffstat (limited to 'src/rate_ctr.c')
-rw-r--r-- | src/rate_ctr.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/rate_ctr.c b/src/rate_ctr.c index 8a232e86..50b3fe74 100644 --- a/src/rate_ctr.c +++ b/src/rate_ctr.c @@ -83,6 +83,15 @@ void rate_ctr_add(struct rate_ctr *ctr, int inc) ctr->current += inc; } +/*! \brief Return the counter difference since the last call to this function */ +int64_t rate_ctr_difference(struct rate_ctr *ctr) +{ + int64_t result = ctr->current - ctr->previous; + ctr->previous = ctr->current; + + return result; +} + static void interval_expired(struct rate_ctr *ctr, enum rate_ctr_intv intv) { /* calculate rate over last interval */ @@ -177,4 +186,36 @@ const struct rate_ctr *rate_ctr_get_by_name(const struct rate_ctr_group *ctrg, c return NULL; } +int rate_ctr_for_each_counter(struct rate_ctr_group *ctrg, + rate_ctr_handler_t handle_counter, void *data) +{ + int rc = 0; + int i; + + for (i = 0; i < ctrg->desc->num_ctr; i++) { + struct rate_ctr *ctr = &ctrg->ctr[i]; + rc = handle_counter(ctrg, + ctr, &ctrg->desc->ctr_desc[i], data); + if (rc < 0) + return rc; + } + + return rc; +} + +int rate_ctr_for_each_group(rate_ctr_group_handler_t handle_group, void *data) +{ + struct rate_ctr_group *statg; + int rc = 0; + + llist_for_each_entry(statg, &rate_ctr_groups, list) { + rc = handle_group(statg, data); + if (rc < 0) + return rc; + } + + return rc; +} + + /*! @} */ |