[ Merge from http://go/wvgerrit/71443 ] The assumption that the metrics will always outlive the CdmSession instance appears not to always hold (at least in a non-android multi-threaded solution). The shared_ptr ensures that the metrics are available even in these rare race conditions. BUG: http://b/123321465 Test: CDM unit tests. Also http://go/wvgerrit/71264 parallel tests. Change-Id: Iaa6a8f6c0fdc46a911789759d6e1228d849aa237
35 lines
931 B
C++
35 lines
931 B
C++
#ifndef WVCDM_METRICS_TIMER_METRIC_H_
|
|
#define WVCDM_METRICS_TIMER_METRIC_H_
|
|
|
|
#include <chrono>
|
|
|
|
namespace wvcdm {
|
|
namespace metrics {
|
|
|
|
class TimerMetric {
|
|
public:
|
|
// Constructs a new TimerMetric.
|
|
explicit TimerMetric() : is_started_(false) {}
|
|
// Starts the clock running. If the clock was previously set, this resets it.
|
|
// IsStarted will return true after this call.
|
|
void Start();
|
|
// Returns whether or not the timer has started.
|
|
bool IsStarted() const { return is_started_; }
|
|
// Stops the clock and clears the current value. IsStarted will return false
|
|
// after this call.
|
|
void Clear();
|
|
// Returns the current clock value as milliseconds (AsMs) or microseconds
|
|
// (AsUs).
|
|
double AsMs() const;
|
|
double AsUs() const;
|
|
|
|
private:
|
|
std::chrono::steady_clock clock_;
|
|
std::chrono::time_point<std::chrono::steady_clock> start_;
|
|
bool is_started_;
|
|
};
|
|
|
|
} // namespace metrics
|
|
} // namespace wvcdm
|
|
#endif
|