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

Side by Side Diff: net/spdy/spdy_header_block.cc

Issue 2665283003: Improve memory estimate of SpdySessionPool in net/ MemoryDumpProvider. (Closed)
Patch Set: rebased 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/spdy/spdy_header_block.h ('k') | net/spdy/spdy_protocol.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/spdy/spdy_header_block.h" 5 #include "net/spdy/spdy_header_block.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <utility> 10 #include <utility>
11 11
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "net/base/arena.h" 15 #include "net/base/arena.h"
16 #include "net/http/http_log_util.h" 16 #include "net/http/http_log_util.h"
17 #include "net/log/net_log_capture_mode.h" 17 #include "net/log/net_log_capture_mode.h"
18 #include "net/spdy/platform/api/spdy_estimate_memory_usage.h"
18 19
19 using base::StringPiece; 20 using base::StringPiece;
20 using std::dec; 21 using std::dec;
21 using std::hex; 22 using std::hex;
22 using std::make_pair; 23 using std::make_pair;
23 using std::max; 24 using std::max;
24 using std::min; 25 using std::min;
25 using std::string; 26 using std::string;
26 27
27 namespace net { 28 namespace net {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 total_size += fragment.size(); 83 total_size += fragment.size();
83 } 84 }
84 char* dst = arena_.Alloc(total_size); 85 char* dst = arena_.Alloc(total_size);
85 size_t written = Join(dst, fragments, separator); 86 size_t written = Join(dst, fragments, separator);
86 DCHECK_EQ(written, total_size); 87 DCHECK_EQ(written, total_size);
87 return StringPiece(dst, total_size); 88 return StringPiece(dst, total_size);
88 } 89 }
89 90
90 size_t bytes_allocated() const { return arena_.status().bytes_allocated(); } 91 size_t bytes_allocated() const { return arena_.status().bytes_allocated(); }
91 92
93 // TODO(xunjieli): https://crbug.com/669108. Merge this with bytes_allocated()
94 size_t EstimateMemoryUsage() const {
95 return arena_.status().bytes_allocated();
96 }
97
92 private: 98 private:
93 UnsafeArena arena_; 99 UnsafeArena arena_;
94 }; 100 };
95 101
96 SpdyHeaderBlock::HeaderValue::HeaderValue(Storage* storage, 102 SpdyHeaderBlock::HeaderValue::HeaderValue(Storage* storage,
97 StringPiece key, 103 StringPiece key,
98 StringPiece initial_value) 104 StringPiece initial_value)
99 : storage_(storage), fragments_({initial_value}), pair_({key, {}}) {} 105 : storage_(storage), fragments_({initial_value}), pair_({key, {}}) {}
100 106
101 SpdyHeaderBlock::HeaderValue::HeaderValue(HeaderValue&& other) 107 SpdyHeaderBlock::HeaderValue::HeaderValue(HeaderValue&& other)
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 auto iter = block_.find(key); 298 auto iter = block_.find(key);
293 if (iter == block_.end()) { 299 if (iter == block_.end()) {
294 DVLOG(1) << "Inserting: (" << key << ", " << value << ")"; 300 DVLOG(1) << "Inserting: (" << key << ", " << value << ")";
295 AppendHeader(key, value); 301 AppendHeader(key, value);
296 return; 302 return;
297 } 303 }
298 DVLOG(1) << "Updating key: " << iter->first << "; appending value: " << value; 304 DVLOG(1) << "Updating key: " << iter->first << "; appending value: " << value;
299 iter->second.Append(GetStorage()->Write(value)); 305 iter->second.Append(GetStorage()->Write(value));
300 } 306 }
301 307
308 size_t SpdyHeaderBlock::EstimateMemoryUsage() const {
309 // TODO(xunjieli): https://crbug.com/669108. Also include |block_| when EMU()
310 // supports linked_hash_map.
311 return SpdyEstimateMemoryUsage(storage_);
312 }
313
302 void SpdyHeaderBlock::AppendHeader(const StringPiece key, 314 void SpdyHeaderBlock::AppendHeader(const StringPiece key,
303 const StringPiece value) { 315 const StringPiece value) {
304 auto storage = GetStorage(); 316 auto storage = GetStorage();
305 auto backed_key = storage->Write(key); 317 auto backed_key = storage->Write(key);
306 block_.emplace(make_pair( 318 block_.emplace(make_pair(
307 backed_key, HeaderValue(storage, backed_key, storage->Write(value)))); 319 backed_key, HeaderValue(storage, backed_key, storage->Write(value))));
308 } 320 }
309 321
310 SpdyHeaderBlock::Storage* SpdyHeaderBlock::GetStorage() { 322 SpdyHeaderBlock::Storage* SpdyHeaderBlock::GetStorage() {
311 if (!storage_) { 323 if (!storage_) {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 for (++it; it != fragments.end(); ++it) { 389 for (++it; it != fragments.end(); ++it) {
378 memcpy(dst, separator.data(), separator.size()); 390 memcpy(dst, separator.data(), separator.size());
379 dst += separator.size(); 391 dst += separator.size();
380 memcpy(dst, it->data(), it->size()); 392 memcpy(dst, it->data(), it->size());
381 dst += it->size(); 393 dst += it->size();
382 } 394 }
383 return dst - original_dst; 395 return dst - original_dst;
384 } 396 }
385 397
386 } // namespace net 398 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_header_block.h ('k') | net/spdy/spdy_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698