-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofiling.cpp
36 lines (31 loc) · 1019 Bytes
/
profiling.cpp
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
#include "rw/logging.h"
#include "rw/profiling.h"
// todo: replace with pdata
#include <unordered_map>
// global profiler map
static std::unordered_map<std::string, std::shared_ptr<profiling::Profiler>> g_profilers;
std::shared_ptr<profiling::Profiler> profiling::get(const std::string& name)
{
auto found = g_profilers.find(name);
if (found != g_profilers.end())
return found->second;
else {
auto profiler = std::make_shared<profiling::Profiler>(name);
g_profilers[name] = profiler;
return profiler;
}
}
void profiling::dump_and_clear()
{
auto logger = rw::logging::get("prof");
for (auto& p : g_profilers) {
if (p.second->count() > 0) {
auto us = std::chrono::duration<double, std::milli>(
p.second->total());
logger->info("{}: {:0.3f}ms, {}x", p.first,
us.count() / (double) p.second->count(),
p.second->count());
p.second->reset();
}
}
}