Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Unified Diff: ash/metrics/task_switch_metrics_recorder.cc

Issue 1133123003: Added metrics to track the time between task switches done via the shelf. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed oshima@'s comments from patch set 2. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/metrics/task_switch_metrics_recorder.h ('k') | ash/metrics/task_switch_metrics_recorder_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/metrics/task_switch_metrics_recorder.cc
diff --git a/ash/metrics/task_switch_metrics_recorder.cc b/ash/metrics/task_switch_metrics_recorder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c3911fe33f05e2a430de8d45fb5cbb0ac277fcc4
--- /dev/null
+++ b/ash/metrics/task_switch_metrics_recorder.cc
@@ -0,0 +1,64 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/metrics/task_switch_metrics_recorder.h"
+
+#include "ash/metrics/task_switch_time_tracker.h"
+
+namespace ash {
+
+namespace {
+
+const char kShelf_histogram[] = "Ash.Shelf.TimeBetweenNavigateToTaskSwitches";
+
+// Returns the histogram name for the given |task_switch_source|.
+const char* GetHistogramName(
+ TaskSwitchMetricsRecorder::TaskSwitchSource task_switch_source) {
+ switch (task_switch_source) {
+ case TaskSwitchMetricsRecorder::kShelf:
+ return kShelf_histogram;
+ }
+ NOTREACHED();
+ return nullptr;
+}
+
+} // namespace
+
+TaskSwitchMetricsRecorder::TaskSwitchMetricsRecorder() {
+}
+
+TaskSwitchMetricsRecorder::~TaskSwitchMetricsRecorder() {
+}
+
+void TaskSwitchMetricsRecorder::OnTaskSwitch(
+ TaskSwitchSource task_switch_source) {
+ TaskSwitchTimeTracker* task_switch_time_tracker =
+ FindTaskSwitchTimeTracker(task_switch_source);
+ if (!task_switch_time_tracker)
+ AddTaskSwitchTimeTracker(task_switch_source);
+
+ task_switch_time_tracker = FindTaskSwitchTimeTracker(task_switch_source);
+ CHECK(task_switch_time_tracker);
+
+ task_switch_time_tracker->OnTaskSwitch();
+}
+
+TaskSwitchTimeTracker* TaskSwitchMetricsRecorder::FindTaskSwitchTimeTracker(
+ TaskSwitchSource task_switch_source) {
+ return histogram_map_.get(task_switch_source);
+}
+
+void TaskSwitchMetricsRecorder::AddTaskSwitchTimeTracker(
+ TaskSwitchSource task_switch_source) {
+ CHECK(histogram_map_.find(task_switch_source) == histogram_map_.end());
+
+ const char* histogram_name = GetHistogramName(task_switch_source);
+ CHECK(histogram_name);
oshima 2015/05/13 23:46:50 nit: DCHECK will be sufficient unless you want to
bruthig 2015/05/14 14:19:46 Done.
+
+ histogram_map_.add(task_switch_source,
+ scoped_ptr<TaskSwitchTimeTracker>(
+ new TaskSwitchTimeTracker(histogram_name)));
+}
+
+} // namespace ash
« no previous file with comments | « ash/metrics/task_switch_metrics_recorder.h ('k') | ash/metrics/task_switch_metrics_recorder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698