forked from microsoft/Multiverso
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.cpp
More file actions
51 lines (41 loc) · 1.37 KB
/
dashboard.cpp
File metadata and controls
51 lines (41 loc) · 1.37 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
#include "multiverso/dashboard.h"
#include <map>
#include <sstream>
#include <string>
#include "multiverso/util/log.h"
namespace multiverso {
std::map<std::string, Monitor*> Dashboard::record_;
std::mutex Dashboard::m_;
void Dashboard::AddMonitor(const std::string& name, Monitor* monitor) {
std::lock_guard<std::mutex> l(m_);
CHECK(record_[name] == nullptr);
record_[name] = monitor;
}
void Dashboard::RemoveMonitor(const std::string& name) {
std::lock_guard<std::mutex> l(m_);
CHECK_NOTNULL(record_[name]);
record_.erase(name);
}
std::string Dashboard::Watch(const std::string& name) {
std::lock_guard<std::mutex> l(m_);
std::string result;
if (record_.find(name) == record_.end()) return result;
Monitor* monitor = record_[name];
CHECK_NOTNULL(monitor);
return monitor->info_string();
}
std::string Monitor::info_string() const {
std::ostringstream oss;
oss << "[" << name_ << "] "
<< " count = " << count_
<< " elapse = " << elapse_ << "ms"
<< " average = " << average() << "ms";
return oss.str();
}
void Dashboard::Display() {
std::lock_guard<std::mutex> l(m_);
Log::Info("--------------Show dashboard monitor information--------------\n");
for (auto& it : record_) Log::Info("%s\n", it.second->info_string().c_str());
Log::Info("--------------------------------------------------------------\n");
}
} // namespace multiverso