OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "gin/v8_isolate_memory_dump_provider.h" | |
6 | |
7 #include "base/message_loop/message_loop.h" | |
8 #include "base/strings/stringprintf.h" | |
9 #include "base/trace_event/memory_dump_manager.h" | |
10 #include "base/trace_event/process_memory_dump.h" | |
11 #include "gin/public/isolate_holder.h" | |
12 #include "v8/include/v8.h" | |
13 | |
14 namespace gin { | |
15 | |
16 namespace { | |
17 const char kDumperFriendlyName[] = "V8IsolateHeap"; | |
18 const char kRootDumpName[] = "v8"; | |
19 const char kIsolateDumpName[] = "isolate_%p/%s"; | |
20 const char kAvailableSizeAttribute[] = "available_size_in_bytes"; | |
21 } // namespace | |
22 | |
23 V8IsolateMemoryDumpProvider::V8IsolateMemoryDumpProvider( | |
24 IsolateHolder* isolate_holder) | |
25 : MemoryDumpProvider(base::MessageLoop::current()->task_runner()) { | |
rmcilroy
2015/04/21 21:57:26
I think you should be using base::ThreadTaskRunner
ssid
2015/04/22 10:41:35
Thanks, changed.
| |
26 DeclareAllocatorAttribute(kRootDumpName, kAvailableSizeAttribute, "bytes"); | |
27 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
28 this); | |
29 isolate_holder_ = isolate_holder; | |
rmcilroy
2015/04/21 21:57:25
nit - move this to the initializer list.
ssid
2015/04/22 10:41:35
Done.
| |
30 } | |
31 | |
32 V8IsolateMemoryDumpProvider::~V8IsolateMemoryDumpProvider() { | |
33 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | |
34 this); | |
35 } | |
36 | |
37 // Called at trace dump point time. Creates a snapshot with the memory counters | |
38 // for the current isolate. | |
39 bool V8IsolateMemoryDumpProvider::DumpInto( | |
40 base::trace_event::ProcessMemoryDump* pmd) { | |
41 v8::HeapStatistics heap_statistics; | |
42 isolate_holder_->isolate()->GetHeapStatistics(&heap_statistics); | |
43 | |
44 size_t known_spaces_used_size = 0; | |
45 size_t known_spaces_size = 0; | |
46 size_t number_of_spaces = isolate_holder_->isolate()->NumberOfHeapSpaces(); | |
47 for (size_t space = 0; space < number_of_spaces; space++) { | |
48 v8::HeapSpaceStatistics space_statistics; | |
49 isolate_holder_->isolate()->GetHeapSpaceStatistics(&space_statistics, | |
50 space); | |
51 size_t space_size = space_statistics.space_size(); | |
52 size_t space_used_size = space_statistics.space_used_size(); | |
53 | |
54 known_spaces_size += space_size; | |
55 known_spaces_used_size += space_used_size; | |
56 | |
57 std::string allocator_name = | |
58 base::StringPrintf(kIsolateDumpName, isolate_holder_->isolate(), | |
rmcilroy
2015/04/21 21:57:25
nit - I would prefer you just had the string liter
ssid
2015/04/22 10:41:35
This is kept as const at the top because each dump
| |
59 space_statistics.space_name()); | |
60 base::trace_event::MemoryAllocatorDump* space_dump = | |
61 pmd->CreateAllocatorDump(kRootDumpName, allocator_name.c_str()); | |
62 space_dump->set_physical_size_in_bytes(static_cast<int>((space_size))); | |
63 space_dump->set_allocated_objects_count(0); | |
rmcilroy
2015/04/21 21:57:26
Add a todo to add support for objects_count? It sh
ssid
2015/04/22 10:41:35
Done.
| |
64 space_dump->set_allocated_objects_size_in_bytes( | |
65 static_cast<int>(space_used_size)); | |
66 space_dump->SetAttribute( | |
67 kAvailableSizeAttribute, | |
68 static_cast<int>(space_statistics.space_available_size())); | |
69 } | |
70 | |
71 // Compute the rest of the memory, not accounted by the spaces above. | |
72 std::string allocator_name = base::StringPrintf( | |
73 kIsolateDumpName, isolate_holder_->isolate(), "other_spaces"); | |
74 base::trace_event::MemoryAllocatorDump* other_spaces_dump = | |
75 pmd->CreateAllocatorDump(kRootDumpName, allocator_name.c_str()); | |
76 other_spaces_dump->set_physical_size_in_bytes( | |
77 heap_statistics.total_heap_size() - known_spaces_size); | |
78 other_spaces_dump->set_allocated_objects_count(0); | |
79 other_spaces_dump->set_allocated_objects_size_in_bytes( | |
80 heap_statistics.used_heap_size() - known_spaces_used_size); | |
rmcilroy
2015/04/21 21:57:25
Should you also add kAvailableSizeAttribute as zer
ssid
2015/04/22 10:41:35
Done.
| |
81 | |
rmcilroy
2015/04/21 21:57:26
Primiano: I don't know how the hierarchy of alloca
| |
82 return true; | |
83 } | |
84 | |
85 const char* V8IsolateMemoryDumpProvider::GetFriendlyName() const { | |
86 return kDumperFriendlyName; | |
87 } | |
88 | |
89 } // namespace gin | |
OLD | NEW |