Chromium Code Reviews| Index: extensions/browser/value_store/leveldb_value_store.cc |
| diff --git a/extensions/browser/value_store/leveldb_value_store.cc b/extensions/browser/value_store/leveldb_value_store.cc |
| index 39a1346df7d2c2ca41d92585254cf4401e397436..a0c35f4d2f89f73411053c1b76ce6c526ede4c56 100644 |
| --- a/extensions/browser/value_store/leveldb_value_store.cc |
| +++ b/extensions/browser/value_store/leveldb_value_store.cc |
| @@ -8,9 +8,12 @@ |
| #include "base/json/json_reader.h" |
| #include "base/json/json_writer.h" |
| #include "base/logging.h" |
| +#include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/strings/sys_string_conversions.h" |
| +#include "base/trace_event/memory_dump_manager.h" |
| +#include "base/trace_event/process_memory_dump.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "extensions/browser/value_store/value_store_util.h" |
| #include "third_party/leveldatabase/env_chromium.h" |
| @@ -59,10 +62,14 @@ LeveldbValueStore::LeveldbValueStore(const std::string& uma_client_name, |
| "Extensions.Database.Open." + uma_client_name, 1, |
| leveldb_env::LEVELDB_STATUS_MAX, leveldb_env::LEVELDB_STATUS_MAX + 1, |
| base::Histogram::kUmaTargetedHistogramFlag); |
| + base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
|
Primiano Tucci (use gerrit)
2015/10/15 08:59:53
same here about threading and unregistration
ssid
2015/10/15 15:22:04
Done.
|
| + this); |
| } |
| LeveldbValueStore::~LeveldbValueStore() { |
| DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| + base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider( |
|
Primiano Tucci (use gerrit)
2015/10/15 08:59:53
And I guess here you meant to UNregister, not re-r
ssid
2015/10/15 15:22:04
Done.
|
| + this); |
| // Delete the database from disk if it's empty (but only if we managed to |
| // open it!). This is safe on destruction, assuming that we have exclusive |
| @@ -325,6 +332,29 @@ bool LeveldbValueStore::WriteToDbForTest(leveldb::WriteBatch* batch) { |
| return !WriteToDb(batch).get(); |
| } |
| +bool LeveldbValueStore::OnMemoryDump( |
| + const base::trace_event::MemoryDumpArgs& args, |
| + base::trace_event::ProcessMemoryDump* pmd) { |
| + if (!db_) |
|
Primiano Tucci (use gerrit)
2015/10/15 08:59:53
you really need to think about threading here. Wha
ssid
2015/10/15 15:22:04
Done.
|
| + return true; |
| + |
| + std::string value; |
| + uint64 size; |
| + db_->GetProperty("leveldb.approximate-memory-usage", &value); |
| + base::StringToUint64(value, &size); |
| + |
| + base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump( |
| + base::StringPrintf("leveldb/value_store/%p", this)); |
|
Primiano Tucci (use gerrit)
2015/10/15 08:59:53
why not putting the uma_client_name or the basenam
ssid
2015/10/15 15:22:04
Done.
|
| + 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; |
| +} |
| + |
| scoped_ptr<ValueStore::Error> LeveldbValueStore::EnsureDbIsOpen() { |
| DCHECK_CURRENTLY_ON(BrowserThread::FILE); |