| 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 <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 RepeatingTimer timer; | 72 RepeatingTimer timer; |
| 73 uint32_t dump_count; | 73 uint32_t dump_count; |
| 74 uint32_t min_timer_period_ms; | 74 uint32_t min_timer_period_ms; |
| 75 uint32_t light_dumps_rate; | 75 uint32_t light_dumps_rate; |
| 76 uint32_t heavy_dumps_rate; | 76 uint32_t heavy_dumps_rate; |
| 77 | 77 |
| 78 uint32_t light_dump_period_ms; | 78 uint32_t light_dump_period_ms; |
| 79 uint32_t heavy_dump_period_ms; | 79 uint32_t heavy_dump_period_ms; |
| 80 | 80 |
| 81 bool is_enabled_for_testing; |
| 82 |
| 81 DISALLOW_COPY_AND_ASSIGN(PeriodicTriggerState); | 83 DISALLOW_COPY_AND_ASSIGN(PeriodicTriggerState); |
| 82 }; | 84 }; |
| 83 | 85 |
| 84 struct BASE_EXPORT PollingTriggerState { | 86 struct BASE_EXPORT PollingTriggerState { |
| 85 enum State { | 87 enum State { |
| 86 CONFIGURED, // Polling trigger was added. | 88 CONFIGURED, // Polling trigger was added. |
| 87 ENABLED, // Polling is running. | 89 ENABLED, // Polling is running. |
| 88 DISABLED // Polling is disabled. | 90 DISABLED // Polling is disabled. |
| 89 }; | 91 }; |
| 90 | 92 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 110 int64_t memory_increase_threshold; | 112 int64_t memory_increase_threshold; |
| 111 uint64_t last_memory_totals_kb[kMaxNumMemorySamples]; | 113 uint64_t last_memory_totals_kb[kMaxNumMemorySamples]; |
| 112 uint32_t last_memory_totals_kb_index; | 114 uint32_t last_memory_totals_kb_index; |
| 113 | 115 |
| 114 DISALLOW_COPY_AND_ASSIGN(PollingTriggerState); | 116 DISALLOW_COPY_AND_ASSIGN(PollingTriggerState); |
| 115 }; | 117 }; |
| 116 | 118 |
| 117 MemoryDumpScheduler(); | 119 MemoryDumpScheduler(); |
| 118 ~MemoryDumpScheduler(); | 120 ~MemoryDumpScheduler(); |
| 119 | 121 |
| 122 // Helper to enable timer on polling thread. |
| 123 void EnablePeriodicTimerOnPollingThread(); |
| 124 |
| 120 // Helper to set polling disabled. | 125 // Helper to set polling disabled. |
| 121 void DisablePollingOnPollingThread(); | 126 void DisableTriggersOnPollingThread(); |
| 122 | 127 |
| 123 // Periodically called by the timer. | 128 // Periodically called by the timer. |
| 124 void RequestPeriodicGlobalDump(); | 129 void RequestPeriodicGlobalDump(); |
| 125 | 130 |
| 126 // Called for polling memory usage and trigger dumps if peak is detected. | 131 // Called for polling memory usage and trigger dumps if peak is detected. |
| 127 void PollMemoryOnPollingThread(); | 132 void PollMemoryOnPollingThread(); |
| 128 | 133 |
| 129 // Returns true if peak memory value is detected. | 134 // Returns true if peak memory value is detected. |
| 130 bool ShouldTriggerDump(uint64_t current_memory_total); | 135 bool ShouldTriggerDump(uint64_t current_memory_total); |
| 131 | 136 |
| 132 // Helper to detect peaks in memory usage. | 137 // Helper to detect peaks in memory usage. |
| 133 bool IsCurrentSamplePeak(uint64_t current_memory_total); | 138 bool IsCurrentSamplePeak(uint64_t current_memory_total); |
| 134 | 139 |
| 135 // Must be set before enabling tracing. | 140 // Must be set before enabling tracing. |
| 136 static void SetPollingIntervalForTesting(uint32_t interval); | 141 static void SetPollingIntervalForTesting(uint32_t interval); |
| 137 | 142 |
| 138 // True if periodic dumping is enabled. | 143 // True if periodic dumping is enabled. |
| 139 bool IsPeriodicTimerRunningForTesting(); | 144 bool IsPeriodicTimerRunningForTesting(); |
| 140 | 145 |
| 146 // Timer.Start is not called if disabled, for tests without message loop. |
| 147 void DisablePeriodicTimerForTesting(bool disable); |
| 148 |
| 141 MemoryDumpManager* mdm_; | 149 MemoryDumpManager* mdm_; |
| 142 | 150 |
| 143 // Accessed on the thread of the client before enabling and only accessed on | 151 // Accessed on the thread of the client before enabling and only accessed on |
| 144 // the thread that called "EnablePeriodicTriggersIfNeeded()" after enabling. | 152 // the polling thread after enabling: |
| 145 std::unique_ptr<PeriodicTriggerState> periodic_state_; | 153 std::unique_ptr<PeriodicTriggerState> periodic_state_; |
| 146 | |
| 147 // Accessed on the thread of the client before enabling and only accessed on | |
| 148 // the polling thread after enabling. | |
| 149 std::unique_ptr<PollingTriggerState> polling_state_; | 154 std::unique_ptr<PollingTriggerState> polling_state_; |
| 150 | 155 |
| 151 // Accessed on the thread of the client only. | 156 // Accessed on the thread of the client only. |
| 152 scoped_refptr<SingleThreadTaskRunner> polling_task_runner_; | 157 scoped_refptr<SingleThreadTaskRunner> polling_task_runner_; |
| 153 | 158 |
| 154 // True when the scheduler is setup. Accessed on the thread of client only. | 159 // True when the scheduler is setup. Accessed on the thread of client only. |
| 155 bool is_setup_; | 160 bool is_setup_; |
| 156 | 161 |
| 162 // Disables the Timer.Start for periodic triggers. |
| 163 static bool periodic_timer_disabled_for_testing_; |
| 164 |
| 157 DISALLOW_COPY_AND_ASSIGN(MemoryDumpScheduler); | 165 DISALLOW_COPY_AND_ASSIGN(MemoryDumpScheduler); |
| 158 }; | 166 }; |
| 159 | 167 |
| 160 } // namespace trace_event | 168 } // namespace trace_event |
| 161 } // namespace base | 169 } // namespace base |
| 162 | 170 |
| 163 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_SCHEDULER_H | 171 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_SCHEDULER_H |
| OLD | NEW |