OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 CONTENT_BROWSER_MEMORY_SWAP_METRICS_OBSERVER_H_ |
| 6 #define CONTENT_BROWSER_MEMORY_SWAP_METRICS_OBSERVER_H_ |
| 7 |
| 8 #include "base/time/time.h" |
| 9 #include "base/timer/timer.h" |
| 10 |
| 11 namespace content { |
| 12 |
| 13 // This class observes system's swapping behavior to collect metrics. |
| 14 // Metrics can be platform-specific. |
| 15 class SwapMetricsObserver { |
| 16 public: |
| 17 // This returns nullptr when swap metrics are not available on the system. |
| 18 static SwapMetricsObserver* GetInstance(); |
| 19 |
| 20 // Starts observing swap metrics. |
| 21 void Start(); |
| 22 |
| 23 // Stop observing swap metrics. |
| 24 void Stop(); |
| 25 |
| 26 protected: |
| 27 SwapMetricsObserver(); |
| 28 virtual ~SwapMetricsObserver(); |
| 29 |
| 30 // Periodically called to update swap metrics. |
| 31 void UpdateMetrics(); |
| 32 |
| 33 // Platform-dependent parts of UpdateMetrics(). |interval| is the elapsed time |
| 34 // since the last UpdateMetrics() call. |interval| will be zero when this |
| 35 // function is called for the first time. |
| 36 virtual void UpdateMetricsInternal(base::TimeDelta interval) = 0; |
| 37 |
| 38 private: |
| 39 // The interval between metrics updates. |
| 40 base::TimeDelta update_interval_; |
| 41 |
| 42 // A periodic timer to update swap metrics. |
| 43 base::RepeatingTimer timer_; |
| 44 |
| 45 // Holds the last TimeTicks when swap metrics are updated. |
| 46 base::TimeTicks last_ticks_; |
| 47 |
| 48 DISALLOW_COPY_AND_ASSIGN(SwapMetricsObserver); |
| 49 }; |
| 50 |
| 51 } // namespace |
| 52 |
| 53 #endif // CONTENT_BROWSER_MEMORY_SWAP_METRICS_OBSERVER_H_ |
OLD | NEW |