Commit 49072647 authored by bruthig's avatar bruthig Committed by Commit bot

Added Ash.TimeBetweenTaskSwitches to record time deltas between all recorded task switches.

TEST=TaskSwitchMetricsRecorderTest.VerifyTaskSwitchesRecordInAllTaskSwitchHistogram

BUG=487745

Review URL: https://codereview.chromium.org/1148723006

Cr-Commit-Position: refs/heads/master@{#333658}
parent ec4a2e23
......@@ -10,6 +10,8 @@ namespace ash {
namespace {
const char kAshTaskSwitchHistogramName[] = "Ash.TimeBetweenTaskSwitches";
const char kDesktopHistogramName[] =
"Ash.Desktop.TimeBetweenNavigateToTaskSwitches";
......@@ -31,6 +33,8 @@ const char kOverviewModeHistogramName[] =
const char* GetHistogramName(
TaskSwitchMetricsRecorder::TaskSwitchSource task_switch_source) {
switch (task_switch_source) {
case TaskSwitchMetricsRecorder::kAny:
return kAshTaskSwitchHistogramName;
case TaskSwitchMetricsRecorder::kAppList:
return kAppListHistogramName;
case TaskSwitchMetricsRecorder::kDesktop:
......@@ -58,6 +62,15 @@ TaskSwitchMetricsRecorder::~TaskSwitchMetricsRecorder() {
void TaskSwitchMetricsRecorder::OnTaskSwitch(
TaskSwitchSource task_switch_source) {
DCHECK_NE(task_switch_source, kAny);
if (task_switch_source != kAny) {
OnTaskSwitchInternal(task_switch_source);
OnTaskSwitchInternal(kAny);
}
}
void TaskSwitchMetricsRecorder::OnTaskSwitchInternal(
TaskSwitchSource task_switch_source) {
TaskSwitchTimeTracker* task_switch_time_tracker =
FindTaskSwitchTimeTracker(task_switch_source);
if (!task_switch_time_tracker)
......
......@@ -27,6 +27,9 @@ class ASH_EXPORT TaskSwitchMetricsRecorder {
// a task switch. Note this is not necessarily comprehensive of all sources.
// TODO(bruthig): Convert enum format from kValue to VALUE.
enum TaskSwitchSource {
// Task switches caused by any two sources in this enum. NOTE: This value
// should NOT be used outside of this class.
kAny,
// Task switches from selecting items in the app list.
kAppList,
// Task switches caused by the user activating a task window by clicking or
......@@ -46,19 +49,30 @@ class ASH_EXPORT TaskSwitchMetricsRecorder {
TaskSwitchMetricsRecorder();
virtual ~TaskSwitchMetricsRecorder();
// Notifies |this| that a "navigate to" task switch has occurred. A
// "navigate to" operation is defined by a task switch where the specific task
// that becomes active is user-predictable (ie Alt+Tab accelerator, launching
// a new window via the shelf, etc). Contrast to a "navigate away" operation
// which is defined as a user interaction that navigates away from a specified
// task and the next task that becomes active is likely not user-predictable
// (ie. closing or minimizing a window, closing a tab, etc).
// Notifies |this| that a "navigate to" task switch has occurred from the
// specified |task_switch_source|. The metrics associated with
// TaskSwitchSource::kAny source will be updated as well.
//
// NOTE: A |task_switch_source| value of TaskSwitchSource::kAny should not be
// used and behavior is undefined if it is.
//
// A "navigate to" operation is defined by a task switch where the specific
// task that becomes active is user-predictable (e.g., Alt+Tab accelerator,
// launching a new window via the shelf, etc). Contrast to a "navigate away"
// operation which is defined as a user interaction that navigates away from a
// specified task and the next task that becomes active is likely not
// user-predictable (e.g., closing or minimizing a window, closing a tab,
// etc).
//
// Will add an entry to |histogram_map_| when called for the first time for
// each |task_switch_source| value.
void OnTaskSwitch(TaskSwitchSource task_switch_source);
private:
// Internal implementation of OnTaskSwitch(TaskSwitchSource) that will accept
// the TaskSwitchSource::kAny value.
void OnTaskSwitchInternal(TaskSwitchSource task_switch_source);
// Returns the TaskSwitchTimeTracker associated with the specified
// |task_switch_source|. May return nullptr if mapping does not exist yet.
TaskSwitchTimeTracker* FindTaskSwitchTimeTracker(
......
......@@ -62,6 +62,17 @@ void TaskSwitchMetricsRecorderTest::TearDown() {
} // namespace
// Verifies that task switches from a non kAny source also add data to the
// Ash.TimeBetweenTaskSwitches histogram.
TEST_F(TaskSwitchMetricsRecorderTest,
VerifyTaskSwitchesRecordInAllTaskSwitchHistogram) {
const std::string kHistogramName = "Ash.TimeBetweenTaskSwitches";
OnTaskSwitch(TaskSwitchMetricsRecorder::kShelf);
OnTaskSwitch(TaskSwitchMetricsRecorder::kShelf);
histogram_tester_->ExpectTotalCount(kHistogramName, 1);
}
// Verifies that the TaskSwitchMetricsRecorder::kDesktop source adds data to the
// Ash.Desktop.TimeBetweenNavigateToTaskSwitches histogram.
TEST_F(TaskSwitchMetricsRecorderTest, VerifyTaskSwitchesForDesktopAreRecorded) {
......
......@@ -860,6 +860,20 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary>
</histogram>
<histogram name="Ash.TimeBetweenTaskSwitches" units="seconds">
<owner>bruthig@google.com</owner>
<owner>tdanderson@google.com</owner>
<summary>
The number of seconds between contiguous task switch user actions triggered
by any of the other task switch actions that are tracked. (e.g.,
Ash.Shelf.TimeBetweenNavigateToTaskSwitches,
Ash.Tab.TimeBetweenSwitchToExistingTabUserActions,
Ash.WindowCycleController.TimeBetweenTaskSwitches,
Ash.AppList.TimeBetweenTaskSwitches,
Ash.WindowSelector.TimeBetweenActiveWindowChanges, etc).
</summary>
</histogram>
<histogram name="Ash.TouchDuration" units="milliseconds">
<obsolete>
Deprecated 12/2013 in r239809, and replaced by Ash.TouchDuration2.
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