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

Unified Diff: components/leveldb_proto/leveldb_database.cc

Issue 2340983002: [tracing] Memory dump provider for leveldb_proto (Closed)
Patch Set: Created 4 years, 3 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 | « components/leveldb_proto/leveldb_database.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/leveldb_proto/leveldb_database.cc
diff --git a/components/leveldb_proto/leveldb_database.cc b/components/leveldb_proto/leveldb_database.cc
index 6a8586f87059b0697cde433968e58676a9a77004..bc628d8e3bbb2b9b6a12625903e21100f7ff1c91 100644
--- a/components/leveldb_proto/leveldb_database.cc
+++ b/components/leveldb_proto/leveldb_database.cc
@@ -4,14 +4,21 @@
#include "components/leveldb_proto/leveldb_database.h"
+#include <inttypes.h>
+
#include <string>
#include <vector>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/metrics/histogram.h"
+#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
+#include "base/strings/stringprintf.h"
+#include "base/threading/sequenced_task_runner_handle.h"
#include "base/threading/thread_checker.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/helpers/memenv/memenv.h"
#include "third_party/leveldatabase/src/include/leveldb/db.h"
@@ -42,6 +49,8 @@ LevelDB::LevelDB(const char* client_name) : open_histogram_(nullptr) {
LevelDB::~LevelDB() {
DFAKE_SCOPED_LOCK(thread_checker_);
+ base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
+ this);
}
bool LevelDB::InitWithOptions(const base::FilePath& database_dir,
@@ -62,6 +71,11 @@ bool LevelDB::InitWithOptions(const base::FilePath& database_dir,
if (status.ok()) {
CHECK(db);
db_.reset(db);
+
+ base::trace_event::MemoryDumpManager::GetInstance()
+ ->RegisterDumpProviderWithSequencedTaskRunner(
+ this, "LevelDB", base::SequencedTaskRunnerHandle::Get(),
+ base::trace_event::MemoryDumpProvider::Options());
return true;
}
@@ -144,4 +158,33 @@ bool LevelDB::Get(const std::string& key, bool* found, std::string* entry) {
return false;
}
+bool LevelDB::OnMemoryDump(const base::trace_event::MemoryDumpArgs& dump_args,
+ base::trace_event::ProcessMemoryDump* pmd) {
+ DFAKE_SCOPED_LOCK(thread_checker_);
+ 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/leveldb_proto/0x%" PRIXPTR,
+ reinterpret_cast<uintptr_t>(db_.get())));
+ dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
+ base::trace_event::MemoryAllocatorDump::kUnitsBytes, size);
+ if (open_histogram_ &&
+ dump_args.level_of_detail !=
+ base::trace_event::MemoryDumpLevelOfDetail::BACKGROUND) {
+ dump->AddString("name", "", open_histogram_->histogram_name());
DmitrySkiba 2016/09/15 17:15:59 This causes name to have "LevelDB.Open." prefix, f
ssid 2016/09/15 18:13:41 Done.
+ }
+
+ // Memory is allocated from system allocator (malloc).
+ pmd->AddSuballocation(dump->guid(),
+ base::trace_event::MemoryDumpManager::GetInstance()
+ ->system_allocator_pool_name());
+ return true;
+}
+
} // namespace leveldb_proto
« no previous file with comments | « components/leveldb_proto/leveldb_database.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698