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

Side by Side Diff: content/browser/dom_storage/session_storage_database.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
« no previous file with comments | « content/browser/dom_storage/session_storage_database.h ('k') | no next file » | 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/session_storage_database.h" 5 #include "content/browser/dom_storage/session_storage_database.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/histogram.h" 13 #include "base/metrics/histogram.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/trace_event/memory_dump_manager.h"
18 #include "base/trace_event/process_memory_dump.h"
17 #include "third_party/leveldatabase/env_chromium.h" 19 #include "third_party/leveldatabase/env_chromium.h"
18 #include "third_party/leveldatabase/src/include/leveldb/db.h" 20 #include "third_party/leveldatabase/src/include/leveldb/db.h"
19 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" 21 #include "third_party/leveldatabase/src/include/leveldb/iterator.h"
20 #include "third_party/leveldatabase/src/include/leveldb/options.h" 22 #include "third_party/leveldatabase/src/include/leveldb/options.h"
21 #include "third_party/leveldatabase/src/include/leveldb/status.h" 23 #include "third_party/leveldatabase/src/include/leveldb/status.h"
22 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" 24 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h"
23 #include "url/gurl.h" 25 #include "url/gurl.h"
24 26
25 27
26 namespace { 28 namespace {
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 } else { 320 } else {
319 // The key is of the form "namespace-<namespaceid>-<origin>". 321 // The key is of the form "namespace-<namespaceid>-<origin>".
320 std::string origin = key.substr(current_namespace_start_key.length()); 322 std::string origin = key.substr(current_namespace_start_key.length());
321 (*namespaces_and_origins)[current_namespace_id].push_back(GURL(origin)); 323 (*namespaces_and_origins)[current_namespace_id].push_back(GURL(origin));
322 } 324 }
323 } 325 }
324 db_->ReleaseSnapshot(options.snapshot); 326 db_->ReleaseSnapshot(options.snapshot);
325 return true; 327 return true;
326 } 328 }
327 329
330 void SessionStorageDatabase::OnMemoryDump(
331 base::trace_event::ProcessMemoryDump* pmd) {
332 std::string db_memory_usage;
333 {
334 base::AutoLock lock(db_lock_);
335 if (!db_)
336 return;
337
338 bool res =
339 db_->GetProperty("leveldb.approximate-memory-usage", &db_memory_usage);
340 DCHECK(res);
341 }
342
343 uint64_t size;
344 bool res = base::StringToUint64(db_memory_usage, &size);
345 DCHECK(res);
346
347 auto mad = pmd->CreateAllocatorDump(
348 base::StringPrintf("dom_storage/session_storage_%p", this));
349 mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
350 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size);
351
352 // Memory is allocated from system allocator (malloc).
353 const char* system_allocator_name =
354 base::trace_event::MemoryDumpManager::GetInstance()
355 ->system_allocator_pool_name();
356 if (system_allocator_name)
357 pmd->AddSuballocation(mad->guid(), system_allocator_name);
358 }
359
328 bool SessionStorageDatabase::LazyOpen(bool create_if_needed) { 360 bool SessionStorageDatabase::LazyOpen(bool create_if_needed) {
329 base::AutoLock auto_lock(db_lock_); 361 base::AutoLock auto_lock(db_lock_);
330 if (db_error_ || is_inconsistent_) { 362 if (db_error_ || is_inconsistent_) {
331 // Don't try to open a database that we know has failed already. 363 // Don't try to open a database that we know has failed already.
332 return false; 364 return false;
333 } 365 }
334 if (IsOpen()) 366 if (IsOpen())
335 return true; 367 return true;
336 368
337 if (!create_if_needed && 369 if (!create_if_needed &&
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 std::string SessionStorageDatabase::MapKey(const std::string& map_id, 760 std::string SessionStorageDatabase::MapKey(const std::string& map_id,
729 const std::string& key) { 761 const std::string& key) {
730 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); 762 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str());
731 } 763 }
732 764
733 const char* SessionStorageDatabase::NextMapIdKey() { 765 const char* SessionStorageDatabase::NextMapIdKey() {
734 return "next-map-id"; 766 return "next-map-id";
735 } 767 }
736 768
737 } // namespace content 769 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/dom_storage/session_storage_database.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698