Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: net/disk_cache/simple/simple_index.cc

Issue 2661333002: Track SimpleCache memory usage in net/ MemoryDumpProvider (Closed)
Patch Set: address comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/simple/simple_index.h" 5 #include "net/disk_cache/simple/simple_index.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/files/file_enumerator.h" 14 #include "base/files/file_enumerator.h"
15 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "base/metrics/field_trial.h" 18 #include "base/metrics/field_trial.h"
19 #include "base/numerics/safe_conversions.h" 19 #include "base/numerics/safe_conversions.h"
20 #include "base/pickle.h" 20 #include "base/pickle.h"
21 #include "base/strings/string_number_conversions.h" 21 #include "base/strings/string_number_conversions.h"
22 #include "base/strings/string_tokenizer.h" 22 #include "base/strings/string_tokenizer.h"
23 #include "base/task_runner.h" 23 #include "base/task_runner.h"
24 #include "base/threading/worker_pool.h" 24 #include "base/threading/worker_pool.h"
25 #include "base/time/time.h" 25 #include "base/time/time.h"
26 #include "base/trace_event/memory_usage_estimator.h"
26 #include "net/base/net_errors.h" 27 #include "net/base/net_errors.h"
27 #include "net/disk_cache/simple/simple_entry_format.h" 28 #include "net/disk_cache/simple/simple_entry_format.h"
28 #include "net/disk_cache/simple/simple_histogram_macros.h" 29 #include "net/disk_cache/simple/simple_histogram_macros.h"
29 #include "net/disk_cache/simple/simple_index_delegate.h" 30 #include "net/disk_cache/simple/simple_index_delegate.h"
30 #include "net/disk_cache/simple/simple_index_file.h" 31 #include "net/disk_cache/simple/simple_index_file.h"
31 #include "net/disk_cache/simple/simple_synchronous_entry.h" 32 #include "net/disk_cache/simple/simple_synchronous_entry.h"
32 #include "net/disk_cache/simple/simple_util.h" 33 #include "net/disk_cache/simple/simple_util.h"
33 34
34 #if defined(OS_POSIX) 35 #if defined(OS_POSIX)
35 #include <sys/stat.h> 36 #include <sys/stat.h>
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 uint64_t size = 0; 262 uint64_t size = 0;
262 for (const auto& entry : entries_set_) { 263 for (const auto& entry : entries_set_) {
263 const EntryMetadata& metadata = entry.second; 264 const EntryMetadata& metadata = entry.second;
264 base::Time entry_time = metadata.GetLastUsedTime(); 265 base::Time entry_time = metadata.GetLastUsedTime();
265 if (initial_time <= entry_time && entry_time < end_time) 266 if (initial_time <= entry_time && entry_time < end_time)
266 size += metadata.GetEntrySize(); 267 size += metadata.GetEntrySize();
267 } 268 }
268 return size; 269 return size;
269 } 270 }
270 271
272 size_t SimpleIndex::EstimateMemoryUsage() const {
273 return base::trace_event::EstimateMemoryUsage(entries_set_) +
274 base::trace_event::EstimateMemoryUsage(removed_entries_);
275 }
276
271 void SimpleIndex::Insert(uint64_t entry_hash) { 277 void SimpleIndex::Insert(uint64_t entry_hash) {
272 DCHECK(io_thread_checker_.CalledOnValidThread()); 278 DCHECK(io_thread_checker_.CalledOnValidThread());
273 // Upon insert we don't know yet the size of the entry. 279 // Upon insert we don't know yet the size of the entry.
274 // It will be updated later when the SimpleEntryImpl finishes opening or 280 // It will be updated later when the SimpleEntryImpl finishes opening or
275 // creating the new entry, and then UpdateEntrySize will be called. 281 // creating the new entry, and then UpdateEntrySize will be called.
276 InsertInEntrySet(entry_hash, EntryMetadata(base::Time::Now(), 0u), 282 InsertInEntrySet(entry_hash, EntryMetadata(base::Time::Now(), 0u),
277 &entries_set_); 283 &entries_set_);
278 if (!initialized_) 284 if (!initialized_)
279 removed_entries_.erase(entry_hash); 285 removed_entries_.erase(entry_hash);
280 PostponeWritingToDisk(); 286 PostponeWritingToDisk();
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 start - last_write_to_disk_); 524 start - last_write_to_disk_);
519 } 525 }
520 } 526 }
521 last_write_to_disk_ = start; 527 last_write_to_disk_ = start;
522 528
523 index_file_->WriteToDisk(reason, entries_set_, cache_size_, start, 529 index_file_->WriteToDisk(reason, entries_set_, cache_size_, start,
524 app_on_background_, base::Closure()); 530 app_on_background_, base::Closure());
525 } 531 }
526 532
527 } // namespace disk_cache 533 } // namespace disk_cache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698