Chromium Code Reviews| Index: ash/metrics/task_switch_time_tracker.h |
| diff --git a/ash/metrics/task_switch_time_tracker.h b/ash/metrics/task_switch_time_tracker.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4f088275bee6e1134c48c9abc6c780be9170f58e |
| --- /dev/null |
| +++ b/ash/metrics/task_switch_time_tracker.h |
| @@ -0,0 +1,76 @@ |
| +// 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. |
| + |
| +#ifndef ASH_METRICS_TASK_SWITCH_TIME_TRACKER_H_ |
| +#define ASH_METRICS_TASK_SWITCH_TIME_TRACKER_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/time/time.h" |
| + |
| +namespace base { |
| +class HistogramBase; |
| +class TickClock; |
| +} |
| + |
| +namespace ash { |
| + |
| +namespace test { |
| +class TaskSwitchTimeTrackerTestAPI; |
| +} // namespace test |
| + |
| +// Tracks time deltas between task switches and records them in a histogram. |
| +class TaskSwitchTimeTracker { |
| + public: |
| + // Create a TaskSwitchTimeTracker that will record data to the histogram with |
| + // the given |histogram_name|. |
| + explicit TaskSwitchTimeTracker(const std::string& histogram_name); |
| + |
| + ~TaskSwitchTimeTracker(); |
| + |
| + // Notifies |this| that a task switch has occurred. A histogram data point |
| + // will be recorded for all calls but the first. |
| + void OnTaskSwitch(); |
| + |
| + private: |
| + friend class test::TaskSwitchTimeTrackerTestAPI; |
| + |
| + // Private constructor that the test::TaskSwitchTimeTrackerTestAPI can use to |
| + // inject a custom |tick_clock|. |
| + TaskSwitchTimeTracker(const std::string& histogram_name, |
| + scoped_ptr<base::TickClock> tick_clock); |
| + |
| + // Returns true if |last_action_time_| has a valid value. |
| + bool HasLastActionTime() const; |
| + |
| + // 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.
|
| + // |last_action_time_|. |
| + base::TimeTicks SetLastActionTime(); |
| + |
| + // Records a data point in the histogram. |
| + void RecordTimeDelta(); |
| + |
| + // Lazily obtains and sets the |histogram_|. |
| + base::HistogramBase* GetHistogram(); |
| + |
| + // The histogram name to record data to. |
| + std::string histogram_name_; |
| + |
| + // The histogram to log data to. Set via GetHistogram() using lazy load. |
| + base::HistogramBase* histogram_ = nullptr; |
| + |
| + // Tracks the last time OnTaskSwitch() was called. A value of |
| + // base::TimeTicks() should be interpreted as not set. |
| + base::TimeTicks last_action_time_; |
| + |
| + // The clock used to determine the |last_action_time_|. |
| + scoped_ptr<base::TickClock> tick_clock_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TaskSwitchTimeTracker); |
| +}; |
| + |
| +} // namespace ash |
| + |
| +#endif // ASH_METRICS_TASK_SWITCH_TIME_TRACKE_H_ |