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

Unified 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 unittests. Created 4 years, 8 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 ae90b0fcc669405433e00f75ad7fd0ad28216888..1b651a68c39b277c49c9db5c869bf2f4ed61e813 100644
--- a/content/browser/dom_storage/session_storage_database.cc
+++ b/content/browser/dom_storage/session_storage_database.cc
@@ -14,6 +14,8 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.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"
@@ -325,6 +327,38 @@ bool SessionStorageDatabase::ReadNamespacesAndOrigins(
return true;
}
+bool SessionStorageDatabase::OnMemoryDump(
+ base::trace_event::ProcessMemoryDump* pmd) {
+ std::string db_memory_usage;
+ {
+ base::AutoLock lock(db_lock_);
+ // Return true if |db_| is null to prevent the dump provider from being
+ // disabled, since it can be created lazily.
+ if (!db_)
+ return true;
+
+ bool res =
+ db_->GetProperty("leveldb.approximate-memory-usage", &db_memory_usage);
+ DCHECK(res);
+ }
+
+ uint64_t size;
+ bool res = base::StringToUint64(db_memory_usage, &size);
+ DCHECK(res);
+
+ auto mad = pmd->CreateAllocatorDump(
+ base::StringPrintf("dom_storage/session_storage_%p", this));
+ mad->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
+ base::trace_event::MemoryAllocatorDump::kUnitsBytes, size);
+
+ // Memory is allocated from system allocator (malloc).
+ const char* system_allocator_name =
+ base::trace_event::MemoryDumpManager::GetInstance()
+ ->system_allocator_pool_name();
+ if (system_allocator_name)
+ pmd->AddSuballocation(mad->guid(), system_allocator_name);
+ return true;
+}
bool SessionStorageDatabase::LazyOpen(bool create_if_needed) {
base::AutoLock auto_lock(db_lock_);
if (db_error_ || is_inconsistent_) {

Powered by Google App Engine
This is Rietveld 408576698