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

Side by Side Diff: net/base/sdch_manager.cc

Issue 2541073003: Instrument SdchManager using MemoryDumpProvider (Closed)
Patch Set: Created 4 years 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/base/sdch_manager.h ('k') | net/base/sdch_manager_unittest.cc » ('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/base/sdch_manager.h" 5 #include "net/base/sdch_manager.h"
6 6
7 #include <limits.h> 7 #include <limits.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/base64url.h" 11 #include "base/base64url.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/stringprintf.h"
16 #include "base/time/default_clock.h" 17 #include "base/time/default_clock.h"
18 #include "base/trace_event/memory_allocator_dump.h"
19 #include "base/trace_event/process_memory_dump.h"
17 #include "base/values.h" 20 #include "base/values.h"
18 #include "crypto/sha2.h" 21 #include "crypto/sha2.h"
19 #include "net/base/parse_number.h" 22 #include "net/base/parse_number.h"
20 #include "net/base/sdch_net_log_params.h" 23 #include "net/base/sdch_net_log_params.h"
21 #include "net/base/sdch_observer.h" 24 #include "net/base/sdch_observer.h"
22 #include "net/url_request/url_request_http_job.h" 25 #include "net/url_request/url_request_http_job.h"
23 26
24 namespace { 27 namespace {
25 28
26 void StripTrailingDot(GURL* gurl) { 29 void StripTrailingDot(GURL* gurl) {
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 } 320 }
318 321
319 void SdchManager::AddObserver(SdchObserver* observer) { 322 void SdchManager::AddObserver(SdchObserver* observer) {
320 observers_.AddObserver(observer); 323 observers_.AddObserver(observer);
321 } 324 }
322 325
323 void SdchManager::RemoveObserver(SdchObserver* observer) { 326 void SdchManager::RemoveObserver(SdchObserver* observer) {
324 observers_.RemoveObserver(observer); 327 observers_.RemoveObserver(observer);
325 } 328 }
326 329
330 void SdchManager::DumpMemoryStats(
331 base::trace_event::ProcessMemoryDump* pmd,
332 const std::string& parent_dump_absolute_name) const {
333 std::string name = base::StringPrintf("net/sdch_manager_%p", this);
334 base::trace_event::MemoryAllocatorDump* dump = pmd->GetAllocatorDump(name);
335 if (dump == nullptr) {
336 // If there are no dictionaries stored, return early without creating a new
337 // MemoryAllocatorDump.
338 size_t total_count = dictionaries_.size();
339 if (total_count == 0)
340 return;
ssid 2016/12/15 23:00:32 I feel if you could move this to the top of the fu
xunjieli 2016/12/16 15:54:02 Done.
341 dump = pmd->CreateAllocatorDump(name);
342 size_t total_size = 0;
343 for (const auto& dictionary : dictionaries_) {
344 total_size += dictionary.second->data.text().size();
345 }
346 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
347 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
348 total_size);
349 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameObjectCount,
350 base::trace_event::MemoryAllocatorDump::kUnitsObjects,
351 total_count);
352 }
353 // Create an empty row under parent's dump so size can be attributed correctly
354 // if |this| is shared between URLRequestContexts.
355 base::trace_event::MemoryAllocatorDump* empty_row_dump =
ssid 2016/12/15 23:00:32 I really wish there was a way to add size to this
xunjieli 2016/12/16 15:54:02 Acknowledged.
356 pmd->CreateAllocatorDump(base::StringPrintf(
357 "%s/sdch_manager", parent_dump_absolute_name.c_str()));
ssid 2016/12/15 23:00:32 You could just do (parent_dump_absolute_name + "/s
xunjieli 2016/12/16 15:54:02 Done.
358 pmd->AddOwnershipEdge(empty_row_dump->guid(), dump->guid());
359 }
360
327 SdchProblemCode SdchManager::AddSdchDictionary( 361 SdchProblemCode SdchManager::AddSdchDictionary(
328 const std::string& dictionary_text, 362 const std::string& dictionary_text,
329 const GURL& dictionary_url, 363 const GURL& dictionary_url,
330 std::string* server_hash_p) { 364 std::string* server_hash_p) {
331 DCHECK(thread_checker_.CalledOnValidThread()); 365 DCHECK(thread_checker_.CalledOnValidThread());
332 std::string client_hash; 366 std::string client_hash;
333 std::string server_hash; 367 std::string server_hash;
334 GenerateHash(dictionary_text, &client_hash, &server_hash); 368 GenerateHash(dictionary_text, &client_hash, &server_hash);
335 if (dictionaries_.find(server_hash) != dictionaries_.end()) 369 if (dictionaries_.find(server_hash) != dictionaries_.end())
336 return SDCH_DICTIONARY_ALREADY_LOADED; // Already loaded. 370 return SDCH_DICTIONARY_ALREADY_LOADED; // Already loaded.
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 entry_dict->SetInteger("tries", it->second.count); 528 entry_dict->SetInteger("tries", it->second.count);
495 entry_dict->SetInteger("reason", it->second.reason); 529 entry_dict->SetInteger("reason", it->second.reason);
496 entry_list->Append(std::move(entry_dict)); 530 entry_list->Append(std::move(entry_dict));
497 } 531 }
498 value->Set("blacklisted", std::move(entry_list)); 532 value->Set("blacklisted", std::move(entry_list));
499 533
500 return std::move(value); 534 return std::move(value);
501 } 535 }
502 536
503 } // namespace net 537 } // namespace net
OLDNEW
« no previous file with comments | « net/base/sdch_manager.h ('k') | net/base/sdch_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698