Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "base/memory/scoped_ptr.h" | |
| 11 #include "base/time/time.h" | |
| 12 | |
| 13 namespace base { | |
| 14 class HistogramBase; | |
| 15 class TickClock; | |
| 16 } | |
| 17 | |
| 18 namespace ash { | |
| 19 | |
| 20 namespace test { | |
| 21 class TaskSwitchTimeTrackerTestAPI; | |
| 22 } // namespace test | |
| 23 | |
| 24 // Tracks time deltas between task switches and records them in a histogram. | |
| 25 class TaskSwitchTimeTracker { | |
| 26 public: | |
| 27 // Create a TaskSwitchTimeTracker that will record data to the histogram with | |
| 28 // the given |histogram_name|. | |
| 29 explicit TaskSwitchTimeTracker(const std::string& histogram_name); | |
| 30 | |
| 31 ~TaskSwitchTimeTracker(); | |
| 32 | |
| 33 // Notifies |this| that a task switch has occurred. A histogram data point | |
| 34 // will be recorded for all calls but the first. | |
| 35 void OnTaskSwitch(); | |
| 36 | |
| 37 private: | |
| 38 friend class test::TaskSwitchTimeTrackerTestAPI; | |
| 39 | |
| 40 // Private constructor that the test::TaskSwitchTimeTrackerTestAPI can use to | |
| 41 // inject a custom |tick_clock|. | |
| 42 TaskSwitchTimeTracker(const std::string& histogram_name, | |
| 43 scoped_ptr<base::TickClock> tick_clock); | |
| 44 | |
| 45 // Returns true if |last_action_time_| has a valid value. | |
| 46 bool HasLastActionTime() const; | |
| 47 | |
| 48 // Records the |last_action_time_| and returns the previous value for | |
|
tdanderson
2015/05/13 19:27:18
nit: specify that we're setting the member to be t
bruthig
2015/05/13 21:16:21
Done.
| |
| 49 // |last_action_time_|. | |
| 50 base::TimeTicks SetLastActionTime(); | |
| 51 | |
| 52 // Records a data point in the histogram. | |
| 53 void RecordTimeDelta(); | |
| 54 | |
| 55 // Lazily obtains and sets the |histogram_|. | |
| 56 base::HistogramBase* GetHistogram(); | |
| 57 | |
| 58 // The histogram name to record data to. | |
| 59 std::string histogram_name_; | |
| 60 | |
| 61 // The histogram to log data to. Set via GetHistogram() using lazy load. | |
| 62 base::HistogramBase* histogram_ = nullptr; | |
| 63 | |
| 64 // Tracks the last time OnTaskSwitch() was called. A value of | |
| 65 // base::TimeTicks() should be interpreted as not set. | |
| 66 base::TimeTicks last_action_time_; | |
| 67 | |
| 68 // The clock used to determine the |last_action_time_|. | |
| 69 scoped_ptr<base::TickClock> tick_clock_; | |
| 70 | |
| 71 DISALLOW_COPY_AND_ASSIGN(TaskSwitchTimeTracker); | |
| 72 }; | |
| 73 | |
| 74 } // namespace ash | |
| 75 | |
| 76 #endif // ASH_METRICS_TASK_SWITCH_TIME_TRACKE_H_ | |
| OLD | NEW |