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

Unified Diff: content/browser/indexed_db/leveldb/leveldb_database.cc

Issue 1420193003: [tracing] Add IndexDB database memory usages to tracing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@leveldb
Patch Set: build fix. Created 4 years, 10 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
« no previous file with comments | « content/browser/indexed_db/leveldb/leveldb_database.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/indexed_db/leveldb/leveldb_database.cc
diff --git a/content/browser/indexed_db/leveldb/leveldb_database.cc b/content/browser/indexed_db/leveldb/leveldb_database.cc
index 8bd919e7c5dcdab04668960d24014a4862d2b711..4cb277cc346546c67ab12ac5ca40a28e5b2bf9f3 100644
--- a/content/browser/indexed_db/leveldb/leveldb_database.cc
+++ b/content/browser/indexed_db/leveldb/leveldb_database.cc
@@ -14,10 +14,13 @@
#include "base/memory/scoped_ptr.h"
#include "base/metrics/histogram.h"
#include "base/strings/string16.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_piece.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/sys_info.h"
+#include "base/trace_event/memory_dump_manager.h"
+#include "base/trace_event/process_memory_dump.h"
#include "build/build_config.h"
#include "content/browser/indexed_db/indexed_db_class_factory.h"
#include "content/browser/indexed_db/indexed_db_tracing.h"
@@ -89,6 +92,8 @@ LevelDBSnapshot::~LevelDBSnapshot() { db_->ReleaseSnapshot(snapshot_); }
LevelDBDatabase::LevelDBDatabase() {}
LevelDBDatabase::~LevelDBDatabase() {
+ base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
+ this);
// db_'s destructor uses comparator_adapter_; order of deletion is important.
CloseDatabase();
comparator_adapter_.reset();
@@ -311,6 +316,7 @@ leveldb::Status LevelDBDatabase::Open(const base::FilePath& file_name,
(*result)->comparator_adapter_ = std::move(comparator_adapter);
(*result)->comparator_ = comparator;
(*result)->filter_policy_ = std::move(filter_policy);
+ (*result)->file_name_for_tracing = file_name.BaseName().AsUTF8Unsafe();
return s;
}
@@ -340,6 +346,7 @@ scoped_ptr<LevelDBDatabase> LevelDBDatabase::OpenInMemory(
result->comparator_adapter_ = std::move(comparator_adapter);
result->comparator_ = comparator;
result->filter_policy_ = std::move(filter_policy);
+ result->file_name_for_tracing = "in-memory-database";
return result;
}
@@ -438,4 +445,29 @@ void LevelDBDatabase::Compact(const base::StringPiece& start,
void LevelDBDatabase::CompactAll() { db_->CompactRange(NULL, NULL); }
+bool LevelDBDatabase::OnMemoryDump(
+ const base::trace_event::MemoryDumpArgs& args,
+ base::trace_event::ProcessMemoryDump* pmd) {
+ if (!db_)
+ return false;
+
+ std::string value;
+ uint64_t size;
+ bool res = db_->GetProperty("leveldb.approximate-memory-usage", &value);
+ DCHECK(res);
+ base::StringToUint64(value, &size);
+
+ auto dump = pmd->CreateAllocatorDump(
+ base::StringPrintf("leveldb/index_db/%p", db_.get()));
Primiano Tucci (use gerrit) 2016/03/02 06:21:55 out of curiosity, why don't we name it just level_
ssid 2016/03/02 23:17:50 If file name is long, which is taken from websites
+ dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
+ base::trace_event::MemoryAllocatorDump::kUnitsBytes, size);
+ dump->AddString("file_name", "", file_name_for_tracing);
+
+ // Memory is allocated from system allocator (malloc).
+ pmd->AddSuballocation(dump->guid(),
+ base::trace_event::MemoryDumpManager::GetInstance()
+ ->system_allocator_pool_name());
+ return true;
+}
+
} // namespace content
« no previous file with comments | « content/browser/indexed_db/leveldb/leveldb_database.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698