Caffe2 - C++ API
A deep learning, cross platform ML framework
Public Member Functions | Static Public Member Functions
caffe2::StatRegistry Class Reference

Holds a map of atomic counters keyed by name. More...

#include <stats.h>

Public Member Functions

StatValueadd (const std::string &name)
 Add a new counter with given name. More...
void publish (ExportedStatList &exported, bool reset=false)
 Populate an ExportedStatList with current counter values. More...
ExportedStatList publish (bool reset=false)
void update (const ExportedStatList &data)
 Update values of counters contained in the given ExportedStatList to the values provided, creating counters that don't exist.

Static Public Member Functions

static StatRegistryget ()
 Retrieve the singleton StatRegistry, which gets populated through the CAFFE_EVENT macro.

Detailed Description

Holds a map of atomic counters keyed by name.

The StatRegistry singleton, accessed through StatRegistry::get(), holds counters registered through the macro CAFFE_EXPORTED_STAT. Example of usage:

struct MyCaffeClass { MyCaffeClass(const std::string& instanceName): stats_(instanceName) {} void run(int numRuns) { try { CAFFE_EVENT(stats_, num_runs, numRuns); tryRun(numRuns); CAFFE_EVENT(stats_, num_successes); } catch (std::exception& e) { CAFFE_EVENT(stats_, num_failures, 1, "arg_to_usdt", e.what()); } CAFFE_EVENT(stats_, usdt_only, 1, "arg_to_usdt"); } private: struct MyStats { CAFFE_STAT_CTOR(MyStats); CAFFE_EXPORTED_STAT(num_runs); CAFFE_EXPORTED_STAT(num_successes); CAFFE_EXPORTED_STAT(num_failures); CAFFE_STAT(usdt_only); } stats_; };

int main() { MyCaffeClass a("first"); MyCaffeClass b("second"); for (int i = 0; i < 10; ++i) {;; } ExportedStatList finalStats; StatRegistry::get().publish(finalStats); }

For every new instance of MyCaffeClass, a new counter is created with the instance name as prefix. Everytime run() is called, the corresponding counter will be incremented by the given value, or 1 if value not provided.

Counter values can then be exported into an ExportedStatList. In the example above, considering "tryRun" never throws, finalStats will be populated as follows:

first/num_runs 100 first/num_successes 10 first/num_failures 0 second/num_runs 50 second/num_successes 10 second/num_failures 0

The event usdt_only is not present in ExportedStatList because it is declared as CAFFE_STAT, which does not create a counter.

Additionally, for each call to CAFFE_EVENT, a USDT probe is generated. The probe will be set up with the following arguments:

It is also possible to create additional StatRegistry instances beyond the singleton. These instances are not automatically populated with CAFFE_EVENT. Instead, they can be populated from an ExportedStatList structure by calling StatRegistry::update().

Definition at line 117 of file stats.h.

Member Function Documentation

StatValue * caffe2::StatRegistry::add ( const std::string &  name)

Add a new counter with given name.

If a counter for this name already exists, returns a pointer to it.

Definition at line 17 of file

void caffe2::StatRegistry::publish ( ExportedStatList exported,
bool  reset = false 

Populate an ExportedStatList with current counter values.

If reset is true, resets all counters to zero. It is guaranteed that no count is lost.

Definition at line 29 of file

The documentation for this class was generated from the following files: