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/threading/platform_thread.h" | |
8 #include "base/trace_event/process_memory_dump.h" | |
9 #include "gin/public/isolate_holder.h" | |
10 #include "v8/include/v8.h" | |
11 | |
12 namespace gin { | |
13 | |
14 namespace { | |
15 | |
Primiano Tucci (use gerrit)
2015/04/17 19:10:31
don't need this extra \n
| |
16 const char kDumperFriendlyName[] = "V8IsolateHeap"; | |
17 const char kDumperRootName[] = "v8_root"; | |
Primiano Tucci (use gerrit)
2015/04/17 19:10:30
kRootDumpName
Primiano Tucci (use gerrit)
2015/04/17 19:10:31
This should be just v8
| |
18 const char kDumperName[] = "v8_isolate"; | |
Primiano Tucci (use gerrit)
2015/04/17 19:10:31
THis should be kIsolateDumpName
| |
19 const char kDumperOtherSpaces[] = "other_spaces"; | |
Primiano Tucci (use gerrit)
2015/04/17 19:10:31
THis you can just put the string inline as you use
| |
20 const char kAvailableSizeAttribute[] = "available_size_in_bytes"; | |
21 const char kPhysicalSizeAttribute[] = "physical_size_in_bytes"; | |
22 } // namespace | |
23 | |
24 V8IsolateMemoryDumpProvider::V8IsolateMemoryDumpProvider( | |
25 IsolateHolder* isolate_holder) { | |
Primiano Tucci (use gerrit)
2015/04/17 19:10:30
After my change here you will need a call to the p
| |
26 DeclareAllocatorAttribute({kAvailableSizeAttribute, "bytes"}); | |
27 DeclareAllocatorAttribute({kPhysicalSizeAttribute, "bytes"}); | |
28 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
29 this); | |
30 isolate_holder_ = isolate_holder; | |
31 } | |
32 | |
33 V8IsolateMemoryDumpProvider::~V8IsolateMemoryDumpProvider() { | |
34 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | |
35 this); | |
36 } | |
37 | |
38 // Called at trace dump point time. Creates a snapshot the memory counters for | |
Primiano Tucci (use gerrit)
2015/04/17 19:10:30
snapshot +with the...
| |
39 // the current process. | |
Primiano Tucci (use gerrit)
2015/04/17 19:10:31
this is actually the current isolate,not process
| |
40 bool V8IsolateMemoryDumpProvider::DumpInto( | |
41 base::trace_event::ProcessMemoryDump* pmd) { | |
42 v8::HeapStatistics heap_statistics; | |
43 isolate_holder_->isolate()->GetHeapStatistics(&heap_statistics); | |
44 | |
45 base::trace_event::MemoryAllocatorDump* root = | |
46 pmd->GetAllocatorDump(kDumperRootName); | |
47 if (root == nullptr) { | |
48 root = pmd->CreateAllocatorDump(kDumperRootName); | |
49 } | |
50 | |
51 int thread_id = base::PlatformThread::CurrentId(); | |
52 std::stringstream dumper_name; | |
Primiano Tucci (use gerrit)
2015/04/17 19:10:30
even if it works anyways, here you need an #includ
| |
53 dumper_name << kDumperName << thread_id; | |
Primiano Tucci (use gerrit)
2015/04/17 19:10:30
probably add an underscore as separator here.
ALso
| |
54 base::trace_event::MemoryAllocatorDump* isolate_dump = | |
55 pmd->CreateAllocatorDump(dumper_name.str(), root); | |
56 | |
57 size_t known_spaces_used_size = 0; | |
58 size_t known_spaces_size = 0; | |
59 int number_of_spaces = isolate_holder_->isolate()->NumberOfHeapSpaces(); | |
60 for (int space = 0; space < number_of_spaces; space++) { | |
Primiano Tucci (use gerrit)
2015/04/17 19:10:31
probably this should be size_t (match the API)
| |
61 v8::HeapSpaceStatistics space_statistics; | |
62 isolate_holder_->isolate()->GetHeapSpaceStatistics(&space_statistics, | |
63 space); | |
64 size_t space_size = space_statistics.space_size(); | |
65 size_t space_used_size = space_statistics.space_used_size(); | |
66 | |
67 known_spaces_size += space_size; | |
68 known_spaces_used_size += space_used_size; | |
69 | |
70 base::trace_event::MemoryAllocatorDump* space_dump = | |
71 pmd->CreateAllocatorDump(space_statistics.space_name(), isolate_dump); | |
Primiano Tucci (use gerrit)
2015/04/17 19:10:30
Note to myself (primiano): probably this will need
| |
72 space_dump->set_physical_size_in_bytes(space_size); | |
73 space_dump->set_allocated_objects_count(0); | |
74 space_dump->set_allocated_objects_size_in_bytes(space_used_size); | |
75 space_dump->SetExtraAttribute(kAvailableSizeAttribute, | |
76 space_statistics.space_available_size()); | |
77 space_dump->SetExtraAttribute(kPhysicalSizeAttribute, | |
Primiano Tucci (use gerrit)
2015/04/17 19:10:31
Maybe add a TODO here, probably this should be our
| |
78 space_statistics.physical_space_size()); | |
79 } | |
80 | |
81 base::trace_event::MemoryAllocatorDump* space_dump = | |
Primiano Tucci (use gerrit)
2015/04/17 19:10:31
Add a comment explaining that here you do the comp
| |
82 pmd->CreateAllocatorDump(kDumperOtherSpaces, isolate_dump); | |
83 space_dump->set_physical_size_in_bytes(heap_statistics.total_heap_size() - | |
84 known_spaces_size); | |
85 space_dump->set_allocated_objects_count(0); | |
86 space_dump->set_allocated_objects_size_in_bytes( | |
87 heap_statistics.used_heap_size() - known_spaces_used_size); | |
88 | |
89 return true; | |
90 } | |
91 | |
92 const char* V8IsolateMemoryDumpProvider::GetFriendlyName() const { | |
93 return kDumperFriendlyName; | |
94 } | |
95 | |
96 } // namespace gin | |
OLD | NEW |