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

Side by Side Diff: ash/metrics/task_switch_time_tracker.h

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: Added ASH_EXPORT to TaskSwitchTimeTracker. 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef ASH_METRICS_TASK_SWITCH_TIME_TRACKER_H_
6 #define ASH_METRICS_TASK_SWITCH_TIME_TRACKER_H_
7
8 #include <string>
9
10 #include "ash/ash_export.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
13
14 namespace base {
15 class HistogramBase;
16 class TickClock;
17 }
18
19 namespace ash {
20
21 namespace test {
22 class TaskSwitchTimeTrackerTestAPI;
23 } // namespace test
24
25 // Tracks time deltas between task switches and records them in a histogram.
26 class ASH_EXPORT TaskSwitchTimeTracker {
27 public:
28 // Create a TaskSwitchTimeTracker that will record data to the histogram with
29 // the given |histogram_name|.
30 explicit TaskSwitchTimeTracker(const std::string& histogram_name);
31
32 ~TaskSwitchTimeTracker();
33
34 // Notifies |this| that a task switch has occurred. A histogram data point
35 // will be recorded for all calls but the first.
36 void OnTaskSwitch();
37
38 private:
39 friend class test::TaskSwitchTimeTrackerTestAPI;
40
41 // Private constructor that the test::TaskSwitchTimeTrackerTestAPI can use to
42 // inject a custom |tick_clock|.
43 TaskSwitchTimeTracker(const std::string& histogram_name,
44 scoped_ptr<base::TickClock> tick_clock);
45
46 // Returns true if |last_action_time_| has a valid value.
47 bool HasLastActionTime() const;
48
49 // Sets the |last_action_time_| to |tick_clock_|'s current value and returns
50 // the previous value for |last_action_time_|.
51 base::TimeTicks SetLastActionTime();
52
53 // Records a data point in the histogram.
54 void RecordTimeDelta();
55
56 // Lazily obtains and sets the |histogram_|.
57 base::HistogramBase* GetHistogram();
58
59 // The histogram name to record data to.
60 std::string histogram_name_;
61
62 // The histogram to log data to. Set via GetHistogram() using lazy load.
63 base::HistogramBase* histogram_ = nullptr;
64
65 // Tracks the last time OnTaskSwitch() was called. A value of
66 // base::TimeTicks() should be interpreted as not set.
67 base::TimeTicks last_action_time_ = base::TimeTicks();
68
69 // The clock used to determine the |last_action_time_|.
70 scoped_ptr<base::TickClock> tick_clock_;
71
72 DISALLOW_COPY_AND_ASSIGN(TaskSwitchTimeTracker);
73 };
74
75 } // namespace ash
76
77 #endif // ASH_METRICS_TASK_SWITCH_TIME_TRACKE_H_
OLDNEW
« no previous file with comments | « ash/metrics/task_switch_metrics_recorder_unittest.cc ('k') | ash/metrics/task_switch_time_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698