15 #include <unordered_map> 21 using hires_clock = std::chrono::steady_clock;
25 using Event = std::pair<Timestamp, float>;
26 using Events = std::pair<Timestamp, std::vector<float>>;
29 void pushEvent(std::string
const& key,
float value = 1.0);
30 void pushEvents(std::string
const& key, std::vector<float> values);
32 std::vector<Event>
getLastEvents(std::string
const& key,
size_t n)
const;
34 bool hasEvent(std::string
const& key)
const;
36 using Reducer = std::function<float(float, float)>;
40 float initValue)
const;
41 void incCounter(std::string
const& key,
float amount = 1.0);
42 void setCounter(std::string
const& key,
float amount);
45 float getCounter(std::string
const& key)
const;
46 float getCounter(std::string
const& key,
float defaultValue)
const;
48 std::string
const& counterKey,
49 std::string
const& eventKey,
56 float initValue)
const;
57 void dumpJson(std::string
const& path)
const;
59 void loadJson(std::string
const& path);
67 hires_clock::time_point start_;
68 std::shared_ptr<MetricsContext> metrics_;
70 unsigned long subsampleFactor_;
76 std::shared_ptr<MetricsContext> metrics,
78 float subsampleRatio = 1);
83 std::unordered_map<std::string, std::vector<Event>>
timeSeries_;
86 std::unordered_map<std::string, std::vector<TimeInterval>>
intervals_;
~Timer()
Definition: metrics.cpp:256
uint64_t Timestamp
Definition: metrics.h:24
void setCounter(std::string const &key, float amount)
Definition: metrics.cpp:118
std::pair< Timestamp, std::vector< float >> Events
Definition: metrics.h:26
std::unordered_map< std::string, float > reduceEventValues(const Reducer &reducer, float initValue) const
Behaves exactly as std::accumulate on all the events streams.
Definition: metrics.cpp:81
bool hasCounter(std::string const &key) const
Definition: metrics.cpp:104
std::unordered_map< std::string, std::vector< Event > > timeSeries_
Definition: metrics.h:83
std::function< float(float, float)> Reducer
Definition: metrics.h:36
double TimeInterval
Definition: metrics.h:27
std::unordered_map< std::string, std::vector< TimeInterval > > intervals_
Definition: metrics.h:86
std::pair< Timestamp, float > Event
Definition: metrics.h:25
void pushEvent(std::string const &key, float value=1.0)
Definition: metrics.cpp:14
TimeInterval getLastInterval(std::string const &key) const
Definition: metrics.cpp:149
void snapshotCounter(std::string const &counterKey, std::string const &eventKey, float defaultValue)
Definition: metrics.cpp:133
std::unordered_map< std::string, float > counters_
Definition: metrics.h:85
std::mutex mutex_
Definition: metrics.h:87
std::unordered_map< std::string, float > getMeanEventValues() const
Definition: metrics.cpp:64
void dumpJson(std::string const &path) const
Definition: metrics.cpp:190
bool hasEvent(std::string const &key) const
Definition: metrics.cpp:59
std::vector< Event > getLastEvents(std::string const &key, size_t n) const
Definition: metrics.cpp:42
float getLastEventValue(std::string const &key) const
Definition: metrics.cpp:55
float getCounter(std::string const &key) const
Definition: metrics.cpp:109
void incCounter(std::string const &key, float amount=1.0)
Definition: metrics.cpp:99
The TorchCraftAI training library.
Definition: batcher.cpp:15
std::unordered_map< std::string, std::vector< Events > > timeSeriesS_
Definition: metrics.h:84
Timer(std::shared_ptr< MetricsContext > metrics, std::string key, float subsampleRatio=1)
Only subsampleRatio events are stored; it is expected that.
Definition: metrics.cpp:237
std::unordered_map< std::string, float > reduceIntervals(const Reducer &reducer, float initValue) const
Behaves exactly as std::accumulate on all the intervals streams.
Definition: metrics.cpp:176
Event getLastEvent(std::string const &key) const
Definition: metrics.cpp:32
void pushEvents(std::string const &key, std::vector< float > values)
Definition: metrics.cpp:22
bool operator==(const MetricsContext &) const
Definition: metrics.cpp:231
void clear()
Definition: metrics.cpp:223
std::unordered_map< std::string, float > getMeanIntervals() const
Definition: metrics.cpp:159
void loadJson(std::string const &path)
Definition: metrics.cpp:208