Chromium Code Reviews| 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 <sstream> | |
| 8 | |
| 9 #include "base/message_loop/message_loop.h" | |
| 10 #include "base/threading/platform_thread.h" | |
| 11 #include "base/trace_event/memory_dump_manager.h" | |
| 12 #include "base/trace_event/process_memory_dump.h" | |
| 13 #include "gin/public/isolate_holder.h" | |
| 14 #include "v8/include/v8.h" | |
| 15 | |
| 16 namespace gin { | |
| 17 | |
| 18 namespace { | |
| 19 const char kDumperFriendlyName[] = "V8IsolateHeap"; | |
| 20 const char kRootDumpName[] = "v8"; | |
| 21 const char kIsolateDumpName[] = "isolate"; | |
|
Primiano Tucci (use gerrit)
2015/04/21 16:43:42
I think that you could have a string format here (
ssid
2015/04/21 17:38:23
Done.
| |
| 22 const char kAvailableSizeAttribute[] = "available_size_in_bytes"; | |
| 23 const char kPhysicalSizeAttribute[] = "physical_size_in_bytes"; | |
| 24 } // namespace | |
| 25 | |
| 26 V8IsolateMemoryDumpProvider::V8IsolateMemoryDumpProvider( | |
| 27 IsolateHolder* isolate_holder) | |
| 28 : MemoryDumpProvider(base::MessageLoop::current()->task_runner()) { | |
| 29 DeclareAllocatorAttribute(kRootDumpName, kAvailableSizeAttribute, "bytes"); | |
| 30 DeclareAllocatorAttribute(kRootDumpName, kPhysicalSizeAttribute, "bytes"); | |
| 31 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
| 32 this); | |
| 33 isolate_holder_ = isolate_holder; | |
| 34 } | |
| 35 | |
| 36 V8IsolateMemoryDumpProvider::~V8IsolateMemoryDumpProvider() { | |
| 37 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | |
| 38 this); | |
| 39 } | |
| 40 | |
| 41 // Called at trace dump point time. Creates a snapshot with the memory counters | |
| 42 // for the current isolate. | |
| 43 bool V8IsolateMemoryDumpProvider::DumpInto( | |
| 44 base::trace_event::ProcessMemoryDump* pmd) { | |
| 45 v8::HeapStatistics heap_statistics; | |
| 46 isolate_holder_->isolate()->GetHeapStatistics(&heap_statistics); | |
| 47 | |
| 48 int thread_id = base::PlatformThread::CurrentId(); | |
| 49 std::stringstream isolate_name; | |
| 50 // TODO(ssid): The thread_id is soon not going to be unique enough if we get | |
| 51 // more isolates per thread. | |
| 52 isolate_name << kIsolateDumpName << '_' << thread_id; | |
|
Primiano Tucci (use gerrit)
2015/04/21 16:43:42
You can simplify this by using StringPrintf (#incl
ssid
2015/04/21 17:38:23
Done.
| |
| 53 | |
| 54 size_t known_spaces_used_size = 0; | |
| 55 size_t known_spaces_size = 0; | |
| 56 size_t number_of_spaces = isolate_holder_->isolate()->NumberOfHeapSpaces(); | |
| 57 for (size_t space = 0; space < number_of_spaces; space++) { | |
| 58 v8::HeapSpaceStatistics space_statistics; | |
| 59 isolate_holder_->isolate()->GetHeapSpaceStatistics(&space_statistics, | |
| 60 space); | |
| 61 size_t space_size = space_statistics.space_size(); | |
| 62 size_t space_used_size = space_statistics.space_used_size(); | |
| 63 | |
| 64 known_spaces_size += space_size; | |
| 65 known_spaces_used_size += space_used_size; | |
| 66 | |
| 67 std::stringstream allocator_name; | |
| 68 allocator_name << isolate_name.str() << '/' | |
| 69 << space_statistics.space_name(); | |
| 70 base::trace_event::MemoryAllocatorDump* space_dump = | |
| 71 pmd->CreateAllocatorDump(kRootDumpName, allocator_name.str()); | |
| 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->SetAttribute(kAvailableSizeAttribute, | |
| 76 space_statistics.space_available_size()); | |
| 77 // TODO(ssid): This should probably be the physical_size_in_bytes. Check | |
| 78 // with V8 owner. | |
| 79 space_dump->SetAttribute(kPhysicalSizeAttribute, | |
| 80 space_statistics.physical_space_size()); | |
| 81 } | |
| 82 | |
| 83 std::stringstream allocator_name; | |
| 84 allocator_name << isolate_name.str() << '/' << "other_spaces"; | |
| 85 // Compute the rest of the memory, not accounted by the spaces above. | |
| 86 base::trace_event::MemoryAllocatorDump* space_dump = | |
|
Primiano Tucci (use gerrit)
2015/04/21 16:43:42
s/space_dump/other_spaces_dump/
ssid
2015/04/21 17:38:22
Note: other spaces are named as : new_space, old_s
| |
| 87 pmd->CreateAllocatorDump(kRootDumpName, allocator_name.str()); | |
| 88 space_dump->set_physical_size_in_bytes(heap_statistics.total_heap_size() - | |
| 89 known_spaces_size); | |
| 90 space_dump->set_allocated_objects_count(0); | |
| 91 space_dump->set_allocated_objects_size_in_bytes( | |
| 92 heap_statistics.used_heap_size() - known_spaces_used_size); | |
| 93 | |
|
Primiano Tucci (use gerrit)
2015/04/21 16:43:42
Can you please do the accounting of the two extra
ssid
2015/04/21 17:38:23
Cant be done for available memory because, there i
| |
| 94 return true; | |
| 95 } | |
| 96 | |
| 97 const char* V8IsolateMemoryDumpProvider::GetFriendlyName() const { | |
| 98 return kDumperFriendlyName; | |
| 99 } | |
| 100 | |
| 101 } // namespace gin | |
| OLD | NEW |