Previously, we did not have a license request latency metric. This is a notable limitation in our metrics. This adds a metric that captures the timing between a GenerateKeyRequest and an AddKey operation. Bug: 72994956 Test: New unit tests. Google Play Change-Id: If99c187399c02f9b5d4c355732af7588bbbefb11
41 lines
899 B
C++
41 lines
899 B
C++
#include "timer_metric.h"
|
|
|
|
#include <stddef.h>
|
|
#include <sys/time.h>
|
|
|
|
namespace wvcdm {
|
|
namespace metrics {
|
|
|
|
void TimerMetric::Start() {
|
|
struct timeval tv;
|
|
gettimeofday(&tv, NULL);
|
|
sec_ = tv.tv_sec;
|
|
usec_ = tv.tv_usec;
|
|
is_started_ = true;
|
|
}
|
|
|
|
void TimerMetric::Clear() {
|
|
is_started_ = false;
|
|
sec_ = 0;
|
|
usec_ = 0;
|
|
}
|
|
|
|
double TimerMetric::AsMs() const {
|
|
struct timeval tv;
|
|
gettimeofday(&tv, NULL);
|
|
return usec_ > tv.tv_usec ?
|
|
(tv.tv_sec - sec_ - 1) * 1000.0 + (tv.tv_usec - usec_ + 1000000.0) / 1000.0 :
|
|
(tv.tv_sec - sec_) * 1000.0 + (tv.tv_usec - usec_) / 1000.0;
|
|
}
|
|
|
|
double TimerMetric::AsUs() const {
|
|
struct timeval tv;
|
|
gettimeofday(&tv, NULL);
|
|
return usec_ > tv.tv_usec ?
|
|
(tv.tv_sec - sec_ - 1) * 1000000.0 + (tv.tv_usec - usec_ + 1000000.0) :
|
|
(tv.tv_sec - sec_) * 1000000.0 + (tv.tv_usec - usec_);
|
|
}
|
|
|
|
} // namespace metrics
|
|
} // namespace wvcdm
|