summaryrefslogtreecommitdiffstats
path: root/extensions/browser/value_store
diff options
context:
space:
mode:
authorssid <ssid@chromium.org>2015-11-06 03:04:05 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-06 11:04:49 +0000
commit736929d3c3722ea3d9e4d3b9493e99c003d3d712 (patch)
treed1e473cb3acb322d659d2a5769a00e3690543686 /extensions/browser/value_store
parent2183f5b2017af0330ce8387ef3ddd99d6d22b9c1 (diff)
downloadchromium_src-736929d3c3722ea3d9e4d3b9493e99c003d3d712.zip
chromium_src-736929d3c3722ea3d9e4d3b9493e99c003d3d712.tar.gz
chromium_src-736929d3c3722ea3d9e4d3b9493e99c003d3d712.tar.bz2
[tracing] Add memory statistics from level db clients to tracing.
The major clients of level database are leveldb value store (just a wrapper around leveldb). This CL adds memory statistics of the opened databases to tracing. BUG=547066 Review URL: https://codereview.chromium.org/1310513004 Cr-Commit-Position: refs/heads/master@{#358303}
Diffstat (limited to 'extensions/browser/value_store')
-rw-r--r--extensions/browser/value_store/leveldb_value_store.cc40
-rw-r--r--extensions/browser/value_store/leveldb_value_store.h8
2 files changed, 47 insertions, 1 deletions
diff --git a/extensions/browser/value_store/leveldb_value_store.cc b/extensions/browser/value_store/leveldb_value_store.cc
index 39a1346..c11e655 100644
--- a/extensions/browser/value_store/leveldb_value_store.cc
+++ b/extensions/browser/value_store/leveldb_value_store.cc
@@ -8,9 +8,13 @@
#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/thread_task_runner_handle.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 +63,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(
+ this, "LeveldbValueStore", base::ThreadTaskRunnerHandle::Get());
}
LeveldbValueStore::~LeveldbValueStore() {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
+ 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 +333,38 @@ bool LeveldbValueStore::WriteToDbForTest(leveldb::WriteBatch* batch) {
return !WriteToDb(batch).get();
}
+bool LeveldbValueStore::OnMemoryDump(
+ const base::trace_event::MemoryDumpArgs& args,
+ base::trace_event::ProcessMemoryDump* pmd) {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+
+ // Return true so that the provider is not disabled.
+ if (!db_)
+ return true;
+
+ std::string value;
+ uint64 size;
+ bool res = db_->GetProperty("leveldb.approximate-memory-usage", &value);
+ DCHECK(res);
+ res = base::StringToUint64(value, &size);
+ DCHECK(res);
+
+ auto dump = pmd->CreateAllocatorDump(
+ base::StringPrintf("leveldb/value_store/%s/%p",
+ open_histogram_->histogram_name().c_str(), this));
+ dump->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(dump->guid(), system_allocator_name);
+
+ return true;
+}
+
scoped_ptr<ValueStore::Error> LeveldbValueStore::EnsureDbIsOpen() {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
diff --git a/extensions/browser/value_store/leveldb_value_store.h b/extensions/browser/value_store/leveldb_value_store.h
index 2901660..e763714 100644
--- a/extensions/browser/value_store/leveldb_value_store.h
+++ b/extensions/browser/value_store/leveldb_value_store.h
@@ -11,6 +11,7 @@
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
+#include "base/trace_event/memory_dump_provider.h"
#include "extensions/browser/value_store/value_store.h"
#include "third_party/leveldatabase/src/include/leveldb/db.h"
@@ -20,7 +21,8 @@ class HistogramBase;
// Value store area, backed by a leveldb database.
// All methods must be run on the FILE thread.
-class LeveldbValueStore : public ValueStore {
+class LeveldbValueStore : public ValueStore,
+ public base::trace_event::MemoryDumpProvider {
public:
// Creates a database bound to |path|. The underlying database won't be
// opened (i.e. may not be created) until one of the get/set/etc methods are
@@ -56,6 +58,10 @@ class LeveldbValueStore : public ValueStore {
// corruption in the database.
bool WriteToDbForTest(leveldb::WriteBatch* batch);
+ // base::trace_event::MemoryDumpProvider implementation.
+ bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
+ base::trace_event::ProcessMemoryDump* pmd) override;
+
private:
// Tries to open the database if it hasn't been opened already.
scoped_ptr<ValueStore::Error> EnsureDbIsOpen();