-
Notifications
You must be signed in to change notification settings - Fork 0
/
stat.cc
59 lines (45 loc) · 1.33 KB
/
stat.cc
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
#include "stat.h"
#include <iostream>
#include <mutex>
#include <vector>
#include "cluster_time.h"
#include "debug.h"
namespace slope {
namespace stat {
static std::unordered_map<std::string, std::vector<LogEntry>> logs;
static std::unordered_map<std::string, LogEntry> meta;
static std::mutex lk;
LogEntry::LogEntry(const std::string& value_):
relative_timestamp(std::chrono::high_resolution_clock::now()
- slope::time::calibrated_local_start_time),
value(value_) { }
void add_value(const std::string& key, const std::string& val) {
std::lock_guard<std::mutex> _(lk);
logs[key].emplace_back(val);
debout("add: " + key + "=" + val);
}
void set_param_meta(const std::string& key, const std::string& val) {
set_meta("param_" + key, val);
}
void set_meta(const std::string& key, const std::string& val) {
std::lock_guard<std::mutex> _(lk);
debout("meta: " + key + val);
meta.emplace(key, LogEntry(val));
}
void to_json(json& j, const LogEntry& e) noexcept {
j = json{{"nanos", e.relative_timestamp.count()}, {"value", e.value}};
}
json get_all_logs() {
return json{
{"time_series", logs},
{"meta", meta},
};
}
namespace key {
extern const std::string operation;
} // namespace key
namespace value{
extern const std::string done_time_calibrate;
} // namespace value
} // namespace time
} // namespace slope