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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 uint32_t light_dumps_rate; | 61 uint32_t light_dumps_rate; |
62 uint32_t heavy_dumps_rate; | 62 uint32_t heavy_dumps_rate; |
63 | 63 |
64 uint32_t light_dump_period_ms; | 64 uint32_t light_dump_period_ms; |
65 uint32_t heavy_dump_period_ms; | 65 uint32_t heavy_dump_period_ms; |
66 | 66 |
67 DISALLOW_COPY_AND_ASSIGN(PeriodicTriggerState); | 67 DISALLOW_COPY_AND_ASSIGN(PeriodicTriggerState); |
68 }; | 68 }; |
69 | 69 |
70 struct PollingTriggerState { | 70 struct PollingTriggerState { |
| 71 static const uint32_t kMaxNumMemorySamples = 50; |
| 72 |
71 explicit PollingTriggerState( | 73 explicit PollingTriggerState( |
72 scoped_refptr<SingleThreadTaskRunner> polling_task_runner); | 74 scoped_refptr<SingleThreadTaskRunner> polling_task_runner); |
73 ~PollingTriggerState(); | 75 ~PollingTriggerState(); |
74 | 76 |
75 bool is_configured; | 77 bool is_configured; |
76 bool is_polling_enabled; | 78 bool is_polling_enabled; |
77 MemoryDumpLevelOfDetail level_of_detail; | 79 MemoryDumpLevelOfDetail level_of_detail; |
78 | 80 |
79 scoped_refptr<SingleThreadTaskRunner> polling_task_runner; | 81 scoped_refptr<SingleThreadTaskRunner> polling_task_runner; |
80 uint32_t polling_interval_ms; | 82 uint32_t polling_interval_ms; |
81 | 83 |
82 // Minimum numer of polls after the last dump at which next dump can be | 84 // Minimum numer of polls after the last dump at which next dump can be |
83 // triggered. | 85 // triggered. |
84 int min_polls_between_dumps; | 86 int min_polls_between_dumps; |
85 int num_polls_from_last_dump; | 87 int num_polls_from_last_dump; |
86 | 88 |
87 uint64_t last_dump_memory_total; | 89 uint64_t last_dump_memory_total; |
| 90 int64_t memory_increase_threshold; |
| 91 uint64_t last_memory_totals_kb[kMaxNumMemorySamples]; |
| 92 uint32_t last_memory_totals_kb_index; |
88 | 93 |
89 DISALLOW_COPY_AND_ASSIGN(PollingTriggerState); | 94 DISALLOW_COPY_AND_ASSIGN(PollingTriggerState); |
90 }; | 95 }; |
91 | 96 |
92 // Helper to set polling disabled on the polling thread. | 97 // Helper to set polling disabled on the polling thread. |
93 void DisablePolling(); | 98 void DisablePolling(); |
94 | 99 |
95 // Periodically called by the timer. | 100 // Periodically called by the timer. |
96 void RequestPeriodicGlobalDump(); | 101 void RequestPeriodicGlobalDump(); |
97 | 102 |
98 // Called for polling memory usage and trigger dumps if peak is detected. | 103 // Called for polling memory usage and trigger dumps if peak is detected. |
99 void PollMemoryOnPollingThread(); | 104 void PollMemoryOnPollingThread(); |
100 | 105 |
101 // Returns true if peak memory value is detected. | 106 // Returns true if peak memory value is detected. |
102 bool ShouldTriggerDump(uint64_t current_memory_total); | 107 bool ShouldTriggerDump(uint64_t current_memory_total); |
103 | 108 |
| 109 // Helper to detect peaks in memory usage. |
| 110 bool IsCurrentSamplePeak(uint64_t current_memory_total); |
| 111 |
104 // Must be set before enabling tracing. | 112 // Must be set before enabling tracing. |
105 static void SetPollingIntervalForTesting(uint32_t interval); | 113 static void SetPollingIntervalForTesting(uint32_t interval); |
106 | 114 |
107 // True if periodic dumping is enabled. | 115 // True if periodic dumping is enabled. |
108 bool IsPeriodicTimerRunningForTesting(); | 116 bool IsPeriodicTimerRunningForTesting(); |
109 | 117 |
110 MemoryDumpManager* mdm_; | 118 MemoryDumpManager* mdm_; |
111 | 119 |
112 PeriodicTriggerState periodic_state_; | 120 PeriodicTriggerState periodic_state_; |
113 PollingTriggerState polling_state_; | 121 PollingTriggerState polling_state_; |
114 | 122 |
115 DISALLOW_COPY_AND_ASSIGN(MemoryDumpScheduler); | 123 DISALLOW_COPY_AND_ASSIGN(MemoryDumpScheduler); |
116 }; | 124 }; |
117 | 125 |
118 } // namespace trace_event | 126 } // namespace trace_event |
119 } // namespace base | 127 } // namespace base |
120 | 128 |
121 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_SCHEDULER_H | 129 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_SCHEDULER_H |
OLD | NEW |