| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_TRACE_EVENT_MEMORY_DUMP_SCHEDULER_H | 5 #ifndef BASE_TRACE_EVENT_MEMORY_DUMP_SCHEDULER_H |
| 6 #define BASE_TRACE_EVENT_MEMORY_DUMP_SCHEDULER_H | 6 #define BASE_TRACE_EVENT_MEMORY_DUMP_SCHEDULER_H |
| 7 | 7 |
| 8 #include "base/base_export.h" | 8 #include "base/base_export.h" |
| 9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 void AddTrigger(MemoryDumpType trigger_type, | 34 void AddTrigger(MemoryDumpType trigger_type, |
| 35 MemoryDumpLevelOfDetail level_of_detail, | 35 MemoryDumpLevelOfDetail level_of_detail, |
| 36 uint32_t min_time_between_dumps_ms); | 36 uint32_t min_time_between_dumps_ms); |
| 37 | 37 |
| 38 // Starts periodic dumps. | 38 // Starts periodic dumps. |
| 39 void NotifyPeriodicTriggerSupported(); | 39 void NotifyPeriodicTriggerSupported(); |
| 40 | 40 |
| 41 // Starts polling memory total. | 41 // Starts polling memory total. |
| 42 void NotifyPollingSupported(); | 42 void NotifyPollingSupported(); |
| 43 | 43 |
| 44 // Resets time for triggering dump to account for minimum time between the |
| 45 // dumps. |
| 46 void NotifyDumpTriggered(); |
| 47 |
| 44 // Disables all triggers. | 48 // Disables all triggers. |
| 45 void DisableAllTriggers(); | 49 void DisableAllTriggers(); |
| 46 | 50 |
| 47 private: | 51 private: |
| 48 friend class MemoryDumpManagerTest; | 52 friend class MemoryDumpManagerTest; |
| 49 FRIEND_TEST_ALL_PREFIXES(MemoryDumpManagerTest, TestPollingOnDumpThread); | 53 FRIEND_TEST_ALL_PREFIXES(MemoryDumpManagerTest, TestPollingOnDumpThread); |
| 50 | 54 |
| 51 // Helper class to schdule periodic memory dumps. | 55 // Helper class to schdule periodic memory dumps. |
| 52 struct PeriodicTriggerState { | 56 struct PeriodicTriggerState { |
| 53 PeriodicTriggerState(); | 57 PeriodicTriggerState(); |
| 54 ~PeriodicTriggerState(); | 58 ~PeriodicTriggerState(); |
| 55 | 59 |
| 56 bool is_configured; | 60 bool is_configured; |
| 57 | 61 |
| 58 RepeatingTimer timer; | 62 RepeatingTimer timer; |
| 59 uint32_t dump_count; | 63 uint32_t dump_count; |
| 60 uint32_t min_timer_period_ms; | 64 uint32_t min_timer_period_ms; |
| 61 uint32_t light_dumps_rate; | 65 uint32_t light_dumps_rate; |
| 62 uint32_t heavy_dumps_rate; | 66 uint32_t heavy_dumps_rate; |
| 63 | 67 |
| 64 uint32_t light_dump_period_ms; | 68 uint32_t light_dump_period_ms; |
| 65 uint32_t heavy_dump_period_ms; | 69 uint32_t heavy_dump_period_ms; |
| 66 | 70 |
| 67 DISALLOW_COPY_AND_ASSIGN(PeriodicTriggerState); | 71 DISALLOW_COPY_AND_ASSIGN(PeriodicTriggerState); |
| 68 }; | 72 }; |
| 69 | 73 |
| 70 struct PollingTriggerState { | 74 struct PollingTriggerState { |
| 75 enum State { |
| 76 CONFIGURED, // Polling trigger was added. |
| 77 ENABLED, // Polling is running. |
| 78 DISABLED // Polling is disabled. |
| 79 }; |
| 80 |
| 71 static const uint32_t kNumTotalsTrackedForPeakDetection = 50; | 81 static const uint32_t kNumTotalsTrackedForPeakDetection = 50; |
| 72 | 82 |
| 73 explicit PollingTriggerState( | 83 explicit PollingTriggerState( |
| 74 scoped_refptr<SingleThreadTaskRunner> polling_task_runner); | 84 scoped_refptr<SingleThreadTaskRunner> polling_task_runner); |
| 75 ~PollingTriggerState(); | 85 ~PollingTriggerState(); |
| 76 | 86 |
| 77 bool is_configured; | 87 // Helper to clear the tracked memory totals and poll count from last dump. |
| 78 bool is_polling_enabled; | 88 void ResetTotals(); |
| 89 |
| 90 State current_state; |
| 79 MemoryDumpLevelOfDetail level_of_detail; | 91 MemoryDumpLevelOfDetail level_of_detail; |
| 80 | 92 |
| 81 scoped_refptr<SingleThreadTaskRunner> polling_task_runner; | 93 scoped_refptr<SingleThreadTaskRunner> polling_task_runner; |
| 82 uint32_t polling_interval_ms; | 94 uint32_t polling_interval_ms; |
| 83 | 95 |
| 84 // Minimum numer of polls after the last dump at which next dump can be | 96 // Minimum numer of polls after the last dump at which next dump can be |
| 85 // triggered. | 97 // triggered. |
| 86 int min_polls_between_dumps; | 98 int min_polls_between_dumps; |
| 87 int num_polls_from_last_dump; | 99 int num_polls_from_last_dump; |
| 88 | 100 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 PeriodicTriggerState periodic_state_; | 132 PeriodicTriggerState periodic_state_; |
| 121 PollingTriggerState polling_state_; | 133 PollingTriggerState polling_state_; |
| 122 | 134 |
| 123 DISALLOW_COPY_AND_ASSIGN(MemoryDumpScheduler); | 135 DISALLOW_COPY_AND_ASSIGN(MemoryDumpScheduler); |
| 124 }; | 136 }; |
| 125 | 137 |
| 126 } // namespace trace_event | 138 } // namespace trace_event |
| 127 } // namespace base | 139 } // namespace base |
| 128 | 140 |
| 129 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_SCHEDULER_H | 141 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_SCHEDULER_H |
| OLD | NEW |