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

Side by Side Diff: net/http/http_cache.cc

Issue 2661333002: Track SimpleCache memory usage in net/ MemoryDumpProvider (Closed)
Patch Set: self 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
« no previous file with comments | « net/http/http_cache.h ('k') | net/http/mock_http_cache.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/http/http_cache.h" 5 #include "net/http/http_cache.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 10 matching lines...) Expand all
21 #include "base/metrics/histogram_macros.h" 21 #include "base/metrics/histogram_macros.h"
22 #include "base/pickle.h" 22 #include "base/pickle.h"
23 #include "base/single_thread_task_runner.h" 23 #include "base/single_thread_task_runner.h"
24 #include "base/strings/string_number_conversions.h" 24 #include "base/strings/string_number_conversions.h"
25 #include "base/strings/string_util.h" 25 #include "base/strings/string_util.h"
26 #include "base/strings/stringprintf.h" 26 #include "base/strings/stringprintf.h"
27 #include "base/threading/thread_task_runner_handle.h" 27 #include "base/threading/thread_task_runner_handle.h"
28 #include "base/threading/worker_pool.h" 28 #include "base/threading/worker_pool.h"
29 #include "base/time/default_clock.h" 29 #include "base/time/default_clock.h"
30 #include "base/time/time.h" 30 #include "base/time/time.h"
31 #include "base/trace_event/memory_allocator_dump.h"
32 #include "base/trace_event/memory_usage_estimator.h"
33 #include "base/trace_event/process_memory_dump.h"
31 #include "net/base/cache_type.h" 34 #include "net/base/cache_type.h"
32 #include "net/base/io_buffer.h" 35 #include "net/base/io_buffer.h"
33 #include "net/base/load_flags.h" 36 #include "net/base/load_flags.h"
34 #include "net/base/net_errors.h" 37 #include "net/base/net_errors.h"
35 #include "net/base/upload_data_stream.h" 38 #include "net/base/upload_data_stream.h"
36 #include "net/disk_cache/disk_cache.h" 39 #include "net/disk_cache/disk_cache.h"
37 #include "net/http/disk_cache_based_quic_server_info.h" 40 #include "net/http/disk_cache_based_quic_server_info.h"
38 #include "net/http/http_cache_transaction.h" 41 #include "net/http/http_cache_transaction.h"
39 #include "net/http/http_network_layer.h" 42 #include "net/http/http_network_layer.h"
40 #include "net/http/http_network_session.h" 43 #include "net/http/http_network_session.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 doomed(false) { 102 doomed(false) {
100 } 103 }
101 104
102 HttpCache::ActiveEntry::~ActiveEntry() { 105 HttpCache::ActiveEntry::~ActiveEntry() {
103 if (disk_entry) { 106 if (disk_entry) {
104 disk_entry->Close(); 107 disk_entry->Close();
105 disk_entry = NULL; 108 disk_entry = NULL;
106 } 109 }
107 } 110 }
108 111
112 size_t HttpCache::ActiveEntry::EstimateMemoryUsage() const {
113 return base::trace_event::EstimateMemoryUsage(readers) +
114 base::trace_event::EstimateMemoryUsage(pending_queue);
115 }
116
109 //----------------------------------------------------------------------------- 117 //-----------------------------------------------------------------------------
110 118
111 // This structure keeps track of work items that are attempting to create or 119 // This structure keeps track of work items that are attempting to create or
112 // open cache entries or the backend itself. 120 // open cache entries or the backend itself.
113 struct HttpCache::PendingOp { 121 struct HttpCache::PendingOp {
114 PendingOp() : disk_entry(NULL) {} 122 PendingOp() : disk_entry(NULL) {}
115 ~PendingOp() {} 123 ~PendingOp() {}
116 124
125 // Returns the estimate of dynamically allocated memory in bytes.
126 size_t EstimateMemoryUsage() const {
127 return base::trace_event::EstimateMemoryUsage(backend) +
128 base::trace_event::EstimateMemoryUsage(writer) +
ssid 2017/02/02 19:30:01 Do we need to measure the memory used by each tran
xunjieli 2017/02/03 17:30:27 SimpleBackendImpl doesn't own the Transaction obje
129 base::trace_event::EstimateMemoryUsage(pending_queue);
130 }
131
117 disk_cache::Entry* disk_entry; 132 disk_cache::Entry* disk_entry;
118 std::unique_ptr<disk_cache::Backend> backend; 133 std::unique_ptr<disk_cache::Backend> backend;
119 std::unique_ptr<WorkItem> writer; 134 std::unique_ptr<WorkItem> writer;
120 CompletionCallback callback; // BackendCallback. 135 CompletionCallback callback; // BackendCallback.
121 WorkItemList pending_queue; 136 WorkItemList pending_queue;
122 }; 137 };
123 138
124 //----------------------------------------------------------------------------- 139 //-----------------------------------------------------------------------------
125 140
126 // The type of operation represented by a work item. 141 // The type of operation represented by a work item.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 } 186 }
172 return false; 187 return false;
173 } 188 }
174 189
175 WorkItemOperation operation() { return operation_; } 190 WorkItemOperation operation() { return operation_; }
176 void ClearTransaction() { trans_ = NULL; } 191 void ClearTransaction() { trans_ = NULL; }
177 void ClearEntry() { entry_ = NULL; } 192 void ClearEntry() { entry_ = NULL; }
178 void ClearCallback() { callback_.Reset(); } 193 void ClearCallback() { callback_.Reset(); }
179 bool Matches(Transaction* trans) const { return trans == trans_; } 194 bool Matches(Transaction* trans) const { return trans == trans_; }
180 bool IsValid() const { return trans_ || entry_ || !callback_.is_null(); } 195 bool IsValid() const { return trans_ || entry_ || !callback_.is_null(); }
196 // Returns the estimate of dynamically allocated memory in bytes.
197 size_t EstimateMemoryUsage() const { return 0; }
181 198
182 private: 199 private:
183 WorkItemOperation operation_; 200 WorkItemOperation operation_;
184 Transaction* trans_; 201 Transaction* trans_;
185 ActiveEntry** entry_; 202 ActiveEntry** entry_;
186 CompletionCallback callback_; // User callback. 203 CompletionCallback callback_; // User callback.
187 disk_cache::Backend** backend_; 204 disk_cache::Backend** backend_;
188 }; 205 };
189 206
190 //----------------------------------------------------------------------------- 207 //-----------------------------------------------------------------------------
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 491
475 std::unique_ptr<HttpTransactionFactory> 492 std::unique_ptr<HttpTransactionFactory>
476 HttpCache::SetHttpNetworkTransactionFactoryForTesting( 493 HttpCache::SetHttpNetworkTransactionFactoryForTesting(
477 std::unique_ptr<HttpTransactionFactory> new_network_layer) { 494 std::unique_ptr<HttpTransactionFactory> new_network_layer) {
478 std::unique_ptr<HttpTransactionFactory> old_network_layer( 495 std::unique_ptr<HttpTransactionFactory> old_network_layer(
479 std::move(network_layer_)); 496 std::move(network_layer_));
480 network_layer_ = std::move(new_network_layer); 497 network_layer_ = std::move(new_network_layer);
481 return old_network_layer; 498 return old_network_layer;
482 } 499 }
483 500
501 void HttpCache::DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd,
502 const std::string& parent_absolute_name) const {
503 size_t memory_estimate = 0;
504 if (disk_cache_)
505 memory_estimate += base::trace_event::EstimateMemoryUsage(disk_cache_);
506 memory_estimate +=
507 base::trace_event::EstimateMemoryUsage(active_entries_) +
508 base::trace_event::EstimateMemoryUsage(doomed_entries_) +
509 base::trace_event::EstimateMemoryUsage(playback_cache_map_) +
510 base::trace_event::EstimateMemoryUsage(pending_ops_);
511 base::trace_event::MemoryAllocatorDump* dump =
512 pmd->CreateAllocatorDump(parent_absolute_name + "/http_cache");
513 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
514 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
515 memory_estimate);
516 }
517
484 //----------------------------------------------------------------------------- 518 //-----------------------------------------------------------------------------
485 519
486 int HttpCache::CreateBackend(disk_cache::Backend** backend, 520 int HttpCache::CreateBackend(disk_cache::Backend** backend,
487 const CompletionCallback& callback) { 521 const CompletionCallback& callback) {
488 if (!backend_factory_.get()) 522 if (!backend_factory_.get())
489 return ERR_FAILED; 523 return ERR_FAILED;
490 524
491 building_backend_ = true; 525 building_backend_ = true;
492 526
493 std::unique_ptr<WorkItem> item = 527 std::unique_ptr<WorkItem> item =
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 building_backend_ = false; 1188 building_backend_ = false;
1155 DeletePendingOp(pending_op); 1189 DeletePendingOp(pending_op);
1156 } 1190 }
1157 1191
1158 // The cache may be gone when we return from the callback. 1192 // The cache may be gone when we return from the callback.
1159 if (!item->DoCallback(result, disk_cache_.get())) 1193 if (!item->DoCallback(result, disk_cache_.get()))
1160 item->NotifyTransaction(result, NULL); 1194 item->NotifyTransaction(result, NULL);
1161 } 1195 }
1162 1196
1163 } // namespace net 1197 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_cache.h ('k') | net/http/mock_http_cache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698