Chromium Code Reviews| Index: gin/v8_isolate_memory_dump_provider.cc |
| diff --git a/gin/v8_isolate_memory_dump_provider.cc b/gin/v8_isolate_memory_dump_provider.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6ca53d4ca135503d842e2e86658e9fa47107bd92 |
| --- /dev/null |
| +++ b/gin/v8_isolate_memory_dump_provider.cc |
| @@ -0,0 +1,101 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "gin/v8_isolate_memory_dump_provider.h" |
| + |
| +#include <sstream> |
| + |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/threading/platform_thread.h" |
| +#include "base/trace_event/memory_dump_manager.h" |
| +#include "base/trace_event/process_memory_dump.h" |
| +#include "gin/public/isolate_holder.h" |
| +#include "v8/include/v8.h" |
| + |
| +namespace gin { |
| + |
| +namespace { |
| +const char kDumperFriendlyName[] = "V8IsolateHeap"; |
| +const char kRootDumpName[] = "v8"; |
| +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.
|
| +const char kAvailableSizeAttribute[] = "available_size_in_bytes"; |
| +const char kPhysicalSizeAttribute[] = "physical_size_in_bytes"; |
| +} // namespace |
| + |
| +V8IsolateMemoryDumpProvider::V8IsolateMemoryDumpProvider( |
| + IsolateHolder* isolate_holder) |
| + : MemoryDumpProvider(base::MessageLoop::current()->task_runner()) { |
| + DeclareAllocatorAttribute(kRootDumpName, kAvailableSizeAttribute, "bytes"); |
| + DeclareAllocatorAttribute(kRootDumpName, kPhysicalSizeAttribute, "bytes"); |
| + base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
| + this); |
| + isolate_holder_ = isolate_holder; |
| +} |
| + |
| +V8IsolateMemoryDumpProvider::~V8IsolateMemoryDumpProvider() { |
| + base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| + this); |
| +} |
| + |
| +// Called at trace dump point time. Creates a snapshot with the memory counters |
| +// for the current isolate. |
| +bool V8IsolateMemoryDumpProvider::DumpInto( |
| + base::trace_event::ProcessMemoryDump* pmd) { |
| + v8::HeapStatistics heap_statistics; |
| + isolate_holder_->isolate()->GetHeapStatistics(&heap_statistics); |
| + |
| + int thread_id = base::PlatformThread::CurrentId(); |
| + std::stringstream isolate_name; |
| + // TODO(ssid): The thread_id is soon not going to be unique enough if we get |
| + // more isolates per thread. |
| + 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.
|
| + |
| + size_t known_spaces_used_size = 0; |
| + size_t known_spaces_size = 0; |
| + size_t number_of_spaces = isolate_holder_->isolate()->NumberOfHeapSpaces(); |
| + for (size_t space = 0; space < number_of_spaces; space++) { |
| + v8::HeapSpaceStatistics space_statistics; |
| + isolate_holder_->isolate()->GetHeapSpaceStatistics(&space_statistics, |
| + space); |
| + size_t space_size = space_statistics.space_size(); |
| + size_t space_used_size = space_statistics.space_used_size(); |
| + |
| + known_spaces_size += space_size; |
| + known_spaces_used_size += space_used_size; |
| + |
| + std::stringstream allocator_name; |
| + allocator_name << isolate_name.str() << '/' |
| + << space_statistics.space_name(); |
| + base::trace_event::MemoryAllocatorDump* space_dump = |
| + pmd->CreateAllocatorDump(kRootDumpName, allocator_name.str()); |
| + space_dump->set_physical_size_in_bytes(space_size); |
| + space_dump->set_allocated_objects_count(0); |
| + space_dump->set_allocated_objects_size_in_bytes(space_used_size); |
| + space_dump->SetAttribute(kAvailableSizeAttribute, |
| + space_statistics.space_available_size()); |
| + // TODO(ssid): This should probably be the physical_size_in_bytes. Check |
| + // with V8 owner. |
| + space_dump->SetAttribute(kPhysicalSizeAttribute, |
| + space_statistics.physical_space_size()); |
| + } |
| + |
| + std::stringstream allocator_name; |
| + allocator_name << isolate_name.str() << '/' << "other_spaces"; |
| + // Compute the rest of the memory, not accounted by the spaces above. |
| + 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
|
| + pmd->CreateAllocatorDump(kRootDumpName, allocator_name.str()); |
| + space_dump->set_physical_size_in_bytes(heap_statistics.total_heap_size() - |
| + known_spaces_size); |
| + space_dump->set_allocated_objects_count(0); |
| + space_dump->set_allocated_objects_size_in_bytes( |
| + heap_statistics.used_heap_size() - known_spaces_used_size); |
| + |
|
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
|
| + return true; |
| +} |
| + |
| +const char* V8IsolateMemoryDumpProvider::GetFriendlyName() const { |
| + return kDumperFriendlyName; |
| +} |
| + |
| +} // namespace gin |