1 #include "caffe2/core/stats.h" 3 #include <condition_variable> 9 ExportedStatMap statMap;
10 for (
const auto& stat : stats) {
12 statMap[stat.key] += stat.value;
18 std::lock_guard<std::mutex> lg(mutex_);
19 auto it = stats_.find(name);
20 if (it != stats_.end()) {
21 return it->second.get();
23 auto v = std::unique_ptr<StatValue>(
new StatValue);
25 stats_.insert(std::make_pair(name, std::move(v)));
30 std::lock_guard<std::mutex> lg(mutex_);
31 exported.resize(stats_.size());
33 for (
const auto& kv : stats_) {
34 auto& out = exported.at(i++);
36 out.value = reset ? kv.second->reset() : kv.second->get();
37 out.ts = std::chrono::high_resolution_clock::now();
42 for (
const auto& stat : data) {
43 add(stat.key)->increment(stat.value);
47 StatRegistry::~StatRegistry() {}
void publish(ExportedStatList &exported, bool reset=false)
Populate an ExportedStatList with current counter values.
StatValue * add(const std::string &name)
Add a new counter with given name.
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
std::vector< ExportedStatValue > ExportedStatList
Holds names and values of counters exported from a StatRegistry.
static StatRegistry & get()
Retrieve the singleton StatRegistry, which gets populated through the CAFFE_EVENT macro...
Holds a map of atomic counters keyed by name.
void update(const ExportedStatList &data)
Update values of counters contained in the given ExportedStatList to the values provided, creating counters that don't exist.