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

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

Issue 2661333002: Track SimpleCache memory usage in net/ MemoryDumpProvider (Closed)
Patch Set: self review 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) 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) +
jkarlin 2017/02/17 18:13:08 You'll need to EMU HttpCache::Transaction, which t
xunjieli 2017/02/21 15:20:39 Acknowledged. We aren't tracking ActiveEntry per o
114 base::trace_event::EstimateMemoryUsage(pending_queue);
jkarlin 2017/02/17 17:43:05 + writer ? EMU(writer) : 0
xunjieli 2017/02/21 15:20:39 Acknowledged.
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) +
129 base::trace_event::EstimateMemoryUsage(pending_queue);
jkarlin 2017/02/17 17:43:06 + disk_entry ? EMU(disk_entry) : 0
jkarlin 2017/02/17 18:03:43 Actually, don't do this. We're going to count the
xunjieli 2017/02/21 15:20:39 Acknowledged.
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.
jkarlin 2017/02/17 17:43:06 Newline above the comment
xunjieli 2017/02/21 15:20:39 Done.
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 =
504 base::trace_event::EstimateMemoryUsage(disk_cache_) +
505 base::trace_event::EstimateMemoryUsage(active_entries_) +
506 base::trace_event::EstimateMemoryUsage(doomed_entries_) +
507 base::trace_event::EstimateMemoryUsage(playback_cache_map_) +
508 base::trace_event::EstimateMemoryUsage(pending_ops_);
jkarlin 2017/02/17 17:43:06 After F2F w/ Helen we discussed that members that
xunjieli 2017/02/21 15:20:39 Acknowledged. I added a comment
509 base::trace_event::MemoryAllocatorDump* dump =
510 pmd->CreateAllocatorDump(parent_absolute_name + "/http_cache");
511 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
512 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
513 memory_estimate);
514 }
515
484 //----------------------------------------------------------------------------- 516 //-----------------------------------------------------------------------------
485 517
486 int HttpCache::CreateBackend(disk_cache::Backend** backend, 518 int HttpCache::CreateBackend(disk_cache::Backend** backend,
487 const CompletionCallback& callback) { 519 const CompletionCallback& callback) {
488 if (!backend_factory_.get()) 520 if (!backend_factory_.get())
489 return ERR_FAILED; 521 return ERR_FAILED;
490 522
491 building_backend_ = true; 523 building_backend_ = true;
492 524
493 std::unique_ptr<WorkItem> item = 525 std::unique_ptr<WorkItem> item =
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 building_backend_ = false; 1186 building_backend_ = false;
1155 DeletePendingOp(pending_op); 1187 DeletePendingOp(pending_op);
1156 } 1188 }
1157 1189
1158 // The cache may be gone when we return from the callback. 1190 // The cache may be gone when we return from the callback.
1159 if (!item->DoCallback(result, disk_cache_.get())) 1191 if (!item->DoCallback(result, disk_cache_.get()))
1160 item->NotifyTransaction(result, NULL); 1192 item->NotifyTransaction(result, NULL);
1161 } 1193 }
1162 1194
1163 } // namespace net 1195 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698