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

Side by Side Diff: content/browser/dom_storage/dom_storage_area.cc

Issue 1950893003: [tracing] Support background mode in dom storage memory dumps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dom_storage
Patch Set: Created 4 years, 6 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 | « no previous file | content/browser/dom_storage/dom_storage_context_impl.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "content/browser/dom_storage/dom_storage_area.h" 5 #include "content/browser/dom_storage/dom_storage_area.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cctype> // for std::isalnum 8 #include <cctype> // for std::isalnum
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 331
332 bool success = task_runner_->PostShutdownBlockingTask( 332 bool success = task_runner_->PostShutdownBlockingTask(
333 FROM_HERE, 333 FROM_HERE,
334 DOMStorageTaskRunner::COMMIT_SEQUENCE, 334 DOMStorageTaskRunner::COMMIT_SEQUENCE,
335 base::Bind(&DOMStorageArea::ShutdownInCommitSequence, this)); 335 base::Bind(&DOMStorageArea::ShutdownInCommitSequence, this));
336 DCHECK(success); 336 DCHECK(success);
337 } 337 }
338 338
339 void DOMStorageArea::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) { 339 void DOMStorageArea::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) {
340 DCHECK(task_runner_->IsRunningOnPrimarySequence()); 340 DCHECK(task_runner_->IsRunningOnPrimarySequence());
341 // Do not trace if usage is very low. 341 if (!is_initial_import_done_)
342 if (map_->bytes_used() < 1024)
343 return; 342 return;
344 343
345 // Limit the url length to 50 and strip special characters. 344 // Limit the url length to 50 and strip special characters.
346 std::string url = origin_.spec().substr(0, 50); 345 std::string url = origin_.spec().substr(0, 50);
347 for (size_t index = 0; index < url.size(); ++index) { 346 for (size_t index = 0; index < url.size(); ++index) {
348 if (!std::isalnum(url[index])) 347 if (!std::isalnum(url[index]))
349 url[index] = '_'; 348 url[index] = '_';
350 } 349 }
351 std::string name = StringPrintf("dom_storage/%s/%p", url.c_str(), this); 350 std::string name = StringPrintf("dom_storage/%s/%p", url.c_str(), this);
352 auto mad = pmd->CreateAllocatorDump(name + "/storage_map");
353 mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
354 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
355 map_->bytes_used());
356 351
357 const char* system_allocator_name = 352 const char* system_allocator_name =
358 base::trace_event::MemoryDumpManager::GetInstance() 353 base::trace_event::MemoryDumpManager::GetInstance()
359 ->system_allocator_pool_name(); 354 ->system_allocator_pool_name();
355 if (commit_batch_) {
356 auto commit_batch_mad = pmd->CreateAllocatorDump(name + "/commit_batch");
357 commit_batch_mad->AddScalar(
358 base::trace_event::MemoryAllocatorDump::kNameSize,
359 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
360 commit_batch_->GetDataSize());
361 if (system_allocator_name)
362 pmd->AddSuballocation(commit_batch_mad->guid(), system_allocator_name);
363 }
364
365 // Do not add storage map usage if less than 1KB.
366 if (map_->bytes_used() < 1024)
367 return;
368
369 auto map_mad = pmd->CreateAllocatorDump(name + "/storage_map");
370 map_mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
371 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
372 map_->bytes_used());
360 if (system_allocator_name) 373 if (system_allocator_name)
361 pmd->AddSuballocation(mad->guid(), system_allocator_name); 374 pmd->AddSuballocation(map_mad->guid(), system_allocator_name);
362 // TODO(ssid): Add memory usage of local backing storage crbug.com/605785. 375 // TODO(ssid): Add memory usage of local backing storage crbug.com/605785.
363 } 376 }
364 377
365 void DOMStorageArea::InitialImportIfNeeded() { 378 void DOMStorageArea::InitialImportIfNeeded() {
366 if (is_initial_import_done_) 379 if (is_initial_import_done_)
367 return; 380 return;
368 381
369 DCHECK(backing_.get()); 382 DCHECK(backing_.get());
370 383
371 base::TimeTicks before = base::TimeTicks::Now(); 384 base::TimeTicks before = base::TimeTicks::Now();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 commit_batch_->clear_all_first, 520 commit_batch_->clear_all_first,
508 commit_batch_->changed_values); 521 commit_batch_->changed_values);
509 DCHECK(success); 522 DCHECK(success);
510 } 523 }
511 commit_batch_.reset(); 524 commit_batch_.reset();
512 backing_.reset(); 525 backing_.reset();
513 session_storage_backing_ = NULL; 526 session_storage_backing_ = NULL;
514 } 527 }
515 528
516 } // namespace content 529 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/dom_storage/dom_storage_context_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698