Chromium Code Reviews| 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 |