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

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

Issue 2582453002: [tracing] Implement polling in MemoryDumpManager (Closed)
Patch Set: nit. Created 3 years, 11 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_MANAGER_H_ 5 #ifndef BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_
6 #define BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ 6 #define BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <set> 12 #include <set>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/atomicops.h" 15 #include "base/atomicops.h"
16 #include "base/containers/hash_tables.h" 16 #include "base/containers/hash_tables.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/ref_counted.h" 18 #include "base/memory/ref_counted.h"
19 #include "base/memory/singleton.h" 19 #include "base/memory/singleton.h"
20 #include "base/synchronization/lock.h" 20 #include "base/synchronization/lock.h"
21 #include "base/timer/timer.h"
22 #include "base/trace_event/memory_dump_request_args.h" 21 #include "base/trace_event/memory_dump_request_args.h"
23 #include "base/trace_event/process_memory_dump.h" 22 #include "base/trace_event/process_memory_dump.h"
24 #include "base/trace_event/trace_event.h" 23 #include "base/trace_event/trace_event.h"
25 24
26 namespace base { 25 namespace base {
27 26
28 class SingleThreadTaskRunner; 27 class SingleThreadTaskRunner;
29 class Thread; 28 class Thread;
30 29
31 namespace trace_event { 30 namespace trace_event {
32 31
33 class MemoryDumpManagerDelegate; 32 class MemoryDumpManagerDelegate;
34 class MemoryDumpProvider; 33 class MemoryDumpProvider;
35 class MemoryDumpSessionState; 34 class MemoryDumpSessionState;
35 class MemoryDumpScheduler;
36 36
37 // This is the interface exposed to the rest of the codebase to deal with 37 // This is the interface exposed to the rest of the codebase to deal with
38 // memory tracing. The main entry point for clients is represented by 38 // memory tracing. The main entry point for clients is represented by
39 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider). 39 // RequestDumpPoint(). The extension by Un(RegisterDumpProvider).
40 class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver { 40 class BASE_EXPORT MemoryDumpManager : public TraceLog::EnabledStateObserver {
41 public: 41 public:
42 static const char* const kTraceCategory; 42 static const char* const kTraceCategory;
43 static const char* const kLogPrefix; 43 static const char* const kLogPrefix;
44 44
45 // This value is returned as the tracing id of the child processes by 45 // This value is returned as the tracing id of the child processes by
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 // When set to true, calling |RegisterMemoryDumpProvider| is a no-op. 145 // When set to true, calling |RegisterMemoryDumpProvider| is a no-op.
146 void set_dumper_registrations_ignored_for_testing(bool ignored) { 146 void set_dumper_registrations_ignored_for_testing(bool ignored) {
147 dumper_registrations_ignored_for_testing_ = ignored; 147 dumper_registrations_ignored_for_testing_ = ignored;
148 } 148 }
149 149
150 private: 150 private:
151 friend std::default_delete<MemoryDumpManager>; // For the testing instance. 151 friend std::default_delete<MemoryDumpManager>; // For the testing instance.
152 friend struct DefaultSingletonTraits<MemoryDumpManager>; 152 friend struct DefaultSingletonTraits<MemoryDumpManager>;
153 friend class MemoryDumpManagerDelegate; 153 friend class MemoryDumpManagerDelegate;
154 friend class MemoryDumpManagerTest; 154 friend class MemoryDumpManagerTest;
155 friend class MemoryDumpScheduler;
155 156
156 // Descriptor used to hold information about registered MDPs. 157 // Descriptor used to hold information about registered MDPs.
157 // Some important considerations about lifetime of this object: 158 // Some important considerations about lifetime of this object:
158 // - In nominal conditions, all the MemoryDumpProviderInfo instances live in 159 // - In nominal conditions, all the MemoryDumpProviderInfo instances live in
159 // the |dump_providers_| collection (% unregistration while dumping). 160 // the |dump_providers_| collection (% unregistration while dumping).
160 // - Upon each dump they (actually their scoped_refptr-s) are copied into 161 // - Upon each dump they (actually their scoped_refptr-s) are copied into
161 // the ProcessMemoryDumpAsyncState. This is to allow removal (see below). 162 // the ProcessMemoryDumpAsyncState. This is to allow removal (see below).
162 // - When the MDP.OnMemoryDump() is invoked, the corresponding MDPInfo copy 163 // - When the MDP.OnMemoryDump() is invoked, the corresponding MDPInfo copy
163 // inside ProcessMemoryDumpAsyncState is removed. 164 // inside ProcessMemoryDumpAsyncState is removed.
164 // - In most cases, the MDPInfo is destroyed within UnregisterDumpProvider(). 165 // - In most cases, the MDPInfo is destroyed within UnregisterDumpProvider().
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // This is essentially |dump_thread_|.task_runner() but needs to be kept 268 // This is essentially |dump_thread_|.task_runner() but needs to be kept
268 // as a separate variable as it needs to be accessed by arbitrary dumpers' 269 // as a separate variable as it needs to be accessed by arbitrary dumpers'
269 // threads outside of the lock_ to avoid races when disabling tracing. 270 // threads outside of the lock_ to avoid races when disabling tracing.
270 // It is immutable for all the duration of a tracing session. 271 // It is immutable for all the duration of a tracing session.
271 const scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner; 272 const scoped_refptr<SingleThreadTaskRunner> dump_thread_task_runner;
272 273
273 private: 274 private:
274 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDumpAsyncState); 275 DISALLOW_COPY_AND_ASSIGN(ProcessMemoryDumpAsyncState);
275 }; 276 };
276 277
277 // Sets up periodic memory dump timers to start global dump requests based on
278 // the dump triggers from trace config.
279 class BASE_EXPORT PeriodicGlobalDumpTimer {
280 public:
281 PeriodicGlobalDumpTimer();
282 ~PeriodicGlobalDumpTimer();
283
284 void Start(const std::vector<TraceConfig::MemoryDumpConfig::Trigger>&
285 triggers_list);
286 void Stop();
287
288 bool IsRunning();
289
290 private:
291 // Periodically called by the timer.
292 void RequestPeriodicGlobalDump();
293
294 RepeatingTimer timer_;
295 uint32_t periodic_dumps_count_;
296 uint32_t light_dump_rate_;
297 uint32_t heavy_dump_rate_;
298
299 DISALLOW_COPY_AND_ASSIGN(PeriodicGlobalDumpTimer);
300 };
301
302 static const int kMaxConsecutiveFailuresCount; 278 static const int kMaxConsecutiveFailuresCount;
303 static const char* const kSystemAllocatorPoolName; 279 static const char* const kSystemAllocatorPoolName;
304 280
305 MemoryDumpManager(); 281 MemoryDumpManager();
306 ~MemoryDumpManager() override; 282 ~MemoryDumpManager() override;
307 283
308 static void SetInstanceForTesting(MemoryDumpManager* instance); 284 static void SetInstanceForTesting(MemoryDumpManager* instance);
309 static void FinalizeDumpAndAddToTrace( 285 static void FinalizeDumpAndAddToTrace(
310 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state); 286 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state);
311 287
(...skipping 16 matching lines...) Expand all
328 // Invokes OnMemoryDump() of the next MDP and calls SetupNextMemoryDump() at 304 // Invokes OnMemoryDump() of the next MDP and calls SetupNextMemoryDump() at
329 // the end to continue the ProcessMemoryDump. Should be called on the MDP task 305 // the end to continue the ProcessMemoryDump. Should be called on the MDP task
330 // runner. 306 // runner.
331 void InvokeOnMemoryDump(ProcessMemoryDumpAsyncState* owned_pmd_async_state); 307 void InvokeOnMemoryDump(ProcessMemoryDumpAsyncState* owned_pmd_async_state);
332 308
333 // Records a quick total memory usage in |memory_total|. This is used to track 309 // Records a quick total memory usage in |memory_total|. This is used to track
334 // and detect peaks in the memory usage of the process without having to 310 // and detect peaks in the memory usage of the process without having to
335 // record all data from dump providers. This value is approximate to trade-off 311 // record all data from dump providers. This value is approximate to trade-off
336 // speed, and not consistent with the rest of the memory-infra metrics. Must 312 // speed, and not consistent with the rest of the memory-infra metrics. Must
337 // be called on the dump thread. 313 // be called on the dump thread.
338 void PollFastMemoryTotal(uint64_t* memory_total); 314 // Returns true if |memory_total| was updated by polling at least 1 MDP.
315 bool PollFastMemoryTotal(uint64_t* memory_total);
339 316
340 // Helper for RegierDumpProvider* functions. 317 // Helper for RegierDumpProvider* functions.
341 void RegisterDumpProviderInternal( 318 void RegisterDumpProviderInternal(
342 MemoryDumpProvider* mdp, 319 MemoryDumpProvider* mdp,
343 const char* name, 320 const char* name,
344 scoped_refptr<SequencedTaskRunner> task_runner, 321 scoped_refptr<SequencedTaskRunner> task_runner,
345 const MemoryDumpProvider::Options& options); 322 const MemoryDumpProvider::Options& options);
346 323
347 // Helper for the public UnregisterDumpProvider* functions. 324 // Helper for the public UnregisterDumpProvider* functions.
348 void UnregisterDumpProviderInternal(MemoryDumpProvider* mdp, 325 void UnregisterDumpProviderInternal(MemoryDumpProvider* mdp,
(...skipping 28 matching lines...) Expand all
377 bool is_coordinator_; 354 bool is_coordinator_;
378 355
379 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_| 356 // Protects from concurrent accesses to the |dump_providers_*| and |delegate_|
380 // to guard against disabling logging while dumping on another thread. 357 // to guard against disabling logging while dumping on another thread.
381 Lock lock_; 358 Lock lock_;
382 359
383 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty 360 // Optimization to avoid attempting any memory dump (i.e. to not walk an empty
384 // dump_providers_enabled_ list) when tracing is not enabled. 361 // dump_providers_enabled_ list) when tracing is not enabled.
385 subtle::AtomicWord memory_tracing_enabled_; 362 subtle::AtomicWord memory_tracing_enabled_;
386 363
387 // For time-triggered periodic dumps. 364 // For triggering memory dumps.
388 PeriodicGlobalDumpTimer periodic_dump_timer_; 365 std::unique_ptr<MemoryDumpScheduler> dump_scheduler_;
389 366
390 // Thread used for MemoryDumpProviders which don't specify a task runner 367 // Thread used for MemoryDumpProviders which don't specify a task runner
391 // affinity. 368 // affinity.
392 std::unique_ptr<Thread> dump_thread_; 369 std::unique_ptr<Thread> dump_thread_;
393 370
394 // The unique id of the child process. This is created only for tracing and is 371 // The unique id of the child process. This is created only for tracing and is
395 // expected to be valid only when tracing is enabled. 372 // expected to be valid only when tracing is enabled.
396 uint64_t tracing_process_id_; 373 uint64_t tracing_process_id_;
397 374
398 // When true, calling |RegisterMemoryDumpProvider| is a no-op. 375 // When true, calling |RegisterMemoryDumpProvider| is a no-op.
(...skipping 26 matching lines...) Expand all
425 } 402 }
426 403
427 private: 404 private:
428 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate); 405 DISALLOW_COPY_AND_ASSIGN(MemoryDumpManagerDelegate);
429 }; 406 };
430 407
431 } // namespace trace_event 408 } // namespace trace_event
432 } // namespace base 409 } // namespace base
433 410
434 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_ 411 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698