Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(558)

Side by Side Diff: base/trace_event/memory_dump_scheduler.h

Issue 2582453002: [tracing] Implement polling in MemoryDumpManager (Closed)
Patch Set: Nit. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 class PeriodicDumpScheduler {
53 public:
54 explicit PeriodicDumpScheduler(MemoryDumpManager* mdm);
55 ~PeriodicDumpScheduler();
56
57 // Adds periodic dump time periods.
58 void AddTrigger(MemoryDumpLevelOfDetail level_of_detail,
59 uint32_t min_time_between_dumps_ms);
60
61 // Starts periodic timer on notification.
62 void NotifySupported();
63
64 // Disables periodic timer.
65 void Disable();
66
67 bool IsTimerRunning() { return timer_.IsRunning(); }
68
69 // Periodically called by the timer.
70 void RequestPeriodicGlobalDump();
71
72 // True if periodic scheduler is enabled in this session.
73 bool is_setup() const { return is_setup_; }
Primiano Tucci (use gerrit) 2017/02/03 20:08:20 s/is_setup/has_triggers/ ? or (is_configured, to k
ssid 2017/02/14 02:05:40 Done.
74
75 private:
76 MemoryDumpManager* mdm_;
77
78 bool is_setup_;
79
80 // Timer for periodic dumps.
81 RepeatingTimer timer_;
82 uint32_t dump_count_;
83 uint32_t min_timer_period_ms_;
84 uint32_t light_dumps_rate_;
85 uint32_t heavy_dumps_rate_;
86
87 uint32_t light_dump_period_ms = 0;
Primiano Tucci (use gerrit) 2017/02/03 20:08:20 why these 2 are initialized here, but not the othe
ssid 2017/02/14 02:05:40 Sorry this was mistake.
88 uint32_t heavy_dump_period_ms = 0;
89
90 DISALLOW_COPY_AND_ASSIGN(PeriodicDumpScheduler);
91 };
92
93 class PeakDumpScheduler {
Primiano Tucci (use gerrit) 2017/02/03 20:08:20 honestly I am not fully sold you need two classes
ssid 2017/02/14 02:05:40 yes I agree this should be the case. I did aim for
94 public:
95 PeakDumpScheduler(
96 MemoryDumpManager* mdm,
97 scoped_refptr<SingleThreadTaskRunner> polling_task_runner);
98 ~PeakDumpScheduler();
99
100 // Sets up peak dump triggers for global memory dumps according to
101 // the trigger.
102 void AddTrigger(MemoryDumpLevelOfDetail level_of_detail,
103 uint32_t min_time_between_dumps_ms);
104
105 // Called for polling memory usage and trigger dumps if peak is detected.
106 void PollMemoryOnPollingThread();
107
108 // Starts polling for peak detection.
109 void NotifySupported();
110
111 // Disables polling for peak detection.
112 void Disable();
113
114 // True if peak dumps scheduler is enabled in this session.
115 bool is_setup() const { return is_setup_; }
116
117 private:
118 // Returns true if peak memory value is detected.
119 bool ShouldTriggerDump(uint64_t current_memory_total);
120
121 MemoryDumpManager* mdm_;
122
123 bool is_setup_;
124 MemoryDumpLevelOfDetail dump_mode_;
125
126 scoped_refptr<SingleThreadTaskRunner> polling_task_runner_;
127 uint32_t polling_interval_ = 0;
128
129 int min_polls_between_dumps_ = 0;
130 int num_polls_from_last_dump_ = 0;
131
132 // Threshold on increase in memory from last dump beyond which a new dump
133 // must be triggered.
134 int64_t memory_increase_threshold_ = 50 * 1024 * 1024; // 50MiB
135 uint64_t last_dump_memory_total_ = 0;
136
137 DISALLOW_COPY_AND_ASSIGN(PeakDumpScheduler);
138 };
139
140 // Must be set before enabling tracing.
141 static void SetPollingIntervalForTesting(uint32_t interval);
142
143 bool IsPeriodicTimerRunningForTesting();
144
145 MemoryDumpManager* mdm_;
146
147 PeriodicDumpScheduler periodic_dump_scheduler_;
148 PeakDumpScheduler peak_dump_scheduler_;
149
150 DISALLOW_COPY_AND_ASSIGN(MemoryDumpScheduler);
151 };
152
153 } // namespace trace_event
154 } // namespace base
155
156 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_SCHEDULER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698