| OLD | NEW | 
|---|
| 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 #include "base/trace_event/memory_dump_manager.h" | 5 #include "base/trace_event/memory_dump_manager.h" | 
| 6 | 6 | 
| 7 #include <algorithm> | 7 #include <algorithm> | 
| 8 #include <utility> | 8 #include <utility> | 
| 9 | 9 | 
| 10 #include "base/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" | 
| 11 #include "base/base_switches.h" | 11 #include "base/base_switches.h" | 
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" | 
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" | 
| 14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" | 
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" | 
| 16 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | 16 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" | 
| 17 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" | 17 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" | 
|  | 18 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" | 
| 18 #include "base/trace_event/malloc_dump_provider.h" | 19 #include "base/trace_event/malloc_dump_provider.h" | 
| 19 #include "base/trace_event/memory_dump_provider.h" | 20 #include "base/trace_event/memory_dump_provider.h" | 
| 20 #include "base/trace_event/memory_dump_session_state.h" | 21 #include "base/trace_event/memory_dump_session_state.h" | 
| 21 #include "base/trace_event/process_memory_dump.h" | 22 #include "base/trace_event/process_memory_dump.h" | 
| 22 #include "base/trace_event/trace_event_argument.h" | 23 #include "base/trace_event/trace_event_argument.h" | 
| 23 #include "build/build_config.h" | 24 #include "build/build_config.h" | 
| 24 | 25 | 
| 25 #if !defined(OS_NACL) | 26 #if !defined(OS_NACL) | 
| 26 #include "base/trace_event/process_memory_totals_dump_provider.h" | 27 #include "base/trace_event/process_memory_totals_dump_provider.h" | 
| 27 #endif | 28 #endif | 
| (...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 512   if (!dump_thread->Start()) { | 513   if (!dump_thread->Start()) { | 
| 513     LOG(ERROR) << "Failed to start the memory-infra thread for tracing"; | 514     LOG(ERROR) << "Failed to start the memory-infra thread for tracing"; | 
| 514     return; | 515     return; | 
| 515   } | 516   } | 
| 516 | 517 | 
| 517   AutoLock lock(lock_); | 518   AutoLock lock(lock_); | 
| 518 | 519 | 
| 519   DCHECK(delegate_);  // At this point we must have a delegate. | 520   DCHECK(delegate_);  // At this point we must have a delegate. | 
| 520 | 521 | 
| 521   scoped_refptr<StackFrameDeduplicator> stack_frame_deduplicator = nullptr; | 522   scoped_refptr<StackFrameDeduplicator> stack_frame_deduplicator = nullptr; | 
|  | 523   scoped_refptr<TypeNameDeduplicator> type_name_deduplicator = nullptr; | 
| 522 | 524 | 
| 523   if (heap_profiling_enabled_) { | 525   if (heap_profiling_enabled_) { | 
| 524     // If heap profiling is enabled, the stack frame deduplicator will be in | 526     // If heap profiling is enabled, the stack frame deduplicator and type name | 
| 525     // use. Add a metadata event to write its frames. | 527     // deduplicator will be in use. Add a metadata events to write the frames | 
|  | 528     // and type IDs. | 
| 526     stack_frame_deduplicator = new StackFrameDeduplicator; | 529     stack_frame_deduplicator = new StackFrameDeduplicator; | 
|  | 530     type_name_deduplicator = new TypeNameDeduplicator; | 
| 527     TRACE_EVENT_API_ADD_METADATA_EVENT( | 531     TRACE_EVENT_API_ADD_METADATA_EVENT( | 
| 528         "stackFrames", "stackFrames", | 532         "stackFrames", "stackFrames", | 
| 529         scoped_refptr<ConvertableToTraceFormat>(stack_frame_deduplicator)); | 533         scoped_refptr<ConvertableToTraceFormat>(stack_frame_deduplicator)); | 
|  | 534     TRACE_EVENT_API_ADD_METADATA_EVENT( | 
|  | 535         "typeNames", "typeNames", | 
|  | 536         scoped_refptr<ConvertableToTraceFormat>(type_name_deduplicator)); | 
| 530   } | 537   } | 
| 531 | 538 | 
| 532   DCHECK(!dump_thread_); | 539   DCHECK(!dump_thread_); | 
| 533   dump_thread_ = std::move(dump_thread); | 540   dump_thread_ = std::move(dump_thread); | 
| 534   session_state_ = new MemoryDumpSessionState(stack_frame_deduplicator); | 541   session_state_ = new MemoryDumpSessionState(stack_frame_deduplicator, | 
|  | 542                                               type_name_deduplicator); | 
| 535 | 543 | 
| 536   for (auto it = dump_providers_.begin(); it != dump_providers_.end(); ++it) { | 544   for (auto it = dump_providers_.begin(); it != dump_providers_.end(); ++it) { | 
| 537     it->disabled = false; | 545     it->disabled = false; | 
| 538     it->consecutive_failures = 0; | 546     it->consecutive_failures = 0; | 
| 539   } | 547   } | 
| 540 | 548 | 
| 541   subtle::NoBarrier_Store(&memory_tracing_enabled_, 1); | 549   subtle::NoBarrier_Store(&memory_tracing_enabled_, 1); | 
| 542 | 550 | 
| 543   // TODO(primiano): This is a temporary hack to disable periodic memory dumps | 551   // TODO(primiano): This is a temporary hack to disable periodic memory dumps | 
| 544   // when running memory benchmarks until telemetry uses TraceConfig to | 552   // when running memory benchmarks until telemetry uses TraceConfig to | 
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 646   auto iter = process_dumps.find(pid); | 654   auto iter = process_dumps.find(pid); | 
| 647   if (iter == process_dumps.end()) { | 655   if (iter == process_dumps.end()) { | 
| 648     scoped_ptr<ProcessMemoryDump> new_pmd(new ProcessMemoryDump(session_state)); | 656     scoped_ptr<ProcessMemoryDump> new_pmd(new ProcessMemoryDump(session_state)); | 
| 649     iter = process_dumps.insert(pid, std::move(new_pmd)).first; | 657     iter = process_dumps.insert(pid, std::move(new_pmd)).first; | 
| 650   } | 658   } | 
| 651   return iter->second; | 659   return iter->second; | 
| 652 } | 660 } | 
| 653 | 661 | 
| 654 }  // namespace trace_event | 662 }  // namespace trace_event | 
| 655 }  // namespace base | 663 }  // namespace base | 
| OLD | NEW | 
|---|