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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/dom_storage/session_storage_database.cc
diff --git a/content/browser/dom_storage/session_storage_database.cc b/content/browser/dom_storage/session_storage_database.cc
index d0ab442238b5817b48761a8267e5858002ba420d..067e053591f44ec11c0ba9c09b42b6bdf831d81f 100644
--- a/content/browser/dom_storage/session_storage_database.cc
+++ b/content/browser/dom_storage/session_storage_database.cc
@@ -12,6 +12,9 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
+#include "base/thread_task_runner_handle.h"
+#include "base/trace_event/memory_dump_manager.h"
+#include "base/trace_event/process_memory_dump.h"
#include "third_party/leveldatabase/env_chromium.h"
#include "third_party/leveldatabase/src/include/leveldb/db.h"
#include "third_party/leveldatabase/src/include/leveldb/iterator.h"
@@ -95,9 +98,13 @@ SessionStorageDatabase::SessionStorageDatabase(const base::FilePath& file_path)
is_inconsistent_(false),
invalid_db_deleted_(false),
operation_count_(0) {
+ base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
+ 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
}
SessionStorageDatabase::~SessionStorageDatabase() {
+ base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
+ this);
}
void SessionStorageDatabase::ReadAreaValues(const std::string& namespace_id,
@@ -323,6 +330,32 @@ bool SessionStorageDatabase::ReadNamespacesAndOrigins(
return true;
}
+bool SessionStorageDatabase::OnMemoryDump(
+ const base::trace_event::MemoryDumpArgs& args,
+ base::trace_event::ProcessMemoryDump* pmd) {
+ if (!db_)
+ return true;
+
+ base::trace_event::MemoryAllocatorDump* dump =
+ pmd->CreateAllocatorDump("leveldb/session_storage_db");
+
+ base::AutoLock auto_lock(db_lock_);
+ std::string value;
+ uint64 size;
+ bool res = db_->GetProperty("leveldb.approximate-memory-usage", &value);
+ DCHECK(res);
+ base::StringToUint64(value, &size);
+
+ dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
+ base::trace_event::MemoryAllocatorDump::kUnitsBytes, size);
+
+ // Memory is allocated from system allocator (malloc).
+ pmd->AddSuballocation(dump->guid(),
+ base::trace_event::MemoryDumpManager::GetInstance()
+ ->system_allocator_pool_name());
+ return true;
+}
+
bool SessionStorageDatabase::LazyOpen(bool create_if_needed) {
michaeln 2015/10/15 23:55:13 This might be a better place to Register with the
base::AutoLock auto_lock(db_lock_);
if (db_error_ || is_inconsistent_) {

Powered by Google App Engine
This is Rietveld 408576698