OLD | NEW |
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/common/host_discardable_shared_memory_manager.h" | 5 #include "content/common/host_discardable_shared_memory_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 memory->Close(); | 148 memory->Close(); |
149 return make_scoped_ptr(new DiscardableMemoryImpl( | 149 return make_scoped_ptr(new DiscardableMemoryImpl( |
150 memory.Pass(), | 150 memory.Pass(), |
151 base::Bind( | 151 base::Bind( |
152 &HostDiscardableSharedMemoryManager::DeletedDiscardableSharedMemory, | 152 &HostDiscardableSharedMemoryManager::DeletedDiscardableSharedMemory, |
153 base::Unretained(this), new_id, ChildProcessHost::kInvalidUniqueID))); | 153 base::Unretained(this), new_id, ChildProcessHost::kInvalidUniqueID))); |
154 } | 154 } |
155 | 155 |
156 bool HostDiscardableSharedMemoryManager::OnMemoryDump( | 156 bool HostDiscardableSharedMemoryManager::OnMemoryDump( |
157 base::trace_event::ProcessMemoryDump* pmd) { | 157 base::trace_event::ProcessMemoryDump* pmd) { |
| 158 base::trace_event::MemoryAllocatorDump* objects_dump = |
| 159 pmd->CreateAllocatorDump(GetMemoryPoolNameForTracing()); |
| 160 base::trace_event::MemoryAllocatorDump* discardable_segments_dump = |
| 161 pmd->CreateAllocatorDump("discardable/segments"); |
| 162 pmd->AddOwnershipEdge(objects_dump->guid(), |
| 163 discardable_segments_dump->guid()); |
| 164 |
158 base::AutoLock lock(lock_); | 165 base::AutoLock lock(lock_); |
159 for (const auto& process_entry : processes_) { | 166 for (const auto& process_entry : processes_) { |
160 const int child_process_id = process_entry.first; | 167 const int child_process_id = process_entry.first; |
161 const MemorySegmentMap& process_segments = process_entry.second; | 168 const MemorySegmentMap& process_segments = process_entry.second; |
162 for (const auto& segment_entry : process_segments) { | 169 for (const auto& segment_entry : process_segments) { |
163 const int segment_id = segment_entry.first; | 170 const int segment_id = segment_entry.first; |
164 const MemorySegment* segment = segment_entry.second.get(); | 171 const MemorySegment* segment = segment_entry.second.get(); |
165 std::string dump_name = base::StringPrintf( | 172 std::string dump_name = |
166 "discardable/process_%x/segment_%d", child_process_id, segment_id); | 173 base::StringPrintf("discardable/segments/process_%x/segment_%d", |
| 174 child_process_id, segment_id); |
167 base::trace_event::MemoryAllocatorDump* dump = | 175 base::trace_event::MemoryAllocatorDump* dump = |
168 pmd->CreateAllocatorDump(dump_name); | 176 pmd->CreateAllocatorDump(dump_name); |
169 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 177 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
170 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 178 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
171 segment->memory()->mapped_size()); | 179 segment->memory()->mapped_size()); |
172 | 180 |
173 // Create the cross-process ownership edge. If the child creates a | 181 // Create the cross-process ownership edge. If the child creates a |
174 // corresponding dump for the same segment, this will avoid to | 182 // corresponding dump for the same segment, this will avoid to |
175 // double-count them in tracing. If, instead, no other process will emit a | 183 // double-count them in tracing. If, instead, no other process will emit a |
176 // dump with the same guid, the segment will be accounted to the browser. | 184 // dump with the same guid, the segment will be accounted to the browser. |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 | 463 |
456 enforce_memory_policy_pending_ = true; | 464 enforce_memory_policy_pending_ = true; |
457 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 465 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
458 FROM_HERE, | 466 FROM_HERE, |
459 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, | 467 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, |
460 weak_ptr_factory_.GetWeakPtr()), | 468 weak_ptr_factory_.GetWeakPtr()), |
461 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); | 469 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); |
462 } | 470 } |
463 | 471 |
464 } // namespace content | 472 } // namespace content |
OLD | NEW |