forked from membase/ep-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatwriter.hh
More file actions
83 lines (68 loc) · 2.38 KB
/
statwriter.hh
File metadata and controls
83 lines (68 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "config.h"
#include <iostream>
#include <memcached/engine.h>
#include <memcached/protocol_binary.h>
#include "ep_engine.h"
#include "histo.hh"
namespace STATWRITER_NAMESPACE {
inline void add_casted_stat(const char *k, const char *v,
ADD_STAT add_stat, const void *cookie) {
EventuallyPersistentEngine *e = ObjectRegistry::onSwitchThread(NULL, true);
add_stat(k, static_cast<uint16_t>(strlen(k)),
v, static_cast<uint32_t>(strlen(v)), cookie);
ObjectRegistry::onSwitchThread(e);
}
template <typename T>
void add_casted_stat(const char *k, T v,
ADD_STAT add_stat, const void *cookie) {
std::stringstream vals;
vals << v;
add_casted_stat(k, vals.str().c_str(), add_stat, cookie);
}
template <typename T>
void add_casted_stat(const char *k, const Atomic<T> &v,
ADD_STAT add_stat, const void *cookie) {
add_casted_stat(k, v.get(), add_stat, cookie);
}
/// @cond DETAILS
/**
* Convert a histogram into a bunch of calls to add stats.
*/
template <typename T>
struct histo_stat_adder {
histo_stat_adder(const char *k, ADD_STAT a, const void *c)
: prefix(k), add_stat(a), cookie(c) {}
void operator() (const HistogramBin<T>* b) {
if (b->count()) {
std::stringstream ss;
ss << prefix << "_" << b->start() << "," << b->end();
add_casted_stat(ss.str().c_str(), b->count(), add_stat, cookie);
}
}
const char *prefix;
ADD_STAT add_stat;
const void *cookie;
};
/// @endcond
template <typename T>
void add_casted_stat(const char *k, const Histogram<T> &v,
ADD_STAT add_stat, const void *cookie) {
histo_stat_adder<T> a(k, add_stat, cookie);
std::for_each(v.begin(), v.end(), a);
}
template <typename P, typename T>
void add_prefixed_stat(P prefix, const char *nm, T val,
ADD_STAT add_stat, const void *cookie) {
std::stringstream name;
name << prefix << ":" << nm;
add_casted_stat(name.str().c_str(), val, add_stat, cookie);
}
template <typename P, typename T>
void add_prefixed_stat(P prefix, const char *nm, Histogram<T> &val,
ADD_STAT add_stat, const void *cookie) {
std::stringstream name;
name << prefix << ":" << nm;
add_casted_stat(name.str().c_str(), val, add_stat, cookie);
}
}
using namespace STATWRITER_NAMESPACE;