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 @@ ...@@ -10,7 +10,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/system_monitor/system_monitor.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 "base/trace_event/trace_event.h"
#include "media/audio/audio_manager.h" #include "media/audio/audio_manager.h"
#include "services/audio/debug_recording.h" #include "services/audio/debug_recording.h"
...@@ -60,7 +60,7 @@ void Service::OnStart() { ...@@ -60,7 +60,7 @@ void Service::OnStart() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DVLOG(4) << "audio::Service::OnStart"; DVLOG(4) << "audio::Service::OnStart";
metrics_ = metrics_ =
std::make_unique<ServiceMetrics>(base::DefaultClock::GetInstance()); std::make_unique<ServiceMetrics>(base::DefaultTickClock::GetInstance());
ref_factory_ = std::make_unique<service_manager::ServiceContextRefFactory>( ref_factory_ = std::make_unique<service_manager::ServiceContextRefFactory>(
base::BindRepeating(&Service::MaybeRequestQuitDelayed, base::BindRepeating(&Service::MaybeRequestQuitDelayed,
base::Unretained(this))); base::Unretained(this)));
......
...@@ -6,47 +6,47 @@ ...@@ -6,47 +6,47 @@
#include "base/debug/stack_trace.h" #include "base/debug/stack_trace.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/time/clock.h" #include "base/time/tick_clock.h"
namespace audio { namespace audio {
ServiceMetrics::ServiceMetrics(base::Clock* clock) ServiceMetrics::ServiceMetrics(const base::TickClock* clock)
: clock_(clock), service_start_(clock_->Now()) {} : clock_(clock), service_start_(clock_->NowTicks()) {}
ServiceMetrics::~ServiceMetrics() { ServiceMetrics::~ServiceMetrics() {
LogHasNoConnectionsDuration(); LogHasNoConnectionsDuration();
UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioService.Uptime", UMA_HISTOGRAM_CUSTOM_TIMES(
clock_->Now() - service_start_, base::TimeDelta(), "Media.AudioService.Uptime", clock_->NowTicks() - service_start_,
base::TimeDelta::FromDays(7), 50); base::TimeDelta(), base::TimeDelta::FromDays(7), 50);
} }
void ServiceMetrics::HasConnections() { void ServiceMetrics::HasConnections() {
has_connections_start_ = clock_->Now(); has_connections_start_ = clock_->NowTicks();
LogHasNoConnectionsDuration(); LogHasNoConnectionsDuration();
} }
void ServiceMetrics::HasNoConnections() { void ServiceMetrics::HasNoConnections() {
has_no_connections_start_ = clock_->Now(); has_no_connections_start_ = clock_->NowTicks();
DCHECK_NE(base::Time(), has_connections_start_); DCHECK_NE(base::TimeTicks(), has_connections_start_);
UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioService.HasConnectionsDuration", UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioService.HasConnectionsDuration",
clock_->Now() - has_connections_start_, clock_->NowTicks() - has_connections_start_,
base::TimeDelta(), base::TimeDelta::FromDays(7), base::TimeDelta(), base::TimeDelta::FromDays(7),
50); 50);
has_connections_start_ = base::Time(); has_connections_start_ = base::TimeTicks();
} }
void ServiceMetrics::LogHasNoConnectionsDuration() { void ServiceMetrics::LogHasNoConnectionsDuration() {
// Service shuts down without having accepted any connections in its lifetime // Service shuts down without having accepted any connections in its lifetime
// or with active connections, meaning there is no "no connection" interval in // or with active connections, meaning there is no "no connection" interval in
// progress. // progress.
if (has_no_connections_start_ == base::Time()) if (has_no_connections_start_.is_null())
return; return;
UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioService.HasNoConnectionsDuration", UMA_HISTOGRAM_CUSTOM_TIMES("Media.AudioService.HasNoConnectionsDuration",
clock_->Now() - has_no_connections_start_, clock_->NowTicks() - has_no_connections_start_,
base::TimeDelta(), base::TimeDelta(),
base::TimeDelta::FromMinutes(10), 50); base::TimeDelta::FromMinutes(10), 50);
has_no_connections_start_ = base::Time(); has_no_connections_start_ = base::TimeTicks();
} }
} // namespace audio } // namespace audio
...@@ -8,14 +8,14 @@ ...@@ -8,14 +8,14 @@
#include "base/time/time.h" #include "base/time/time.h"
namespace base { namespace base {
class Clock; class TickClock;
} }
namespace audio { namespace audio {
class ServiceMetrics { class ServiceMetrics {
public: public:
explicit ServiceMetrics(base::Clock* clock); explicit ServiceMetrics(const base::TickClock* clock);
~ServiceMetrics(); ~ServiceMetrics();
void HasConnections(); void HasConnections();
...@@ -24,10 +24,10 @@ class ServiceMetrics { ...@@ -24,10 +24,10 @@ class ServiceMetrics {
private: private:
void LogHasNoConnectionsDuration(); void LogHasNoConnectionsDuration();
const base::Clock* clock_; const base::TickClock* clock_;
const base::Time service_start_; const base::TimeTicks service_start_;
base::Time has_connections_start_; base::TimeTicks has_connections_start_;
base::Time has_no_connections_start_; base::TimeTicks has_no_connections_start_;
DISALLOW_COPY_AND_ASSIGN(ServiceMetrics); DISALLOW_COPY_AND_ASSIGN(ServiceMetrics);
}; };
......
...@@ -8,14 +8,14 @@ ...@@ -8,14 +8,14 @@
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/test/histogram_tester.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" #include "testing/gtest/include/gtest/gtest.h"
namespace audio { namespace audio {
TEST(AudioServiceMetricsTest, CreateDestroy_LogsUptime) { TEST(AudioServiceMetricsTest, CreateDestroy_LogsUptime) {
base::SimpleTestClock test_clock; base::SimpleTestTickClock test_clock;
test_clock.SetNow(base::Time::Now()); test_clock.SetNowTicks(base::TimeTicks::Now());
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
std::unique_ptr<ServiceMetrics> metrics = std::unique_ptr<ServiceMetrics> metrics =
...@@ -28,8 +28,8 @@ TEST(AudioServiceMetricsTest, CreateDestroy_LogsUptime) { ...@@ -28,8 +28,8 @@ TEST(AudioServiceMetricsTest, CreateDestroy_LogsUptime) {
} }
TEST(AudioServiceMetricsTest, AddRemoveConnection_LogsHasConnectionDuration) { TEST(AudioServiceMetricsTest, AddRemoveConnection_LogsHasConnectionDuration) {
base::SimpleTestClock test_clock; base::SimpleTestTickClock test_clock;
test_clock.SetNow(base::Time::Now()); test_clock.SetNowTicks(base::TimeTicks::Now());
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
ServiceMetrics metrics(&test_clock); ServiceMetrics metrics(&test_clock);
...@@ -44,8 +44,8 @@ TEST(AudioServiceMetricsTest, AddRemoveConnection_LogsHasConnectionDuration) { ...@@ -44,8 +44,8 @@ TEST(AudioServiceMetricsTest, AddRemoveConnection_LogsHasConnectionDuration) {
} }
TEST(AudioServiceMetricsTest, RemoveAddConnection_LogsHasNoConnectionDuration) { TEST(AudioServiceMetricsTest, RemoveAddConnection_LogsHasNoConnectionDuration) {
base::SimpleTestClock test_clock; base::SimpleTestTickClock test_clock;
test_clock.SetNow(base::Time::Now()); test_clock.SetNowTicks(base::TimeTicks::Now());
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
ServiceMetrics metrics(&test_clock); 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