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 "gin/v8_isolate_memory_dump_provider.h" | 5 #include "gin/v8_isolate_memory_dump_provider.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "base/trace_event/memory_dump_manager.h" | 10 #include "base/trace_event/memory_dump_manager.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 return true; | 46 return true; |
47 } | 47 } |
48 | 48 |
49 void V8IsolateMemoryDumpProvider::DumpMemoryStatistics( | 49 void V8IsolateMemoryDumpProvider::DumpMemoryStatistics( |
50 base::trace_event::ProcessMemoryDump* pmd) { | 50 base::trace_event::ProcessMemoryDump* pmd) { |
51 v8::HeapStatistics heap_statistics; | 51 v8::HeapStatistics heap_statistics; |
52 isolate_holder_->isolate()->GetHeapStatistics(&heap_statistics); | 52 isolate_holder_->isolate()->GetHeapStatistics(&heap_statistics); |
53 | 53 |
54 size_t known_spaces_used_size = 0; | 54 size_t known_spaces_used_size = 0; |
55 size_t known_spaces_size = 0; | 55 size_t known_spaces_size = 0; |
56 size_t known_spaces_available_size = 0; | |
57 size_t number_of_spaces = isolate_holder_->isolate()->NumberOfHeapSpaces(); | 56 size_t number_of_spaces = isolate_holder_->isolate()->NumberOfHeapSpaces(); |
58 for (size_t space = 0; space < number_of_spaces; space++) { | 57 for (size_t space = 0; space < number_of_spaces; space++) { |
59 v8::HeapSpaceStatistics space_statistics; | 58 v8::HeapSpaceStatistics space_statistics; |
60 isolate_holder_->isolate()->GetHeapSpaceStatistics(&space_statistics, | 59 isolate_holder_->isolate()->GetHeapSpaceStatistics(&space_statistics, |
61 space); | 60 space); |
62 const size_t space_size = space_statistics.space_size(); | 61 const size_t space_size = space_statistics.space_size(); |
63 const size_t space_used_size = space_statistics.space_used_size(); | 62 const size_t space_used_size = space_statistics.space_used_size(); |
64 size_t space_available_size = space_statistics.space_available_size(); | |
65 | 63 |
66 known_spaces_size += space_size; | 64 known_spaces_size += space_size; |
67 known_spaces_used_size += space_used_size; | 65 known_spaces_used_size += space_used_size; |
68 known_spaces_available_size += space_available_size; | |
69 | 66 |
70 std::string allocator_name = | 67 std::string allocator_name = |
71 base::StringPrintf("%s/%s_%p/%s/%s", kRootDumpName, kIsolateDumpName, | 68 base::StringPrintf("%s/%s_%p/%s/%s", kRootDumpName, kIsolateDumpName, |
72 isolate_holder_->isolate(), kHeapSpacesDumpName, | 69 isolate_holder_->isolate(), kHeapSpacesDumpName, |
73 space_statistics.space_name()); | 70 space_statistics.space_name()); |
74 base::trace_event::MemoryAllocatorDump* space_dump = | 71 base::trace_event::MemoryAllocatorDump* space_dump = |
75 pmd->CreateAllocatorDump(allocator_name); | 72 pmd->CreateAllocatorDump(allocator_name); |
76 space_dump->AddScalar( | 73 space_dump->AddScalar( |
77 base::trace_event::MemoryAllocatorDump::kNameOuterSize, | 74 base::trace_event::MemoryAllocatorDump::kNameOuterSize, |
78 base::trace_event::MemoryAllocatorDump::kUnitsBytes, space_size); | 75 base::trace_event::MemoryAllocatorDump::kUnitsBytes, space_size); |
79 | 76 |
| 77 // TODO(ssid): Fix crbug.com/481504 to get the objects count of live objects |
| 78 // after the last GC. |
80 space_dump->AddScalar( | 79 space_dump->AddScalar( |
81 base::trace_event::MemoryAllocatorDump::kNameInnerSize, | 80 base::trace_event::MemoryAllocatorDump::kNameInnerSize, |
82 base::trace_event::MemoryAllocatorDump::kUnitsBytes, space_used_size); | 81 base::trace_event::MemoryAllocatorDump::kUnitsBytes, space_used_size); |
83 space_dump->AddScalar(kAvailableSizeAttribute, | 82 space_dump->AddScalar(kAvailableSizeAttribute, |
84 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 83 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
85 space_available_size); | 84 space_statistics.space_available_size()); |
86 } | 85 } |
87 // Compute the rest of the memory, not accounted by the spaces above. | 86 // Compute the rest of the memory, not accounted by the spaces above. |
88 std::string allocator_name = base::StringPrintf( | 87 std::string allocator_name = base::StringPrintf( |
89 "%s/%s_%p/%s/%s", kRootDumpName, kIsolateDumpName, | 88 "%s/%s_%p/%s/%s", kRootDumpName, kIsolateDumpName, |
90 isolate_holder_->isolate(), kHeapSpacesDumpName, "other_spaces"); | 89 isolate_holder_->isolate(), kHeapSpacesDumpName, "other_spaces"); |
91 base::trace_event::MemoryAllocatorDump* other_spaces_dump = | 90 base::trace_event::MemoryAllocatorDump* other_spaces_dump = |
92 pmd->CreateAllocatorDump(allocator_name); | 91 pmd->CreateAllocatorDump(allocator_name); |
93 other_spaces_dump->AddScalar( | 92 other_spaces_dump->AddScalar( |
94 base::trace_event::MemoryAllocatorDump::kNameOuterSize, | 93 base::trace_event::MemoryAllocatorDump::kNameOuterSize, |
95 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 94 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
96 heap_statistics.total_heap_size() - known_spaces_size); | 95 heap_statistics.total_heap_size() - known_spaces_size); |
97 other_spaces_dump->AddScalar( | 96 other_spaces_dump->AddScalar( |
98 base::trace_event::MemoryAllocatorDump::kNameInnerSize, | 97 base::trace_event::MemoryAllocatorDump::kNameInnerSize, |
99 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 98 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
100 heap_statistics.used_heap_size() - known_spaces_used_size); | 99 heap_statistics.used_heap_size() - known_spaces_used_size); |
101 | 100 |
102 // TODO(ssid): Fix crbug.com/481504 to get the total available size of the | 101 // TODO(ssid): Fix crbug.com/481504 to get the total available size of the |
103 // heap. | 102 // heap. |
104 other_spaces_dump->AddScalar( | 103 other_spaces_dump->AddScalar( |
105 kAvailableSizeAttribute, | 104 kAvailableSizeAttribute, |
106 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 105 base::trace_event::MemoryAllocatorDump::kUnitsBytes, 0); |
107 heap_statistics.total_available_size() - known_spaces_available_size); | |
108 } | 106 } |
109 | 107 |
110 } // namespace gin | 108 } // namespace gin |
OLD | NEW |