| 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 "components/discardable_memory/service/discardable_shared_memory_manage
r.h" | 5 #include "components/discardable_memory/service/discardable_shared_memory_manage
r.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/debug/crash_logging.h" | 14 #include "base/debug/crash_logging.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/discardable_memory.h" | 16 #include "base/memory/discardable_memory.h" |
| 17 #include "base/memory/memory_coordinator_client_registry.h" | 17 #include "base/memory/memory_coordinator_client_registry.h" |
| 18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 19 #include "base/memory/shared_memory_tracker.h" |
| 19 #include "base/numerics/safe_math.h" | 20 #include "base/numerics/safe_math.h" |
| 20 #include "base/process/memory.h" | 21 #include "base/process/memory.h" |
| 21 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
| 22 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
| 23 #include "base/sys_info.h" | 24 #include "base/sys_info.h" |
| 24 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
| 25 #include "base/trace_event/memory_allocator_dump.h" | 26 #include "base/trace_event/memory_allocator_dump.h" |
| 26 #include "base/trace_event/memory_dump_manager.h" | 27 #include "base/trace_event/memory_dump_manager.h" |
| 27 #include "base/trace_event/process_memory_dump.h" | 28 #include "base/trace_event/process_memory_dump.h" |
| 28 #include "base/trace_event/trace_event.h" | 29 #include "base/trace_event/trace_event.h" |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 // corresponding dump for the same segment, this will avoid to | 322 // corresponding dump for the same segment, this will avoid to |
| 322 // double-count them in tracing. If, instead, no other process will emit a | 323 // double-count them in tracing. If, instead, no other process will emit a |
| 323 // dump with the same guid, the segment will be accounted to the browser. | 324 // dump with the same guid, the segment will be accounted to the browser. |
| 324 const uint64_t client_tracing_id = | 325 const uint64_t client_tracing_id = |
| 325 ClientProcessUniqueIdToTracingProcessId(client_id); | 326 ClientProcessUniqueIdToTracingProcessId(client_id); |
| 326 base::trace_event::MemoryAllocatorDumpGuid shared_segment_guid = | 327 base::trace_event::MemoryAllocatorDumpGuid shared_segment_guid = |
| 327 DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing( | 328 DiscardableSharedMemoryHeap::GetSegmentGUIDForTracing( |
| 328 client_tracing_id, segment_id); | 329 client_tracing_id, segment_id); |
| 329 pmd->CreateSharedGlobalAllocatorDump(shared_segment_guid); | 330 pmd->CreateSharedGlobalAllocatorDump(shared_segment_guid); |
| 330 pmd->AddOwnershipEdge(dump->guid(), shared_segment_guid); | 331 pmd->AddOwnershipEdge(dump->guid(), shared_segment_guid); |
| 332 base::SharedMemoryTracker::AddOwnershipEdgeToSharedGlobalDump( |
| 333 pmd, shared_segment_guid, |
| 334 segment->memory()->handle(), segment->memory()->mapped_size()); |
| 331 | 335 |
| 332 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) | 336 #if defined(COUNT_RESIDENT_BYTES_SUPPORTED) |
| 333 if (args.level_of_detail == | 337 if (args.level_of_detail == |
| 334 base::trace_event::MemoryDumpLevelOfDetail::DETAILED) { | 338 base::trace_event::MemoryDumpLevelOfDetail::DETAILED) { |
| 335 size_t resident_size = | 339 size_t resident_size = |
| 336 base::trace_event::ProcessMemoryDump::CountResidentBytes( | 340 base::trace_event::ProcessMemoryDump::CountResidentBytes( |
| 337 segment->memory()->memory(), segment->memory()->mapped_size()); | 341 segment->memory()->memory(), segment->memory()->mapped_size()); |
| 338 | 342 |
| 339 // This is added to the global dump since it has to be attributed to | 343 // This is added to the global dump since it has to be attributed to |
| 340 // both the allocator dumps involved. | 344 // both the allocator dumps involved. |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 return; | 621 return; |
| 618 | 622 |
| 619 enforce_memory_policy_pending_ = true; | 623 enforce_memory_policy_pending_ = true; |
| 620 DCHECK(enforce_memory_policy_task_runner_); | 624 DCHECK(enforce_memory_policy_task_runner_); |
| 621 enforce_memory_policy_task_runner_->PostDelayedTask( | 625 enforce_memory_policy_task_runner_->PostDelayedTask( |
| 622 FROM_HERE, enforce_memory_policy_callback_, | 626 FROM_HERE, enforce_memory_policy_callback_, |
| 623 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); | 627 base::TimeDelta::FromMilliseconds(kEnforceMemoryPolicyDelayMs)); |
| 624 } | 628 } |
| 625 | 629 |
| 626 } // namespace discardable_memory | 630 } // namespace discardable_memory |
| OLD | NEW |