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 <inttypes.h> | 7 #include <inttypes.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 callback_task_runner->PostTask( | 735 callback_task_runner->PostTask( |
736 FROM_HERE, BindOnce(&MemoryDumpManager::FinalizeDumpAndAddToTrace, | 736 FROM_HERE, BindOnce(&MemoryDumpManager::FinalizeDumpAndAddToTrace, |
737 Passed(&pmd_async_state))); | 737 Passed(&pmd_async_state))); |
738 return; | 738 return; |
739 } | 739 } |
740 | 740 |
741 TRACE_EVENT0(kTraceCategory, "MemoryDumpManager::FinalizeDumpAndAddToTrace"); | 741 TRACE_EVENT0(kTraceCategory, "MemoryDumpManager::FinalizeDumpAndAddToTrace"); |
742 | 742 |
743 // The results struct to fill. | 743 // The results struct to fill. |
744 // TODO(hjd): Transitional until we send the full PMD. See crbug.com/704203 | 744 // TODO(hjd): Transitional until we send the full PMD. See crbug.com/704203 |
745 base::Optional<MemoryDumpCallbackResult> result_opt; | 745 base::Optional<MemoryDumpCallbackResult> result; |
746 | |
747 for (const auto& kv : pmd_async_state->process_dumps) { | 746 for (const auto& kv : pmd_async_state->process_dumps) { |
748 ProcessId pid = kv.first; // kNullProcessId for the current process. | 747 ProcessId pid = kv.first; // kNullProcessId for the current process. |
749 ProcessMemoryDump* process_memory_dump = kv.second.get(); | 748 ProcessMemoryDump* process_memory_dump = kv.second.get(); |
750 std::unique_ptr<TracedValue> traced_value(new TracedValue); | 749 std::unique_ptr<TracedValue> traced_value(new TracedValue); |
751 process_memory_dump->AsValueInto(traced_value.get()); | 750 process_memory_dump->AsValueInto(traced_value.get()); |
752 traced_value->SetString("level_of_detail", | 751 traced_value->SetString("level_of_detail", |
753 MemoryDumpLevelOfDetailToString( | 752 MemoryDumpLevelOfDetailToString( |
754 pmd_async_state->req_args.level_of_detail)); | 753 pmd_async_state->req_args.level_of_detail)); |
755 const char* const event_name = | 754 const char* const event_name = |
756 MemoryDumpTypeToString(pmd_async_state->req_args.dump_type); | 755 MemoryDumpTypeToString(pmd_async_state->req_args.dump_type); |
757 | 756 |
758 std::unique_ptr<ConvertableToTraceFormat> event_value( | 757 std::unique_ptr<ConvertableToTraceFormat> event_value( |
759 std::move(traced_value)); | 758 std::move(traced_value)); |
760 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_PROCESS_ID( | 759 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_PROCESS_ID( |
761 TRACE_EVENT_PHASE_MEMORY_DUMP, | 760 TRACE_EVENT_PHASE_MEMORY_DUMP, |
762 TraceLog::GetCategoryGroupEnabled(kTraceCategory), event_name, | 761 TraceLog::GetCategoryGroupEnabled(kTraceCategory), event_name, |
763 trace_event_internal::kGlobalScope, dump_guid, pid, | 762 trace_event_internal::kGlobalScope, dump_guid, pid, |
764 kTraceEventNumArgs, kTraceEventArgNames, | 763 kTraceEventNumArgs, kTraceEventArgNames, |
765 kTraceEventArgTypes, nullptr /* arg_values */, &event_value, | 764 kTraceEventArgTypes, nullptr /* arg_values */, &event_value, |
766 TRACE_EVENT_FLAG_HAS_ID); | 765 TRACE_EVENT_FLAG_HAS_ID); |
767 | 766 |
768 // TODO(hjd): Transitional until we send the full PMD. See crbug.com/704203 | 767 // TODO(hjd): Transitional until we send the full PMD. See crbug.com/704203 |
769 // Don't try to fill the struct in detailed mode since it is hard to avoid | 768 // Don't try to fill the struct in detailed mode since it is hard to avoid |
770 // double counting. | 769 // double counting. |
771 if (pmd_async_state->req_args.level_of_detail == | 770 if (pmd_async_state->req_args.level_of_detail == |
772 MemoryDumpLevelOfDetail::DETAILED) | 771 MemoryDumpLevelOfDetail::DETAILED) |
773 continue; | 772 continue; |
774 MemoryDumpCallbackResult result; | 773 if (!result.has_value()) |
| 774 result = MemoryDumpCallbackResult(); |
775 // TODO(hjd): Transitional until we send the full PMD. See crbug.com/704203 | 775 // TODO(hjd): Transitional until we send the full PMD. See crbug.com/704203 |
776 if (pid == kNullProcessId) { | 776 if (pid == kNullProcessId) { |
777 result.chrome_dump.malloc_total_kb = | 777 result->chrome_dump.malloc_total_kb = |
778 GetDumpsSumKb("malloc", process_memory_dump); | 778 GetDumpsSumKb("malloc", process_memory_dump); |
779 result.chrome_dump.v8_total_kb = | 779 result->chrome_dump.v8_total_kb = |
780 GetDumpsSumKb("v8/*", process_memory_dump); | 780 GetDumpsSumKb("v8/*", process_memory_dump); |
781 | 781 |
782 // partition_alloc reports sizes for both allocated_objects and | 782 // partition_alloc reports sizes for both allocated_objects and |
783 // partitions. The memory allocated_objects uses is a subset of | 783 // partitions. The memory allocated_objects uses is a subset of |
784 // the partitions memory so to avoid double counting we only | 784 // the partitions memory so to avoid double counting we only |
785 // count partitions memory. | 785 // count partitions memory. |
786 result.chrome_dump.partition_alloc_total_kb = | 786 result->chrome_dump.partition_alloc_total_kb = |
787 GetDumpsSumKb("partition_alloc/partitions/*", process_memory_dump); | 787 GetDumpsSumKb("partition_alloc/partitions/*", process_memory_dump); |
788 result.chrome_dump.blink_gc_total_kb = | 788 result->chrome_dump.blink_gc_total_kb = |
789 GetDumpsSumKb("blink_gc", process_memory_dump); | 789 GetDumpsSumKb("blink_gc", process_memory_dump); |
790 FillOsDumpFromProcessMemoryDump(process_memory_dump, &result.os_dump); | 790 FillOsDumpFromProcessMemoryDump(process_memory_dump, &result->os_dump); |
791 } else { | 791 } else { |
792 auto& os_dump = result.extra_processes_dump[pid]; | 792 auto& os_dump = result->extra_processes_dump[pid]; |
793 FillOsDumpFromProcessMemoryDump(process_memory_dump, &os_dump); | 793 FillOsDumpFromProcessMemoryDump(process_memory_dump, &os_dump); |
794 } | 794 } |
795 result_opt = result; | |
796 } | 795 } |
797 | 796 |
798 bool tracing_still_enabled; | 797 bool tracing_still_enabled; |
799 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &tracing_still_enabled); | 798 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &tracing_still_enabled); |
800 if (!tracing_still_enabled) { | 799 if (!tracing_still_enabled) { |
801 pmd_async_state->dump_successful = false; | 800 pmd_async_state->dump_successful = false; |
802 VLOG(1) << kLogPrefix << " failed because tracing was disabled before" | 801 VLOG(1) << kLogPrefix << " failed because tracing was disabled before" |
803 << " the dump was completed"; | 802 << " the dump was completed"; |
804 } | 803 } |
805 | 804 |
806 if (!pmd_async_state->callback.is_null()) { | 805 if (!pmd_async_state->callback.is_null()) { |
807 pmd_async_state->callback.Run(dump_guid, pmd_async_state->dump_successful, | 806 pmd_async_state->callback.Run(dump_guid, pmd_async_state->dump_successful, |
808 result_opt); | 807 result); |
809 pmd_async_state->callback.Reset(); | 808 pmd_async_state->callback.Reset(); |
810 } | 809 } |
811 | 810 |
812 TRACE_EVENT_NESTABLE_ASYNC_END0(kTraceCategory, "ProcessMemoryDump", | 811 TRACE_EVENT_NESTABLE_ASYNC_END0(kTraceCategory, "ProcessMemoryDump", |
813 TRACE_ID_LOCAL(dump_guid)); | 812 TRACE_ID_LOCAL(dump_guid)); |
814 } | 813 } |
815 | 814 |
816 void MemoryDumpManager::OnTraceLogEnabled() { | 815 void MemoryDumpManager::OnTraceLogEnabled() { |
817 bool enabled; | 816 bool enabled; |
818 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &enabled); | 817 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &enabled); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 if (iter == process_dumps.end()) { | 973 if (iter == process_dumps.end()) { |
975 std::unique_ptr<ProcessMemoryDump> new_pmd( | 974 std::unique_ptr<ProcessMemoryDump> new_pmd( |
976 new ProcessMemoryDump(session_state, dump_args)); | 975 new ProcessMemoryDump(session_state, dump_args)); |
977 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; | 976 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; |
978 } | 977 } |
979 return iter->second.get(); | 978 return iter->second.get(); |
980 } | 979 } |
981 | 980 |
982 } // namespace trace_event | 981 } // namespace trace_event |
983 } // namespace base | 982 } // namespace base |
OLD | NEW |