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 BASE_TRACE_EVENT_MEMORY_DUMP_SCHEDULER_H |
| 6 #define BASE_TRACE_EVENT_MEMORY_DUMP_SCHEDULER_H |
| 7 |
| 8 #include "base/base_export.h" |
| 9 #include "base/gtest_prod_util.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/timer/timer.h" |
| 12 #include "base/trace_event/memory_dump_request_args.h" |
| 13 |
| 14 namespace base { |
| 15 class SingleThreadTaskRunner; |
| 16 |
| 17 namespace trace_event { |
| 18 |
| 19 class MemoryDumpManager; |
| 20 |
| 21 // Schedules global dump requests based on the triggers added. |
| 22 class BASE_EXPORT MemoryDumpScheduler { |
| 23 public: |
| 24 MemoryDumpScheduler( |
| 25 MemoryDumpManager* mdm_, |
| 26 scoped_refptr<SingleThreadTaskRunner> polling_task_runner); |
| 27 ~MemoryDumpScheduler(); |
| 28 |
| 29 // Adds triggers for scheduling global dumps. Both periodic and peak triggers |
| 30 // cannot be added together. At the moment the periodic support is limited to |
| 31 // at most one periodic trigger per dump mode and peak triggers are limited to |
| 32 // at most one. All intervals should be an integeral multiple of the smallest |
| 33 // interval specified. |
| 34 void AddTrigger(MemoryDumpType trigger_type, |
| 35 MemoryDumpLevelOfDetail level_of_detail, |
| 36 uint32_t min_time_between_dumps_ms); |
| 37 |
| 38 // Starts periodic dumps. |
| 39 void NotifyPeriodicTriggerSupported(); |
| 40 |
| 41 // Starts polling memory total. |
| 42 void NotifyPollingSupported(); |
| 43 |
| 44 // Disables all triggers. |
| 45 void DisableAllTriggers(); |
| 46 |
| 47 private: |
| 48 friend class MemoryDumpManagerTest; |
| 49 FRIEND_TEST_ALL_PREFIXES(MemoryDumpManagerTest, TestPollingOnDumpThread); |
| 50 |
| 51 // Helper class to schdule periodic memory dumps. |
| 52 struct PeriodicTriggerState { |
| 53 PeriodicTriggerState(); |
| 54 ~PeriodicTriggerState(); |
| 55 |
| 56 bool is_configured; |
| 57 |
| 58 RepeatingTimer timer; |
| 59 uint32_t dump_count; |
| 60 uint32_t min_timer_period_ms; |
| 61 uint32_t light_dumps_rate; |
| 62 uint32_t heavy_dumps_rate; |
| 63 |
| 64 uint32_t light_dump_period_ms; |
| 65 uint32_t heavy_dump_period_ms; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(PeriodicTriggerState); |
| 68 }; |
| 69 |
| 70 struct PollingTriggerState { |
| 71 explicit PollingTriggerState( |
| 72 scoped_refptr<SingleThreadTaskRunner> polling_task_runner); |
| 73 ~PollingTriggerState(); |
| 74 |
| 75 bool is_configured; |
| 76 bool is_polling_enabled; |
| 77 MemoryDumpLevelOfDetail level_of_detail; |
| 78 |
| 79 scoped_refptr<SingleThreadTaskRunner> polling_task_runner; |
| 80 uint32_t polling_interval_ms; |
| 81 |
| 82 // Minimum numer of polls after the last dump at which next dump can be |
| 83 // triggered. |
| 84 int min_polls_between_dumps; |
| 85 int num_polls_from_last_dump; |
| 86 |
| 87 uint64_t last_dump_memory_total; |
| 88 |
| 89 DISALLOW_COPY_AND_ASSIGN(PollingTriggerState); |
| 90 }; |
| 91 |
| 92 // Helper to set polling disabled on the polling thread. |
| 93 void DisablePolling(); |
| 94 |
| 95 // Periodically called by the timer. |
| 96 void RequestPeriodicGlobalDump(); |
| 97 |
| 98 // Called for polling memory usage and trigger dumps if peak is detected. |
| 99 void PollMemoryOnPollingThread(); |
| 100 |
| 101 // Returns true if peak memory value is detected. |
| 102 bool ShouldTriggerDump(uint64_t current_memory_total); |
| 103 |
| 104 // Must be set before enabling tracing. |
| 105 static void SetPollingIntervalForTesting(uint32_t interval); |
| 106 |
| 107 // True if periodic dumping is enabled. |
| 108 bool IsPeriodicTimerRunningForTesting(); |
| 109 |
| 110 MemoryDumpManager* mdm_; |
| 111 |
| 112 PeriodicTriggerState periodic_state_; |
| 113 PollingTriggerState polling_state_; |
| 114 |
| 115 DISALLOW_COPY_AND_ASSIGN(MemoryDumpScheduler); |
| 116 }; |
| 117 |
| 118 } // namespace trace_event |
| 119 } // namespace base |
| 120 |
| 121 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_SCHEDULER_H |
OLD | NEW |