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

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: tweak a few comments 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"
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 // disabled (unregistered). This is to avoid taking lock while polling. 712 // disabled (unregistered). This is to avoid taking lock while polling.
713 for (const auto& mdpinfo : dump_providers_for_polling_) { 713 for (const auto& mdpinfo : dump_providers_for_polling_) {
714 uint64_t value = 0; 714 uint64_t value = 0;
715 mdpinfo->dump_provider->PollFastMemoryTotal(&value); 715 mdpinfo->dump_provider->PollFastMemoryTotal(&value);
716 *memory_total += value; 716 *memory_total += value;
717 } 717 }
718 return true; 718 return true;
719 } 719 }
720 720
721 // static 721 // static
722 uint32_t MemoryDumpManager::SumSizesInKbForPrefix(
723 const std::string& prefix,
724 const ProcessMemoryDump* pmd) {
725 uint64_t sum = 0;
726 for (const auto& kv : pmd->allocator_dumps()) {
727 if (kv.first.compare(0, prefix.length(), prefix) == 0) {
Primiano Tucci (use gerrit) 2017/03/22 17:19:52 as we discussed offline let's use StartsWith in st
hjd 2017/03/22 19:24:20 Done.
728 sum += kv.second->GetSize();
729 }
730 }
731 // Convert bytes to kilobytes.
Primiano Tucci (use gerrit) 2017/03/22 17:19:52 this comment should be unnecessary given the name
hjd 2017/03/22 19:24:20 Done.
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 // Fill results struct.
Primiano Tucci (use gerrit) 2017/03/22 17:19:52 ditto about todo + bug
hjd 2017/03/22 19:24:20 Done.
755 MemoryDumpCallbackResult result;
756 for (const auto& kv : pmd_async_state->process_dumps) {
Primiano Tucci (use gerrit) 2017/03/22 17:19:52 since you have the same loop below, could you make
hjd 2017/03/22 19:24:20 not really, just seemed easier while I was debuggi
757 ProcessMemoryDump* process_memory_dump = kv.second.get();
758 if (kv.first == kNullProcessId) {
759 result.chrome_dump.v8_total_kb =
760 SumSizesInKbForPrefix("v8/", process_memory_dump);
761 result.chrome_dump.malloc_total_kb =
762 SumSizesInKbForPrefix("malloc/", process_memory_dump);
Primiano Tucci (use gerrit) 2017/03/22 17:19:52 hmm I know that we discussed this offline but now
hjd 2017/03/22 19:24:20 Done.
763 // partition_alloc reports sizes for both allocated_objects and
764 // partitions. The memory allocated_objects uses is a subset of
765 // the partitions memory so to avoid double counting we only
766 // count partitions memory.
767 result.chrome_dump.partition_alloc_total_kb = SumSizesInKbForPrefix(
768 "partition_alloc/partitions", process_memory_dump);
769 result.chrome_dump.blink_gc_total_kb =
770 SumSizesInKbForPrefix("blink_gc/", process_memory_dump);
771 }
772 }
773
740 for (const auto& kv : pmd_async_state->process_dumps) { 774 for (const auto& kv : pmd_async_state->process_dumps) {
741 ProcessId pid = kv.first; // kNullProcessId for the current process. 775 ProcessId pid = kv.first; // kNullProcessId for the current process.
742 ProcessMemoryDump* process_memory_dump = kv.second.get(); 776 ProcessMemoryDump* process_memory_dump = kv.second.get();
743 std::unique_ptr<TracedValue> traced_value(new TracedValue); 777 std::unique_ptr<TracedValue> traced_value(new TracedValue);
744 process_memory_dump->AsValueInto(traced_value.get()); 778 process_memory_dump->AsValueInto(traced_value.get());
745 traced_value->SetString("level_of_detail", 779 traced_value->SetString("level_of_detail",
746 MemoryDumpLevelOfDetailToString( 780 MemoryDumpLevelOfDetailToString(
747 pmd_async_state->req_args.level_of_detail)); 781 pmd_async_state->req_args.level_of_detail));
748 const char* const event_name = 782 const char* const event_name =
749 MemoryDumpTypeToString(pmd_async_state->req_args.dump_type); 783 MemoryDumpTypeToString(pmd_async_state->req_args.dump_type);
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 if (iter == process_dumps.end()) { 995 if (iter == process_dumps.end()) {
962 std::unique_ptr<ProcessMemoryDump> new_pmd( 996 std::unique_ptr<ProcessMemoryDump> new_pmd(
963 new ProcessMemoryDump(session_state, dump_args)); 997 new ProcessMemoryDump(session_state, dump_args));
964 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; 998 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first;
965 } 999 }
966 return iter->second.get(); 1000 return iter->second.get();
967 } 1001 }
968 1002
969 } // namespace trace_event 1003 } // namespace trace_event
970 } // namespace base 1004 } // namespace base
OLDNEW
« base/trace_event/memory_dump_manager.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