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 COMPONENTS_MEMORY_PRESSURE_MEMORY_PRESSURE_STATS_COLLECTOR_H_ | |
| 6 #define COMPONENTS_MEMORY_PRESSURE_MEMORY_PRESSURE_STATS_COLLECTOR_H_ | |
| 7 | |
| 8 #include "base/time/tick_clock.h" | |
| 9 #include "components/memory_pressure/memory_pressure_listener.h" | |
| 10 | |
| 11 namespace memory_pressure { | |
| 12 | |
| 13 // Enumeration of UMA memory pressure levels. This needs to be kept in sync with | |
| 14 // histograms.xml and the memory pressure levels defined in | |
|
grt (UTC plus 2)
2015/09/08 17:22:46
these values aren't in sync with MemoryPressureLev
chrisha
2015/09/08 18:48:43
Well, it needs to be kept in sync in the sense tha
| |
| 15 // MemoryPressureListener. Included in the header so that | |
| 16 // UMA_MEMORY_PRESSURE_LEVEL_COUNT is available. | |
| 17 enum MemoryPressureLevelUMA { | |
| 18 UMA_MEMORY_PRESSURE_LEVEL_NONE = 0, | |
| 19 UMA_MEMORY_PRESSURE_LEVEL_MODERATE = 1, | |
| 20 UMA_MEMORY_PRESSURE_LEVEL_CRITICAL = 2, | |
| 21 // This must be the last value in the enum. | |
| 22 UMA_MEMORY_PRESSURE_LEVEL_COUNT, | |
| 23 }; | |
| 24 | |
| 25 // Enumeration of UMA pressure level changes. This needs to be kept in sync | |
| 26 // with histograms.xml and the memory pressure levels defined in | |
| 27 // MemoryPressureListener. Exposed for unittesting. | |
| 28 enum MemoryPressureLevelChangeUMA { | |
| 29 UMA_MEMORY_PRESSURE_LEVEL_CHANGE_NONE_TO_MODERATE = 0, | |
| 30 UMA_MEMORY_PRESSURE_LEVEL_CHANGE_NONE_TO_CRITICAL = 1, | |
| 31 UMA_MEMORY_PRESSURE_LEVEL_CHANGE_MODERATE_TO_CRITICAL = 2, | |
| 32 UMA_MEMORY_PRESSURE_LEVEL_CHANGE_CRITICAL_TO_MODERATE = 3, | |
| 33 UMA_MEMORY_PRESSURE_LEVEL_CHANGE_CRITICAL_TO_NONE = 4, | |
| 34 UMA_MEMORY_PRESSURE_LEVEL_CHANGE_MODERATE_TO_NONE = 5, | |
| 35 // This must be the last value in the enum. | |
| 36 UMA_MEMORY_PRESSURE_LEVEL_CHANGE_COUNT | |
| 37 }; | |
| 38 | |
| 39 // Class that is responsible for collecting and eventually reporting memory | |
|
grt (UTC plus 2)
2015/09/08 17:22:46
nit: add the names of the histograms to the doc co
chrisha
2015/09/08 18:48:43
Done.
| |
| 40 // pressure statistics. | |
| 41 // | |
| 42 // On platforms with a polling memory pressure implementation the | |
| 43 // UpdateStatistics function will be invoked every time the pressure is polled. | |
| 44 // On non-polling platforms (Mac, Android) it will be invoked on a periodic | |
| 45 // timer, and at the moment of pressure level changes. | |
| 46 class MemoryPressureStatsCollector { | |
| 47 public: | |
| 48 using MemoryPressureLevel = MemoryPressureListener::MemoryPressureLevel; | |
| 49 | |
| 50 // The provided |tick_clock| must outlive this class. | |
| 51 MemoryPressureStatsCollector(base::TickClock* tick_clock); | |
| 52 | |
| 53 // This is to be called periodically to ensure that up to date statistics | |
| 54 // have been reported. | |
| 55 void UpdateStatistics(MemoryPressureLevel current_pressure_level); | |
| 56 | |
| 57 private: | |
| 58 friend class TestMemoryPressureStatsCollector; | |
| 59 | |
| 60 // Helper functions for delivering collected statistics. | |
| 61 static void ReportCumulativeTime(MemoryPressureLevel pressure_level, | |
| 62 int seconds); | |
| 63 static void ReportLevelChange(MemoryPressureLevel old_pressure_level, | |
| 64 MemoryPressureLevel new_pressure_level); | |
| 65 | |
| 66 // The tick clock in use. This class is intended to be owned by a class with | |
| 67 // a tick clock, and ownership remains there. Also intended as a test seam. | |
| 68 base::TickClock* tick_clock_; | |
| 69 | |
| 70 // Buckets of time that have been spent in different pressure levels, but | |
| 71 // not yet reported. At every call to UpdateStatistics these buckets will be | |
| 72 // drained of as many 'full' seconds of time as possible and reported via | |
| 73 // UMA. The remaining time (< 1000 ms) will be left in the bucket to be rolled | |
| 74 // into a later UMA report. | |
| 75 base::TimeDelta unreported_cumulative_time_[UMA_MEMORY_PRESSURE_LEVEL_COUNT]; | |
| 76 | |
| 77 // The last observed pressure level and the time at which it was observed, and | |
| 78 // the time when this pressure level started. | |
| 79 MemoryPressureLevel last_pressure_level_; | |
| 80 base::TimeTicks last_update_time_; | |
| 81 | |
| 82 DISALLOW_COPY_AND_ASSIGN(MemoryPressureStatsCollector); | |
| 83 }; | |
| 84 | |
| 85 } // namespace memory_pressure | |
| 86 | |
| 87 #endif // COMPONENTS_MEMORY_PRESSURE_MEMORY_PRESSURE_STATS_COLLECTOR_H_ | |
| OLD | NEW |