Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/disk_cache/memory/mem_backend_impl.h" | 5 #include "net/disk_cache/memory/mem_backend_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
| 14 #include "base/trace_event/memory_usage_estimator.h" | 14 #include "base/trace_event/memory_usage_estimator.h" |
| 15 #include "base/trace_event/process_memory_dump.h" | |
| 15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 16 #include "net/disk_cache/cache_util.h" | 17 #include "net/disk_cache/cache_util.h" |
| 17 #include "net/disk_cache/memory/mem_entry_impl.h" | 18 #include "net/disk_cache/memory/mem_entry_impl.h" |
| 18 | 19 |
| 19 using base::Time; | 20 using base::Time; |
| 20 | 21 |
| 21 namespace disk_cache { | 22 namespace disk_cache { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 return std::unique_ptr<Backend::Iterator>( | 278 return std::unique_ptr<Backend::Iterator>( |
| 278 new MemIterator(weak_factory_.GetWeakPtr())); | 279 new MemIterator(weak_factory_.GetWeakPtr())); |
| 279 } | 280 } |
| 280 | 281 |
| 281 void MemBackendImpl::OnExternalCacheHit(const std::string& key) { | 282 void MemBackendImpl::OnExternalCacheHit(const std::string& key) { |
| 282 EntryMap::iterator it = entries_.find(key); | 283 EntryMap::iterator it = entries_.find(key); |
| 283 if (it != entries_.end()) | 284 if (it != entries_.end()) |
| 284 it->second->UpdateStateOnUse(MemEntryImpl::ENTRY_WAS_NOT_MODIFIED); | 285 it->second->UpdateStateOnUse(MemEntryImpl::ENTRY_WAS_NOT_MODIFIED); |
| 285 } | 286 } |
| 286 | 287 |
| 287 size_t MemBackendImpl::EstimateMemoryUsage() const { | 288 size_t MemBackendImpl::DumpMemoryStats( |
| 289 base::trace_event::ProcessMemoryDump* pmd, | |
| 290 const std::string& parent_absolute_name) const { | |
| 291 base::trace_event::MemoryAllocatorDump* dump = | |
| 292 pmd->CreateAllocatorDump(parent_absolute_name + "/memory_backend"); | |
|
ssid
2017/03/27 17:41:45
I think you should whitelist these strings in trac
jkarlin
2017/03/27 17:59:28
Thanks, done!
| |
| 293 | |
| 288 // Entries in lru_list_ will be counted by EMU but not in entries_ since | 294 // Entries in lru_list_ will be counted by EMU but not in entries_ since |
| 289 // they're pointers. | 295 // they're pointers. |
| 290 return base::trace_event::EstimateMemoryUsage(lru_list_) + | 296 size_t size = base::trace_event::EstimateMemoryUsage(lru_list_) + |
| 291 base::trace_event::EstimateMemoryUsage(entries_); | 297 base::trace_event::EstimateMemoryUsage(entries_); |
| 298 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
| 299 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size); | |
| 300 | |
| 301 dump->AddScalar("phys_mem", | |
| 302 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
| 303 base::SysInfo::AmountOfPhysicalMemory()); | |
| 304 dump->AddScalar("cur_size", | |
| 305 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
| 306 current_size_); | |
| 307 dump->AddScalar("max_size", | |
| 308 base::trace_event::MemoryAllocatorDump::kUnitsBytes, | |
| 309 max_size_); | |
| 310 return size; | |
| 292 } | 311 } |
| 293 | 312 |
| 294 void MemBackendImpl::EvictIfNeeded() { | 313 void MemBackendImpl::EvictIfNeeded() { |
| 295 if (current_size_ <= max_size_) | 314 if (current_size_ <= max_size_) |
| 296 return; | 315 return; |
| 297 | 316 |
| 298 int target_size = std::max(0, max_size_ - kDefaultEvictionSize); | 317 int target_size = std::max(0, max_size_ - kDefaultEvictionSize); |
| 299 | 318 |
| 300 base::LinkNode<MemEntryImpl>* entry = lru_list_.head(); | 319 base::LinkNode<MemEntryImpl>* entry = lru_list_.head(); |
| 301 while (current_size_ > target_size && entry != lru_list_.end()) { | 320 while (current_size_ > target_size && entry != lru_list_.end()) { |
| 302 MemEntryImpl* to_doom = entry->value(); | 321 MemEntryImpl* to_doom = entry->value(); |
| 303 entry = entry->next(); | 322 entry = entry->next(); |
| 304 if (!to_doom->InUse()) | 323 if (!to_doom->InUse()) |
| 305 to_doom->Doom(); | 324 to_doom->Doom(); |
| 306 } | 325 } |
| 307 } | 326 } |
| 308 | 327 |
| 309 } // namespace disk_cache | 328 } // namespace disk_cache |
| OLD | NEW |