forked from membase/ep-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatsnap.cc
More file actions
50 lines (44 loc) · 1.39 KB
/
statsnap.cc
File metadata and controls
50 lines (44 loc) · 1.39 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
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
#include "config.h"
#include <iostream>
#include <cstdlib>
#include <string>
#include <map>
#include "common.hh"
#include "statsnap.hh"
#include "ep_engine.h"
extern "C" {
static void add_stat(const char *key, const uint16_t klen,
const char *val, const uint32_t vlen,
const void *cookie) {
assert(cookie);
void *cokie = const_cast<void *>(cookie);
StatSnap *ssnap = static_cast<StatSnap *>(cokie);
ObjectRegistry::onSwitchThread(ssnap->getEngine());
std::string k(key, klen);
std::string v(val, vlen);
ssnap->getMap()[k] = v;
}
}
bool StatSnap::getStats() {
map.clear();
bool rv = engine->getStats(this, NULL, 0, add_stat) == ENGINE_SUCCESS &&
engine->getStats(this, "tap", 3, add_stat) == ENGINE_SUCCESS;
if (rv && engine->isShutdownMode()) {
map["ep_force_shutdown"] = engine->isForceShutdown() ? "true" : "false";
std::stringstream ss;
ss << ep_real_time();
map["ep_shutdown_time"] = ss.str();
}
return rv;
}
bool StatSnap::callback(Dispatcher &d, TaskId t) {
if (getStats()) {
engine->getEpStore()->getRWUnderlying()->snapshotStats(map);
}
if (runOnce) {
return false;
}
d.snooze(t, STATSNAP_FREQ);
return true;
}