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

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

Issue 2760253005: memory-infra: Fill the memory dump callback result (1/2) (Closed)
Patch Set: fill struct only in detailed mode Created 3 years, 9 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 #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/allocator/features.h" 10 #include "base/allocator/features.h"
11 #include "base/atomic_sequence_num.h" 11 #include "base/atomic_sequence_num.h"
12 #include "base/base_switches.h" 12 #include "base/base_switches.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/debug/alias.h" 15 #include "base/debug/alias.h"
16 #include "base/debug/debugging_flags.h" 16 #include "base/debug/debugging_flags.h"
17 #include "base/debug/stack_trace.h" 17 #include "base/debug/stack_trace.h"
18 #include "base/debug/thread_heap_usage_tracker.h" 18 #include "base/debug/thread_heap_usage_tracker.h"
19 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
20 #include "base/strings/pattern.h"
21 #include "base/strings/string_piece.h"
20 #include "base/threading/thread.h" 22 #include "base/threading/thread.h"
21 #include "base/threading/thread_task_runner_handle.h" 23 #include "base/threading/thread_task_runner_handle.h"
22 #include "base/trace_event/heap_profiler.h" 24 #include "base/trace_event/heap_profiler.h"
23 #include "base/trace_event/heap_profiler_allocation_context_tracker.h" 25 #include "base/trace_event/heap_profiler_allocation_context_tracker.h"
24 #include "base/trace_event/heap_profiler_event_filter.h" 26 #include "base/trace_event/heap_profiler_event_filter.h"
25 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" 27 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h"
26 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" 28 #include "base/trace_event/heap_profiler_type_name_deduplicator.h"
27 #include "base/trace_event/malloc_dump_provider.h" 29 #include "base/trace_event/malloc_dump_provider.h"
28 #include "base/trace_event/memory_dump_provider.h" 30 #include "base/trace_event/memory_dump_provider.h"
29 #include "base/trace_event/memory_dump_scheduler.h" 31 #include "base/trace_event/memory_dump_scheduler.h"
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 // disabled (unregistered). This is to avoid taking lock while polling. 714 // disabled (unregistered). This is to avoid taking lock while polling.
713 for (const auto& mdpinfo : dump_providers_for_polling_) { 715 for (const auto& mdpinfo : dump_providers_for_polling_) {
714 uint64_t value = 0; 716 uint64_t value = 0;
715 mdpinfo->dump_provider->PollFastMemoryTotal(&value); 717 mdpinfo->dump_provider->PollFastMemoryTotal(&value);
716 *memory_total += value; 718 *memory_total += value;
717 } 719 }
718 return true; 720 return true;
719 } 721 }
720 722
721 // static 723 // static
724 uint32_t MemoryDumpManager::GetDumpsSumKb(const std::string& pattern,
Primiano Tucci (use gerrit) 2017/03/24 11:41:27 ah, also just realized that this could be just a f
hjd 2017/03/24 11:57:17 as we realized offline it would make accessing Get
725 const ProcessMemoryDump* pmd) {
726 uint64_t sum = 0;
727 for (const auto& kv : pmd->allocator_dumps()) {
728 auto name = StringPiece(kv.first);
729 if (MatchPattern(name, pattern))
730 sum += kv.second->GetSize();
731 }
732 return sum / 1024;
733 }
734
735 // static
722 void MemoryDumpManager::FinalizeDumpAndAddToTrace( 736 void MemoryDumpManager::FinalizeDumpAndAddToTrace(
723 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state) { 737 std::unique_ptr<ProcessMemoryDumpAsyncState> pmd_async_state) {
724 HEAP_PROFILER_SCOPED_IGNORE; 738 HEAP_PROFILER_SCOPED_IGNORE;
725 DCHECK(pmd_async_state->pending_dump_providers.empty()); 739 DCHECK(pmd_async_state->pending_dump_providers.empty());
726 const uint64_t dump_guid = pmd_async_state->req_args.dump_guid; 740 const uint64_t dump_guid = pmd_async_state->req_args.dump_guid;
727 if (!pmd_async_state->callback_task_runner->BelongsToCurrentThread()) { 741 if (!pmd_async_state->callback_task_runner->BelongsToCurrentThread()) {
728 scoped_refptr<SingleThreadTaskRunner> callback_task_runner = 742 scoped_refptr<SingleThreadTaskRunner> callback_task_runner =
729 pmd_async_state->callback_task_runner; 743 pmd_async_state->callback_task_runner;
730 callback_task_runner->PostTask( 744 callback_task_runner->PostTask(
731 FROM_HERE, Bind(&MemoryDumpManager::FinalizeDumpAndAddToTrace, 745 FROM_HERE, Bind(&MemoryDumpManager::FinalizeDumpAndAddToTrace,
732 Passed(&pmd_async_state))); 746 Passed(&pmd_async_state)));
733 return; 747 return;
734 } 748 }
735 749
736 TRACE_EVENT_WITH_FLOW0(kTraceCategory, 750 TRACE_EVENT_WITH_FLOW0(kTraceCategory,
737 "MemoryDumpManager::FinalizeDumpAndAddToTrace", 751 "MemoryDumpManager::FinalizeDumpAndAddToTrace",
738 TRACE_ID_MANGLE(dump_guid), TRACE_EVENT_FLAG_FLOW_IN); 752 TRACE_ID_MANGLE(dump_guid), TRACE_EVENT_FLAG_FLOW_IN);
739 753
754 // The results struct to fill.
755 // TODO(hjd): Transitional until we send the full PMD. See crbug.com/704203
756 MemoryDumpCallbackResult result;
757
740 for (const auto& kv : pmd_async_state->process_dumps) { 758 for (const auto& kv : pmd_async_state->process_dumps) {
741 ProcessId pid = kv.first; // kNullProcessId for the current process. 759 ProcessId pid = kv.first; // kNullProcessId for the current process.
742 ProcessMemoryDump* process_memory_dump = kv.second.get(); 760 ProcessMemoryDump* process_memory_dump = kv.second.get();
743 std::unique_ptr<TracedValue> traced_value(new TracedValue); 761 std::unique_ptr<TracedValue> traced_value(new TracedValue);
744 process_memory_dump->AsValueInto(traced_value.get()); 762 process_memory_dump->AsValueInto(traced_value.get());
745 traced_value->SetString("level_of_detail", 763 traced_value->SetString("level_of_detail",
746 MemoryDumpLevelOfDetailToString( 764 MemoryDumpLevelOfDetailToString(
747 pmd_async_state->req_args.level_of_detail)); 765 pmd_async_state->req_args.level_of_detail));
748 const char* const event_name = 766 const char* const event_name =
749 MemoryDumpTypeToString(pmd_async_state->req_args.dump_type); 767 MemoryDumpTypeToString(pmd_async_state->req_args.dump_type);
750 768
751 std::unique_ptr<ConvertableToTraceFormat> event_value( 769 std::unique_ptr<ConvertableToTraceFormat> event_value(
752 std::move(traced_value)); 770 std::move(traced_value));
753 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_PROCESS_ID( 771 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_PROCESS_ID(
754 TRACE_EVENT_PHASE_MEMORY_DUMP, 772 TRACE_EVENT_PHASE_MEMORY_DUMP,
755 TraceLog::GetCategoryGroupEnabled(kTraceCategory), event_name, 773 TraceLog::GetCategoryGroupEnabled(kTraceCategory), event_name,
756 trace_event_internal::kGlobalScope, dump_guid, pid, 774 trace_event_internal::kGlobalScope, dump_guid, pid,
757 kTraceEventNumArgs, kTraceEventArgNames, 775 kTraceEventNumArgs, kTraceEventArgNames,
758 kTraceEventArgTypes, nullptr /* arg_values */, &event_value, 776 kTraceEventArgTypes, nullptr /* arg_values */, &event_value,
759 TRACE_EVENT_FLAG_HAS_ID); 777 TRACE_EVENT_FLAG_HAS_ID);
778
779 // TODO(hjd): Transitional until we send the full PMD. See crbug.com/704203
780 // Don't try to fill the struct in detailed mode since it is hard to avoid
781 // double counting.
782 if (pmd_async_state->req_args.level_of_detail ==
Primiano Tucci (use gerrit) 2017/03/24 11:39:22 since you have already an if below I'd just merge
hjd 2017/03/24 11:57:16 That if is about to a have another case in about a
783 MemoryDumpLevelOfDetail::DETAILED)
784 continue;
785
786 // TODO(hjd): Transitional until we send the full PMD. See crbug.com/704203
787 if (pid == kNullProcessId) {
788 result.chrome_dump.malloc_total_kb =
789 GetDumpsSumKb("malloc", process_memory_dump);
790 result.chrome_dump.v8_total_kb =
791 GetDumpsSumKb("v8/*", process_memory_dump);
792
793 // partition_alloc reports sizes for both allocated_objects and
794 // partitions. The memory allocated_objects uses is a subset of
795 // the partitions memory so to avoid double counting we only
796 // count partitions memory.
797 result.chrome_dump.partition_alloc_total_kb =
798 GetDumpsSumKb("partition_alloc/partitions/*", process_memory_dump);
799 result.chrome_dump.blink_gc_total_kb =
800 GetDumpsSumKb("blink_gc", process_memory_dump);
801 }
760 } 802 }
761 803
762 bool tracing_still_enabled; 804 bool tracing_still_enabled;
763 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &tracing_still_enabled); 805 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &tracing_still_enabled);
764 if (!tracing_still_enabled) { 806 if (!tracing_still_enabled) {
765 pmd_async_state->dump_successful = false; 807 pmd_async_state->dump_successful = false;
766 VLOG(1) << kLogPrefix << " failed because tracing was disabled before" 808 VLOG(1) << kLogPrefix << " failed because tracing was disabled before"
767 << " the dump was completed"; 809 << " the dump was completed";
768 } 810 }
769 811
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 if (iter == process_dumps.end()) { 1003 if (iter == process_dumps.end()) {
962 std::unique_ptr<ProcessMemoryDump> new_pmd( 1004 std::unique_ptr<ProcessMemoryDump> new_pmd(
963 new ProcessMemoryDump(session_state, dump_args)); 1005 new ProcessMemoryDump(session_state, dump_args));
964 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; 1006 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first;
965 } 1007 }
966 return iter->second.get(); 1008 return iter->second.get();
967 } 1009 }
968 1010
969 } // namespace trace_event 1011 } // namespace trace_event
970 } // namespace base 1012 } // namespace base
OLDNEW
« base/trace_event/memory_allocator_dump.h ('K') | « base/trace_event/memory_dump_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698