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

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: nits. 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) {
michaeln 2016/04/26 22:56:25 do give people warm fuzzies, can u add DCHECK(task
ssid 2016/05/04 06:06:14 Done.
338 // Do not trace if usage is very low.
339 if (map_->bytes_used() < 1024)
340 return;
341
342 // Limit the url length to 50 and strip special characters.
343 std::string url = origin_.spec().substr(0, 50);
344 for (size_t index = 0; index < url.size(); ++index) {
345 if (!std::isalnum(url[index]))
346 url[index] = '_';
347 }
348 std::string name = StringPrintf("dom_storage/%s/%p", url.c_str(), this);
349 auto mad = pmd->CreateAllocatorDump(name + "/storage_map");
350 mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
351 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
352 map_->bytes_used());
353
354 const char* system_allocator_name =
355 base::trace_event::MemoryDumpManager::GetInstance()
356 ->system_allocator_pool_name();
357 if (system_allocator_name)
358 pmd->AddSuballocation(mad->guid(), system_allocator_name);
359 // TODO(ssid): Add memory usage of local backing storage crbug.com/605785.
360 }
361
333 void DOMStorageArea::InitialImportIfNeeded() { 362 void DOMStorageArea::InitialImportIfNeeded() {
334 if (is_initial_import_done_) 363 if (is_initial_import_done_)
335 return; 364 return;
336 365
337 DCHECK(backing_.get()); 366 DCHECK(backing_.get());
338 367
339 base::TimeTicks before = base::TimeTicks::Now(); 368 base::TimeTicks before = base::TimeTicks::Now();
340 DOMStorageValuesMap initial_values; 369 DOMStorageValuesMap initial_values;
341 backing_->ReadAllValues(&initial_values); 370 backing_->ReadAllValues(&initial_values);
342 map_->SwapValues(&initial_values); 371 map_->SwapValues(&initial_values);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 commit_batch_->clear_all_first, 504 commit_batch_->clear_all_first,
476 commit_batch_->changed_values); 505 commit_batch_->changed_values);
477 DCHECK(success); 506 DCHECK(success);
478 } 507 }
479 commit_batch_.reset(); 508 commit_batch_.reset();
480 backing_.reset(); 509 backing_.reset();
481 session_storage_backing_ = NULL; 510 session_storage_backing_ = NULL;
482 } 511 }
483 512
484 } // namespace content 513 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698