Commit b1b39646 authored by Marina Ciocea's avatar Marina Ciocea Committed by Commit Bot

Use TimeTicks instead of Time in audio service metrics.

Change-Id: Ib7e84f47bd70ba36e00de7c5e9f75c8e2005c2c6
Reviewed-on: https://chromium-review.googlesource.com/1068183
Commit-Queue: Marina Ciocea <marinaciocea@chromium.org>
Commit-Queue: Olga Sharonova <olka@chromium.org>
Reviewed-by: default avatarOlga Sharonova <olka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561033}
parent 60808884
......@@ -10,7 +10,7 @@
#include "base/macros.h"
#include "base/single_thread_task_runner.h"
#include "base/system_monitor/system_monitor.h"
#include "base/time/default_clock.h"
#include "base/time/default_tick_clock.h"
#include "base/trace_event/trace_event.h"
#include "media/audio/audio_manager.h"
#include "services/audio/debug_recording.h"
......@@ -60,7 +60,7 @@ void Service::OnStart() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DVLOG(4) << "audio::Service::OnStart";
metrics_ =
std::make_unique<ServiceMetrics>(base::DefaultClock::GetInstance());
std::make_unique<ServiceMetrics>(base::DefaultTickClock::GetInstance());
ref_factory_ = std::make_unique<service_manager::ServiceContextRefFactory>(
base::BindRepeating(&Service::MaybeRequestQuitDelayed,
base::Unretained(this)));
......
......@@ -6,47 +6,47 @@
#include "base/debug/stack_trace.h"
#include "base/metrics/histogram_macros.h"
#include "base/time/clock.h"
#include "base/time/tick_clock.h"
namespace audio {
ServiceMetrics::ServiceMetrics(base::Clock* clock)
: clock_(clock), service_start_(clock_->Now()) {}
ServiceMetrics::ServiceMetrics(const base::TickClock* clock)
: clock_(clock), service_start_(clock_->NowTicks()) {}
ServiceMetrics::~ServiceMetrics() {
LogHasNoConnectionsDuration();
UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioService.Uptime",
clock_->Now() - service_start_, base::TimeDelta(),
base::TimeDelta::FromDays(7), 50);
UMA_HISTOGRAM_CUSTOM_TIMES(
"Media.AudioService.Uptime", clock_->NowTicks() - service_start_,
base::TimeDelta(), base::TimeDelta::FromDays(7), 50);
}
void ServiceMetrics::HasConnections() {
has_connections_start_ = clock_->Now();
has_connections_start_ = clock_->NowTicks();
LogHasNoConnectionsDuration();
}
void ServiceMetrics::HasNoConnections() {
has_no_connections_start_ = clock_->Now();
DCHECK_NE(base::Time(), has_connections_start_);
has_no_connections_start_ = clock_->NowTicks();
DCHECK_NE(base::TimeTicks(), has_connections_start_);
UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioService.HasConnectionsDuration",
clock_->Now() - has_connections_start_,
clock_->NowTicks() - has_connections_start_,
base::TimeDelta(), base::TimeDelta::FromDays(7),
50);
has_connections_start_ = base::Time();
has_connections_start_ = base::TimeTicks();
}
void ServiceMetrics::LogHasNoConnectionsDuration() {
// Service shuts down without having accepted any connections in its lifetime
// or with active connections, meaning there is no "no connection" interval in
// progress.
if (has_no_connections_start_ == base::Time())
if (has_no_connections_start_.is_null())
return;
UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioService.HasNoConnectionsDuration",
clock_->Now() - has_no_connections_start_,
clock_->NowTicks() - has_no_connections_start_,
base::TimeDelta(),
base::TimeDelta::FromMinutes(10), 50);
has_no_connections_start_ = base::Time();
has_no_connections_start_ = base::TimeTicks();
}
} // namespace audio
......@@ -8,14 +8,14 @@
#include "base/time/time.h"
namespace base {
class Clock;
class TickClock;
}
namespace audio {
class ServiceMetrics {
public:
explicit ServiceMetrics(base::Clock* clock);
explicit ServiceMetrics(const base::TickClock* clock);
~ServiceMetrics();
void HasConnections();
......@@ -24,10 +24,10 @@ class ServiceMetrics {
private:
void LogHasNoConnectionsDuration();
const base::Clock* clock_;
const base::Time service_start_;
base::Time has_connections_start_;
base::Time has_no_connections_start_;
const base::TickClock* clock_;
const base::TimeTicks service_start_;
base::TimeTicks has_connections_start_;
base::TimeTicks has_no_connections_start_;
DISALLOW_COPY_AND_ASSIGN(ServiceMetrics);
};
......
......@@ -8,14 +8,14 @@
#include "base/metrics/histogram_macros.h"
#include "base/test/histogram_tester.h"
#include "base/test/simple_test_clock.h"
#include "base/test/simple_test_tick_clock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace audio {
TEST(AudioServiceMetricsTest, CreateDestroy_LogsUptime) {
base::SimpleTestClock test_clock;
test_clock.SetNow(base::Time::Now());
base::SimpleTestTickClock test_clock;
test_clock.SetNowTicks(base::TimeTicks::Now());
base::HistogramTester histogram_tester;
std::unique_ptr<ServiceMetrics> metrics =
......@@ -28,8 +28,8 @@ TEST(AudioServiceMetricsTest, CreateDestroy_LogsUptime) {
}
TEST(AudioServiceMetricsTest, AddRemoveConnection_LogsHasConnectionDuration) {
base::SimpleTestClock test_clock;
test_clock.SetNow(base::Time::Now());
base::SimpleTestTickClock test_clock;
test_clock.SetNowTicks(base::TimeTicks::Now());
base::HistogramTester histogram_tester;
ServiceMetrics metrics(&test_clock);
......@@ -44,8 +44,8 @@ TEST(AudioServiceMetricsTest, AddRemoveConnection_LogsHasConnectionDuration) {
}
TEST(AudioServiceMetricsTest, RemoveAddConnection_LogsHasNoConnectionDuration) {
base::SimpleTestClock test_clock;
test_clock.SetNow(base::Time::Now());
base::SimpleTestTickClock test_clock;
test_clock.SetNowTicks(base::TimeTicks::Now());
base::HistogramTester histogram_tester;
ServiceMetrics metrics(&test_clock);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment