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

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

Issue 1310513004: [tracing] Add memory statistics from level db clients to tracing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@skia_res
Patch Set: Fix double lock. Created 5 years, 2 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/session_storage_database.h" 5 #include "content/browser/dom_storage/session_storage_database.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/thread_task_runner_handle.h"
16 #include "base/trace_event/memory_dump_manager.h"
17 #include "base/trace_event/process_memory_dump.h"
15 #include "third_party/leveldatabase/env_chromium.h" 18 #include "third_party/leveldatabase/env_chromium.h"
16 #include "third_party/leveldatabase/src/include/leveldb/db.h" 19 #include "third_party/leveldatabase/src/include/leveldb/db.h"
17 #include "third_party/leveldatabase/src/include/leveldb/iterator.h" 20 #include "third_party/leveldatabase/src/include/leveldb/iterator.h"
18 #include "third_party/leveldatabase/src/include/leveldb/options.h" 21 #include "third_party/leveldatabase/src/include/leveldb/options.h"
19 #include "third_party/leveldatabase/src/include/leveldb/status.h" 22 #include "third_party/leveldatabase/src/include/leveldb/status.h"
20 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" 23 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h"
21 #include "url/gurl.h" 24 #include "url/gurl.h"
22 25
23 26
24 namespace { 27 namespace {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 SessionStorageDatabase* session_storage_database_; 91 SessionStorageDatabase* session_storage_database_;
89 }; 92 };
90 93
91 94
92 SessionStorageDatabase::SessionStorageDatabase(const base::FilePath& file_path) 95 SessionStorageDatabase::SessionStorageDatabase(const base::FilePath& file_path)
93 : file_path_(file_path), 96 : file_path_(file_path),
94 db_error_(false), 97 db_error_(false),
95 is_inconsistent_(false), 98 is_inconsistent_(false),
96 invalid_db_deleted_(false), 99 invalid_db_deleted_(false),
97 operation_count_(0) { 100 operation_count_(0) {
101 base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
102 this, base::ThreadTaskRunnerHandle::Get());
michaeln 2015/10/15 23:55:13 The threading needs some work. This class is creat
Primiano Tucci (use gerrit) 2015/10/16 09:10:34 There are mainly two reason why I restricted the m
98 } 103 }
99 104
100 SessionStorageDatabase::~SessionStorageDatabase() { 105 SessionStorageDatabase::~SessionStorageDatabase() {
106 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
107 this);
101 } 108 }
102 109
103 void SessionStorageDatabase::ReadAreaValues(const std::string& namespace_id, 110 void SessionStorageDatabase::ReadAreaValues(const std::string& namespace_id,
104 const GURL& origin, 111 const GURL& origin,
105 DOMStorageValuesMap* result) { 112 DOMStorageValuesMap* result) {
106 // We don't create a database if it doesn't exist. In that case, there is 113 // We don't create a database if it doesn't exist. In that case, there is
107 // nothing to be added to the result. 114 // nothing to be added to the result.
108 if (!LazyOpen(false)) 115 if (!LazyOpen(false))
109 return; 116 return;
110 DBOperation operation(this); 117 DBOperation operation(this);
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } else { 323 } else {
317 // The key is of the form "namespace-<namespaceid>-<origin>". 324 // The key is of the form "namespace-<namespaceid>-<origin>".
318 std::string origin = key.substr(current_namespace_start_key.length()); 325 std::string origin = key.substr(current_namespace_start_key.length());
319 (*namespaces_and_origins)[current_namespace_id].push_back(GURL(origin)); 326 (*namespaces_and_origins)[current_namespace_id].push_back(GURL(origin));
320 } 327 }
321 } 328 }
322 db_->ReleaseSnapshot(options.snapshot); 329 db_->ReleaseSnapshot(options.snapshot);
323 return true; 330 return true;
324 } 331 }
325 332
333 bool SessionStorageDatabase::OnMemoryDump(
334 const base::trace_event::MemoryDumpArgs& args,
335 base::trace_event::ProcessMemoryDump* pmd) {
336 if (!db_)
337 return true;
338
339 base::trace_event::MemoryAllocatorDump* dump =
340 pmd->CreateAllocatorDump("leveldb/session_storage_db");
341
342 base::AutoLock auto_lock(db_lock_);
343 std::string value;
344 uint64 size;
345 bool res = db_->GetProperty("leveldb.approximate-memory-usage", &value);
346 DCHECK(res);
347 base::StringToUint64(value, &size);
348
349 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
350 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size);
351
352 // Memory is allocated from system allocator (malloc).
353 pmd->AddSuballocation(dump->guid(),
354 base::trace_event::MemoryDumpManager::GetInstance()
355 ->system_allocator_pool_name());
356 return true;
357 }
358
326 bool SessionStorageDatabase::LazyOpen(bool create_if_needed) { 359 bool SessionStorageDatabase::LazyOpen(bool create_if_needed) {
michaeln 2015/10/15 23:55:13 This might be a better place to Register with the
327 base::AutoLock auto_lock(db_lock_); 360 base::AutoLock auto_lock(db_lock_);
328 if (db_error_ || is_inconsistent_) { 361 if (db_error_ || is_inconsistent_) {
329 // Don't try to open a database that we know has failed already. 362 // Don't try to open a database that we know has failed already.
330 return false; 363 return false;
331 } 364 }
332 if (IsOpen()) 365 if (IsOpen())
333 return true; 366 return true;
334 367
335 if (!create_if_needed && 368 if (!create_if_needed &&
336 (!base::PathExists(file_path_) || base::IsDirectoryEmpty(file_path_))) { 369 (!base::PathExists(file_path_) || base::IsDirectoryEmpty(file_path_))) {
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 std::string SessionStorageDatabase::MapKey(const std::string& map_id, 754 std::string SessionStorageDatabase::MapKey(const std::string& map_id,
722 const std::string& key) { 755 const std::string& key) {
723 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str()); 756 return base::StringPrintf("map-%s-%s", map_id.c_str(), key.c_str());
724 } 757 }
725 758
726 const char* SessionStorageDatabase::NextMapIdKey() { 759 const char* SessionStorageDatabase::NextMapIdKey() {
727 return "next-map-id"; 760 return "next-map-id";
728 } 761 }
729 762
730 } // namespace content 763 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698