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

Side by Side Diff: content/child/child_discardable_shared_memory_manager.cc

Issue 1100073004: Adding discardable memory dump provider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/child_discardable_shared_memory_manager.h" 5 #include "content/child/child_discardable_shared_memory_manager.h"
6 6
7 #include "base/atomic_sequence_num.h" 7 #include "base/atomic_sequence_num.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/debug/crash_logging.h" 9 #include "base/debug/crash_logging.h"
10 #include "base/memory/discardable_memory.h" 10 #include "base/memory/discardable_memory.h"
11 #include "base/memory/discardable_shared_memory.h" 11 #include "base/memory/discardable_shared_memory.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/process/memory.h" 13 #include "base/process/memory.h"
14 #include "base/process/process_metrics.h" 14 #include "base/process/process_metrics.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/stringprintf.h"
17 #include "base/trace_event/memory_dump_manager.h"
18 #include "base/trace_event/process_memory_dump.h"
16 #include "base/trace_event/trace_event.h" 19 #include "base/trace_event/trace_event.h"
17 #include "content/common/child_process_messages.h" 20 #include "content/common/child_process_messages.h"
18 21
19 namespace content { 22 namespace content {
20 namespace { 23 namespace {
21 24
22 // Default allocation size. 25 // Default allocation size.
23 #if defined(OS_ANDROID) 26 #if defined(OS_ANDROID)
24 // Larger allocation size on Android to avoid reaching the FD-limit. 27 // Larger allocation size on Android to avoid reaching the FD-limit.
25 const size_t kAllocationSize = 32 * 1024 * 1024; 28 const size_t kAllocationSize = 32 * 1024 * 1024;
26 #else 29 #else
27 const size_t kAllocationSize = 4 * 1024 * 1024; 30 const size_t kAllocationSize = 4 * 1024 * 1024;
28 #endif 31 #endif
29 32
33 const char kMemoryDumperFriendlyName[] = "ChildDiscardable";
reveman 2015/04/23 17:32:30 is "Discardable" enough? we're not using the "Chil
ssid 2015/04/24 11:23:04 Done.
34
30 // Global atomic to generate unique discardable shared memory IDs. 35 // Global atomic to generate unique discardable shared memory IDs.
31 base::StaticAtomicSequenceNumber g_next_discardable_shared_memory_id; 36 base::StaticAtomicSequenceNumber g_next_discardable_shared_memory_id;
32 37
33 class DiscardableMemoryImpl : public base::DiscardableMemory { 38 class DiscardableMemoryImpl : public base::DiscardableMemory {
34 public: 39 public:
35 DiscardableMemoryImpl(ChildDiscardableSharedMemoryManager* manager, 40 DiscardableMemoryImpl(ChildDiscardableSharedMemoryManager* manager,
36 scoped_ptr<DiscardableSharedMemoryHeap::Span> span) 41 scoped_ptr<DiscardableSharedMemoryHeap::Span> span)
37 : manager_(manager), span_(span.Pass()), is_locked_(true) {} 42 : manager_(manager), span_(span.Pass()), is_locked_(true) {}
38 43
39 ~DiscardableMemoryImpl() override { 44 ~DiscardableMemoryImpl() override {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 scoped_refptr<ThreadSafeSender> sender, 81 scoped_refptr<ThreadSafeSender> sender,
77 DiscardableSharedMemoryId id) { 82 DiscardableSharedMemoryId id) {
78 sender->Send(new ChildProcessHostMsg_DeletedDiscardableSharedMemory(id)); 83 sender->Send(new ChildProcessHostMsg_DeletedDiscardableSharedMemory(id));
79 } 84 }
80 85
81 } // namespace 86 } // namespace
82 87
83 ChildDiscardableSharedMemoryManager::ChildDiscardableSharedMemoryManager( 88 ChildDiscardableSharedMemoryManager::ChildDiscardableSharedMemoryManager(
84 ThreadSafeSender* sender) 89 ThreadSafeSender* sender)
85 : heap_(base::GetPageSize()), sender_(sender) { 90 : heap_(base::GetPageSize()), sender_(sender) {
91 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
92 this);
86 } 93 }
87 94
88 ChildDiscardableSharedMemoryManager::~ChildDiscardableSharedMemoryManager() { 95 ChildDiscardableSharedMemoryManager::~ChildDiscardableSharedMemoryManager() {
96 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
Primiano Tucci (use gerrit) 2015/04/23 16:11:55 Considering that this is not a singleton, you shou
ssid 2015/04/24 11:23:03 Thanks. done
97 this);
89 // TODO(reveman): Determine if this DCHECK can be enabled. crbug.com/430533 98 // TODO(reveman): Determine if this DCHECK can be enabled. crbug.com/430533
90 // DCHECK_EQ(heap_.GetSize(), heap_.GetSizeOfFreeLists()); 99 // DCHECK_EQ(heap_.GetSize(), heap_.GetSizeOfFreeLists());
91 if (heap_.GetSize()) 100 if (heap_.GetSize())
92 MemoryUsageChanged(0, 0); 101 MemoryUsageChanged(0, 0);
93 } 102 }
94 103
95 scoped_ptr<base::DiscardableMemory> 104 scoped_ptr<base::DiscardableMemory>
96 ChildDiscardableSharedMemoryManager::AllocateLockedDiscardableMemory( 105 ChildDiscardableSharedMemoryManager::AllocateLockedDiscardableMemory(
97 size_t size) { 106 size_t size) {
98 base::AutoLock lock(lock_); 107 base::AutoLock lock(lock_);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 static const char kDiscardableMemoryAllocatedKey[] = 291 static const char kDiscardableMemoryAllocatedKey[] =
283 "discardable-memory-allocated"; 292 "discardable-memory-allocated";
284 base::debug::SetCrashKeyValue(kDiscardableMemoryAllocatedKey, 293 base::debug::SetCrashKeyValue(kDiscardableMemoryAllocatedKey,
285 base::Uint64ToString(new_bytes_total)); 294 base::Uint64ToString(new_bytes_total));
286 295
287 static const char kDiscardableMemoryFreeKey[] = "discardable-memory-free"; 296 static const char kDiscardableMemoryFreeKey[] = "discardable-memory-free";
288 base::debug::SetCrashKeyValue(kDiscardableMemoryFreeKey, 297 base::debug::SetCrashKeyValue(kDiscardableMemoryFreeKey,
289 base::Uint64ToString(new_bytes_free)); 298 base::Uint64ToString(new_bytes_free));
290 } 299 }
291 300
301 bool ChildDiscardableSharedMemoryManager::DumpInto(
302 base::trace_event::ProcessMemoryDump* pmd) {
303 DiscardableSharedMemoryHeap::MemoryStatistics stats;
304 heap_.GetMemoryStatistics(&stats);
305 for (size_t segment = 0; segment < stats.segments_stats.size(); segment++) {
306 std::string segment_id = base::StringPrintf("segment_%zu", segment);
reveman 2015/04/23 17:32:30 nit: looking at process_memory_dump.h it seems lik
ssid 2015/04/24 11:23:03 I used '_' in V8 provider. Primiano, WDYT?
307 base::trace_event::MemoryAllocatorDump* segment_dump =
308 pmd->CreateAllocatorDump("child_discardable_memory",
reveman 2015/04/23 17:32:30 nit: is "discardable" enough? omitting "child_" to
ssid 2015/04/24 11:23:03 Yes discardable is enough.
309 segment_id.c_str());
310 segment_dump->set_physical_size_in_bytes(
311 static_cast<int>(stats.segments_stats[segment].size));
312 segment_dump->set_allocated_objects_count(
313 static_cast<int>(stats.segments_stats[segment].num_of_objects));
314 segment_dump->set_allocated_objects_size_in_bytes(
315 static_cast<int>(stats.segments_stats[segment].used_size));
316 }
317 return true;
318 }
319
320 const char* ChildDiscardableSharedMemoryManager::GetFriendlyName() const {
321 return kMemoryDumperFriendlyName;
322 }
323
292 } // namespace content 324 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698