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; | 745 base::Optional<MemoryDumpCallbackResult> result_opt; |
| 746 |
746 for (const auto& kv : pmd_async_state->process_dumps) { | 747 for (const auto& kv : pmd_async_state->process_dumps) { |
747 ProcessId pid = kv.first; // kNullProcessId for the current process. | 748 ProcessId pid = kv.first; // kNullProcessId for the current process. |
748 ProcessMemoryDump* process_memory_dump = kv.second.get(); | 749 ProcessMemoryDump* process_memory_dump = kv.second.get(); |
749 std::unique_ptr<TracedValue> traced_value(new TracedValue); | 750 std::unique_ptr<TracedValue> traced_value(new TracedValue); |
750 process_memory_dump->AsValueInto(traced_value.get()); | 751 process_memory_dump->AsValueInto(traced_value.get()); |
751 traced_value->SetString("level_of_detail", | 752 traced_value->SetString("level_of_detail", |
752 MemoryDumpLevelOfDetailToString( | 753 MemoryDumpLevelOfDetailToString( |
753 pmd_async_state->req_args.level_of_detail)); | 754 pmd_async_state->req_args.level_of_detail)); |
754 const char* const event_name = | 755 const char* const event_name = |
755 MemoryDumpTypeToString(pmd_async_state->req_args.dump_type); | 756 MemoryDumpTypeToString(pmd_async_state->req_args.dump_type); |
756 | 757 |
757 std::unique_ptr<ConvertableToTraceFormat> event_value( | 758 std::unique_ptr<ConvertableToTraceFormat> event_value( |
758 std::move(traced_value)); | 759 std::move(traced_value)); |
759 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_PROCESS_ID( | 760 TRACE_EVENT_API_ADD_TRACE_EVENT_WITH_PROCESS_ID( |
760 TRACE_EVENT_PHASE_MEMORY_DUMP, | 761 TRACE_EVENT_PHASE_MEMORY_DUMP, |
761 TraceLog::GetCategoryGroupEnabled(kTraceCategory), event_name, | 762 TraceLog::GetCategoryGroupEnabled(kTraceCategory), event_name, |
762 trace_event_internal::kGlobalScope, dump_guid, pid, | 763 trace_event_internal::kGlobalScope, dump_guid, pid, |
763 kTraceEventNumArgs, kTraceEventArgNames, | 764 kTraceEventNumArgs, kTraceEventArgNames, |
764 kTraceEventArgTypes, nullptr /* arg_values */, &event_value, | 765 kTraceEventArgTypes, nullptr /* arg_values */, &event_value, |
765 TRACE_EVENT_FLAG_HAS_ID); | 766 TRACE_EVENT_FLAG_HAS_ID); |
766 | 767 |
767 // TODO(hjd): Transitional until we send the full PMD. See crbug.com/704203 | 768 // TODO(hjd): Transitional until we send the full PMD. See crbug.com/704203 |
768 // Don't try to fill the struct in detailed mode since it is hard to avoid | 769 // Don't try to fill the struct in detailed mode since it is hard to avoid |
769 // double counting. | 770 // double counting. |
770 if (pmd_async_state->req_args.level_of_detail == | 771 if (pmd_async_state->req_args.level_of_detail == |
771 MemoryDumpLevelOfDetail::DETAILED) | 772 MemoryDumpLevelOfDetail::DETAILED) |
772 continue; | 773 continue; |
773 if (!result.has_value()) | 774 MemoryDumpCallbackResult result; |
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; |
795 } | 796 } |
796 | 797 |
797 bool tracing_still_enabled; | 798 bool tracing_still_enabled; |
798 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &tracing_still_enabled); | 799 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &tracing_still_enabled); |
799 if (!tracing_still_enabled) { | 800 if (!tracing_still_enabled) { |
800 pmd_async_state->dump_successful = false; | 801 pmd_async_state->dump_successful = false; |
801 VLOG(1) << kLogPrefix << " failed because tracing was disabled before" | 802 VLOG(1) << kLogPrefix << " failed because tracing was disabled before" |
802 << " the dump was completed"; | 803 << " the dump was completed"; |
803 } | 804 } |
804 | 805 |
805 if (!pmd_async_state->callback.is_null()) { | 806 if (!pmd_async_state->callback.is_null()) { |
806 pmd_async_state->callback.Run(dump_guid, pmd_async_state->dump_successful, | 807 pmd_async_state->callback.Run(dump_guid, pmd_async_state->dump_successful, |
807 result); | 808 result_opt); |
808 pmd_async_state->callback.Reset(); | 809 pmd_async_state->callback.Reset(); |
809 } | 810 } |
810 | 811 |
811 TRACE_EVENT_NESTABLE_ASYNC_END0(kTraceCategory, "ProcessMemoryDump", | 812 TRACE_EVENT_NESTABLE_ASYNC_END0(kTraceCategory, "ProcessMemoryDump", |
812 TRACE_ID_LOCAL(dump_guid)); | 813 TRACE_ID_LOCAL(dump_guid)); |
813 } | 814 } |
814 | 815 |
815 void MemoryDumpManager::OnTraceLogEnabled() { | 816 void MemoryDumpManager::OnTraceLogEnabled() { |
816 bool enabled; | 817 bool enabled; |
817 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &enabled); | 818 TRACE_EVENT_CATEGORY_GROUP_ENABLED(kTraceCategory, &enabled); |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 if (iter == process_dumps.end()) { | 974 if (iter == process_dumps.end()) { |
974 std::unique_ptr<ProcessMemoryDump> new_pmd( | 975 std::unique_ptr<ProcessMemoryDump> new_pmd( |
975 new ProcessMemoryDump(session_state, dump_args)); | 976 new ProcessMemoryDump(session_state, dump_args)); |
976 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; | 977 iter = process_dumps.insert(std::make_pair(pid, std::move(new_pmd))).first; |
977 } | 978 } |
978 return iter->second.get(); | 979 return iter->second.get(); |
979 } | 980 } |
980 | 981 |
981 } // namespace trace_event | 982 } // namespace trace_event |
982 } // namespace base | 983 } // namespace base |
OLD | NEW |