| 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 bool HostDiscardableSharedMemoryManager::OnMemoryDump( | 169 bool HostDiscardableSharedMemoryManager::OnMemoryDump( |
| 170 const base::trace_event::MemoryDumpArgs& args, | 170 const base::trace_event::MemoryDumpArgs& args, |
| 171 base::trace_event::ProcessMemoryDump* pmd) { | 171 base::trace_event::ProcessMemoryDump* pmd) { |
| 172 base::AutoLock lock(lock_); | 172 base::AutoLock lock(lock_); |
| 173 for (const auto& process_entry : processes_) { | 173 for (const auto& process_entry : processes_) { |
| 174 const int child_process_id = process_entry.first; | 174 const int child_process_id = process_entry.first; |
| 175 const MemorySegmentMap& process_segments = process_entry.second; | 175 const MemorySegmentMap& process_segments = process_entry.second; |
| 176 for (const auto& segment_entry : process_segments) { | 176 for (const auto& segment_entry : process_segments) { |
| 177 const int segment_id = segment_entry.first; | 177 const int segment_id = segment_entry.first; |
| 178 const MemorySegment* segment = segment_entry.second.get(); | 178 const MemorySegment* segment = segment_entry.second.get(); |
| 179 if (!segment->memory()->mapped_size()) |
| 180 continue; |
| 181 |
| 179 std::string dump_name = base::StringPrintf( | 182 std::string dump_name = base::StringPrintf( |
| 180 "discardable/process_%x/segment_%d", child_process_id, segment_id); | 183 "discardable/process_%x/segment_%d", child_process_id, segment_id); |
| 181 base::trace_event::MemoryAllocatorDump* dump = | 184 base::trace_event::MemoryAllocatorDump* dump = |
| 182 pmd->CreateAllocatorDump(dump_name); | 185 pmd->CreateAllocatorDump(dump_name); |
| 186 |
| 183 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | 187 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 184 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | 188 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 185 segment->memory()->mapped_size()); | 189 segment->memory()->mapped_size()); |
| 186 | 190 |
| 191 // Host can only tell if whole segment is locked or not. |
| 192 dump->AddScalar( |
| 193 "locked_size", base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 194 segment->memory()->IsMemoryLocked() ? segment->memory()->mapped_size() |
| 195 : 0u); |
| 196 |
| 187 // Create the cross-process ownership edge. If the child creates a | 197 // Create the cross-process ownership edge. If the child creates a |
| 188 // corresponding dump for the same segment, this will avoid to | 198 // corresponding dump for the same segment, this will avoid to |
| 189 // double-count them in tracing. If, instead, no other process will emit a | 199 // double-count them in tracing. If, instead, no other process will emit a |
| 190 // dump with the same guid, the segment will be accounted to the browser. | 200 // dump with the same guid, the segment will be accounted to the browser. |
| 191 const uint64 child_tracing_process_id = | 201 const uint64 child_tracing_process_id = |
| 192 ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId( | 202 ChildProcessHostImpl::ChildProcessUniqueIdToTracingProcessId( |
| 193 child_process_id); | 203 child_process_id); |
| 194 base::trace_event::MemoryAllocatorDumpGuid shared_segment_guid = | 204 base::trace_event::MemoryAllocatorDumpGuid shared_segment_guid = |
| 195 DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing( | 205 DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing( |
| 196 child_tracing_process_id, segment_id); | 206 child_tracing_process_id, segment_id); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 | 476 |
| 467 enforce_memory_policy_pending_ = true; | 477 enforce_memory_policy_pending_ = true; |
| 468 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 478 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 469 FROM_HERE, | 479 FROM_HERE, |
| 470 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, | 480 base::Bind(&HostDiscardableSharedMemoryManager::EnforceMemoryPolicy, |
| 471 weak_ptr_factory_.GetWeakPtr()), | 481 weak_ptr_factory_.GetWeakPtr()), |
| 472 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); | 482 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); |
| 473 } | 483 } |
| 474 | 484 |
| 475 } // namespace content | 485 } // namespace content |
| OLD | NEW |