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

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

Issue 1906243002: [tracing] Add a memory dump provider for DOM storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix dcheck and return value. Created 4 years, 7 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 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 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/location.h" 11 #include "base/location.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
13 #include "base/process/process_info.h" 14 #include "base/process/process_info.h"
15 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "base/trace_event/memory_dump_manager.h"
19 #include "base/trace_event/process_memory_dump.h"
16 #include "content/browser/dom_storage/dom_storage_namespace.h" 20 #include "content/browser/dom_storage/dom_storage_namespace.h"
17 #include "content/browser/dom_storage/dom_storage_task_runner.h" 21 #include "content/browser/dom_storage/dom_storage_task_runner.h"
18 #include "content/browser/dom_storage/local_storage_database_adapter.h" 22 #include "content/browser/dom_storage/local_storage_database_adapter.h"
19 #include "content/browser/dom_storage/session_storage_database.h" 23 #include "content/browser/dom_storage/session_storage_database.h"
20 #include "content/browser/dom_storage/session_storage_database_adapter.h" 24 #include "content/browser/dom_storage/session_storage_database_adapter.h"
21 #include "content/common/dom_storage/dom_storage_map.h" 25 #include "content/common/dom_storage/dom_storage_map.h"
22 #include "content/common/dom_storage/dom_storage_types.h" 26 #include "content/common/dom_storage/dom_storage_types.h"
23 #include "content/public/browser/browser_thread.h" 27 #include "content/public/browser/browser_thread.h"
24 #include "storage/browser/database/database_util.h" 28 #include "storage/browser/database/database_util.h"
25 #include "storage/common/database/database_identifier.h" 29 #include "storage/common/database/database_identifier.h"
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 if (!backing_) 327 if (!backing_)
324 return; 328 return;
325 329
326 bool success = task_runner_->PostShutdownBlockingTask( 330 bool success = task_runner_->PostShutdownBlockingTask(
327 FROM_HERE, 331 FROM_HERE,
328 DOMStorageTaskRunner::COMMIT_SEQUENCE, 332 DOMStorageTaskRunner::COMMIT_SEQUENCE,
329 base::Bind(&DOMStorageArea::ShutdownInCommitSequence, this)); 333 base::Bind(&DOMStorageArea::ShutdownInCommitSequence, this));
330 DCHECK(success); 334 DCHECK(success);
331 } 335 }
332 336
337 void DOMStorageArea::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) {
338 DCHECK(task_runner_->IsRunningOnPrimarySequence());
339 // Do not trace if usage is very low.
340 if (map_->bytes_used() < 1024)
341 return;
342
343 // Limit the url length to 50 and strip special characters.
344 std::string url = origin_.spec().substr(0, 50);
345 for (size_t index = 0; index < url.size(); ++index) {
346 if (!std::isalnum(url[index]))
347 url[index] = '_';
348 }
349 std::string name = StringPrintf("dom_storage/%s/%p", url.c_str(), this);
350 auto mad = pmd->CreateAllocatorDump(name + "/storage_map");
351 mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
352 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
353 map_->bytes_used());
354
355 const char* system_allocator_name =
356 base::trace_event::MemoryDumpManager::GetInstance()
357 ->system_allocator_pool_name();
358 if (system_allocator_name)
359 pmd->AddSuballocation(mad->guid(), system_allocator_name);
360 // TODO(ssid): Add memory usage of local backing storage crbug.com/605785.
361 }
362
333 void DOMStorageArea::InitialImportIfNeeded() { 363 void DOMStorageArea::InitialImportIfNeeded() {
334 if (is_initial_import_done_) 364 if (is_initial_import_done_)
335 return; 365 return;
336 366
337 DCHECK(backing_.get()); 367 DCHECK(backing_.get());
338 368
339 base::TimeTicks before = base::TimeTicks::Now(); 369 base::TimeTicks before = base::TimeTicks::Now();
340 DOMStorageValuesMap initial_values; 370 DOMStorageValuesMap initial_values;
341 backing_->ReadAllValues(&initial_values); 371 backing_->ReadAllValues(&initial_values);
342 map_->SwapValues(&initial_values); 372 map_->SwapValues(&initial_values);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 commit_batch_->clear_all_first, 505 commit_batch_->clear_all_first,
476 commit_batch_->changed_values); 506 commit_batch_->changed_values);
477 DCHECK(success); 507 DCHECK(success);
478 } 508 }
479 commit_batch_.reset(); 509 commit_batch_.reset();
480 backing_.reset(); 510 backing_.reset();
481 session_storage_backing_ = NULL; 511 session_storage_backing_ = NULL;
482 } 512 }
483 513
484 } // namespace content 514 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/dom_storage/dom_storage_area.h ('k') | content/browser/dom_storage/dom_storage_context_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698