Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1862)

Side by Side Diff: gin/v8_isolate_memory_dump_provider.cc

Issue 1088683003: Adding v8_isolate_memory_dump_provider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase for using locker. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gin/v8_isolate_memory_dump_provider.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/strings/stringprintf.h"
8 #include "base/thread_task_runner_handle.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::ThreadTaskRunnerHandle::Get()),
26 isolate_holder_(isolate_holder) {
27 DeclareAllocatorAttribute(kRootDumpName, kAvailableSizeAttribute, "bytes");
28 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
29 this);
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 if (isolate_holder_->access_mode() == IsolateHolder::kUseLocker) {
42 v8::Locker locked(isolate_holder_->isolate());
43 DumpMemoryStatistics_(pmd);
44 } else {
45 DumpMemoryStatistics_(pmd);
46 }
47 return true;
48 }
49
50 const char* V8IsolateMemoryDumpProvider::GetFriendlyName() const {
51 return kDumperFriendlyName;
52 }
53
54 void V8IsolateMemoryDumpProvider::DumpMemoryStatistics_(
55 base::trace_event::ProcessMemoryDump* pmd) {
56 v8::HeapStatistics heap_statistics;
57 isolate_holder_->isolate()->GetHeapStatistics(&heap_statistics);
58
59 size_t known_spaces_used_size = 0;
60 size_t known_spaces_size = 0;
61 size_t number_of_spaces = isolate_holder_->isolate()->NumberOfHeapSpaces();
62 for (size_t space = 0; space < number_of_spaces; space++) {
63 v8::HeapSpaceStatistics space_statistics;
64 isolate_holder_->isolate()->GetHeapSpaceStatistics(&space_statistics,
65 space);
66 size_t space_size = space_statistics.space_size();
67 size_t space_used_size = space_statistics.space_used_size();
68
69 known_spaces_size += space_size;
70 known_spaces_used_size += space_used_size;
71
72 std::string allocator_name =
73 base::StringPrintf(kIsolateDumpName, isolate_holder_->isolate(),
74 space_statistics.space_name());
75 base::trace_event::MemoryAllocatorDump* space_dump =
76 pmd->CreateAllocatorDump(kRootDumpName, allocator_name.c_str());
77 space_dump->set_physical_size_in_bytes(static_cast<int>((space_size)));
Primiano Tucci (use gerrit) 2015/04/27 08:41:03 set_physical_size_in_bytes takes a uint64, this sh
ssid 2015/04/27 12:15:28 Done.
78 // TODO(ssid): It is possible to get the objects count of live objects
79 // after the last GC.
Primiano Tucci (use gerrit) 2015/04/27 08:41:03 Hmm not really sure I understand what is the messa
ssid 2015/04/27 12:15:28 Done.
80 space_dump->set_allocated_objects_count(0);
81 space_dump->set_allocated_objects_size_in_bytes(
82 static_cast<int>(space_used_size));
Primiano Tucci (use gerrit) 2015/04/27 08:41:03 ditto here for int <> uint64
83 space_dump->SetAttribute(
84 kAvailableSizeAttribute,
85 static_cast<int>(space_statistics.space_available_size()));
86 }
87 // Compute the rest of the memory, not accounted by the spaces above.
88 std::string allocator_name = base::StringPrintf(
89 kIsolateDumpName, isolate_holder_->isolate(), "other_spaces");
90 base::trace_event::MemoryAllocatorDump* other_spaces_dump =
91 pmd->CreateAllocatorDump(kRootDumpName, allocator_name.c_str());
92 other_spaces_dump->set_physical_size_in_bytes(
93 static_cast<int>(heap_statistics.total_heap_size() - known_spaces_size));
94 other_spaces_dump->set_allocated_objects_count(0);
95 other_spaces_dump->set_allocated_objects_size_in_bytes(static_cast<int>(
96 heap_statistics.used_heap_size() - known_spaces_used_size));
97 // TODO(ssid): Extend GetHeapStatistics api to return available size.
Primiano Tucci (use gerrit) 2015/04/27 08:41:03 Add a blank line before the TODO
98 other_spaces_dump->SetAttribute(kAvailableSizeAttribute, 0);
99 }
100
101 } // namespace gin
OLDNEW
« no previous file with comments | « gin/v8_isolate_memory_dump_provider.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698