Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 "base/memory/shared_memory_tracker.h" | |
| 6 | |
| 7 #include "base/memory/shared_memory.h" | |
| 8 #include "base/strings/stringprintf.h" | |
| 9 #include "base/trace_event/memory_dump_manager.h" | |
| 10 #include "base/trace_event/process_memory_dump.h" | |
| 11 | |
| 12 namespace base { | |
| 13 | |
| 14 const char* kSharedMemoryDumpName = "shared_memory"; | |
|
danakj
2017/01/25 16:58:13
static
hajimehoshi
2017/01/26 10:56:00
Done.
| |
| 15 | |
| 16 SharedMemoryTracker* SharedMemoryTracker::GetInstance() { | |
| 17 return base::Singleton<SharedMemoryTracker, base::LeakySingletonTraits< | |
| 18 SharedMemoryTracker>>::get(); | |
| 19 } | |
| 20 | |
| 21 bool SharedMemoryTracker::OnMemoryDump( | |
| 22 const base::trace_event::MemoryDumpArgs& args, | |
| 23 base::trace_event::ProcessMemoryDump* pmd) { | |
| 24 for (auto& bucket : buckets_) { | |
| 25 base::AutoLock lock(bucket.lock); | |
| 26 for (const auto& usage : bucket.usages) { | |
| 27 SharedMemoryHandleID id = usage.first; | |
| 28 std::string id_str = GetSharedMemoryHandleIDString(id); | |
| 29 std::string dump_name = | |
| 30 base::StringPrintf("%s/%s", kSharedMemoryDumpName, id_str.c_str()); | |
|
danakj
2017/01/25 16:58:13
I think you could just print the two components of
ssid
2017/01/25 23:03:06
This function would be required later for the othe
hajimehoshi
2017/01/26 10:56:00
Right, a function to convert id into string would
| |
| 31 auto guid = base::trace_event::MemoryAllocatorDumpGuid(dump_name); | |
| 32 base::trace_event::MemoryAllocatorDump* local_dump = | |
|
danakj
2017/01/25 16:58:13
what deletes this?
ssid
2017/01/25 23:03:06
This gets added to trace json file at MemoryDumpMa
| |
| 33 pmd->CreateAllocatorDump(dump_name); | |
| 34 local_dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
|
ssid
2017/01/25 23:03:06
I think we need a TODO here saying this size repor
hajimehoshi
2017/01/26 10:56:00
Done.
| |
| 35 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
| 36 usage.second); | |
| 37 base::trace_event::MemoryAllocatorDump* global_dump = | |
|
danakj
2017/01/25 16:58:13
what deletes this?
ssid
2017/01/25 23:03:06
Same comment as above.
| |
| 38 pmd->CreateSharedGlobalAllocatorDump(guid); | |
| 39 global_dump->AddScalar( | |
| 40 base::trace_event::MemoryAllocatorDump::kNameSize, | |
| 41 base::trace_event::MemoryAllocatorDump::kUnitsBytes, usage.second); | |
| 42 pmd->AddOwnershipEdge(local_dump->guid(), global_dump->guid()); | |
|
ssid
2017/01/25 23:03:06
Is there any way to identify if this is browser or
ssid
2017/01/25 23:03:06
We also need a TODO here saying this is currently
hajimehoshi
2017/01/26 10:56:00
I'm not sure about this. I'll leave TODO here inst
| |
| 43 } | |
| 44 } | |
| 45 return true; | |
| 46 } | |
| 47 | |
| 48 bool SharedMemoryTracker::IncrementMemoryUsage( | |
| 49 const SharedMemory& shared_memory) { | |
| 50 SharedMemoryHandleID id; | |
| 51 if (!GetIDFromSharedMemoryHandle(shared_memory.handle(), &id)) { | |
| 52 return false; | |
| 53 } | |
| 54 int bucket = id.file_id % kTrackerBucketNum; | |
| 55 base::AutoLock lock(buckets_[bucket].lock); | |
| 56 buckets_[bucket].usages[id] = shared_memory.mapped_size(); | |
| 57 return true; | |
| 58 } | |
| 59 | |
| 60 bool SharedMemoryTracker::DecrementMemoryUsage( | |
| 61 const SharedMemory& shared_memory) { | |
| 62 SharedMemoryHandleID id; | |
| 63 if (!GetIDFromSharedMemoryHandle(shared_memory.handle(), &id)) { | |
| 64 return false; | |
| 65 } | |
| 66 int bucket = id.file_id % kTrackerBucketNum; | |
| 67 base::AutoLock lock(buckets_[bucket].lock); | |
| 68 buckets_[bucket].usages.erase(id); | |
| 69 return true; | |
| 70 } | |
| 71 | |
| 72 SharedMemoryTracker::SharedMemoryTracker() { | |
| 73 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( | |
| 74 this, "SharedMemoryTracker", nullptr); | |
| 75 } | |
| 76 | |
| 77 SharedMemoryTracker::~SharedMemoryTracker() {} | |
|
danakj
2017/01/25 16:58:13
= default for these
hajimehoshi
2017/01/26 10:56:00
Done.
| |
| 78 | |
| 79 SharedMemoryTracker::TrackerBucket::TrackerBucket() {} | |
| 80 | |
| 81 SharedMemoryTracker::TrackerBucket::~TrackerBucket() {} | |
| 82 | |
| 83 } // namespace | |
| OLD | NEW |