diff options
author | cmumford <cmumford@chromium.org> | 2015-07-13 16:52:55 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-13 23:53:28 +0000 |
commit | 488167c188c92f291a9a7c21c26e44b9f3c654ad (patch) | |
tree | cdef102a55f2c511bb919011fd1176d6dba34ded /extensions/browser/value_store | |
parent | 6ceefd2e4a8a04218995580534479a0dbd328404 (diff) | |
download | chromium_src-488167c188c92f291a9a7c21c26e44b9f3c654ad.zip chromium_src-488167c188c92f291a9a7c21c26e44b9f3c654ad.tar.gz chromium_src-488167c188c92f291a9a7c21c26e44b9f3c654ad.tar.bz2 |
Added UMA statistics logging for extensions leveldb open use.
Added leveldb usage (currently only db open) statistics reporting for
several extensions storage backends. These will be logged as:
Extensions.Database.Open.Settings
Extensions.Database.Open.State
Extensions.Database.Open.Rules
BUG=508330
Review URL: https://codereview.chromium.org/1229193002
Cr-Commit-Position: refs/heads/master@{#338596}
Diffstat (limited to 'extensions/browser/value_store')
6 files changed, 41 insertions, 15 deletions
diff --git a/extensions/browser/value_store/leveldb_value_store.cc b/extensions/browser/value_store/leveldb_value_store.cc index 0db63a17..39a1346 100644 --- a/extensions/browser/value_store/leveldb_value_store.cc +++ b/extensions/browser/value_store/leveldb_value_store.cc @@ -48,9 +48,17 @@ class ScopedSnapshot { } // namespace -LeveldbValueStore::LeveldbValueStore(const base::FilePath& db_path) - : db_path_(db_path) { +LeveldbValueStore::LeveldbValueStore(const std::string& uma_client_name, + const base::FilePath& db_path) + : db_path_(db_path), open_histogram_(nullptr) { DCHECK_CURRENTLY_ON(BrowserThread::FILE); + + // Used in lieu of UMA_HISTOGRAM_ENUMERATION because the histogram name is + // not a constant. + open_histogram_ = base::LinearHistogram::FactoryGet( + "Extensions.Database.Open." + uma_client_name, 1, + leveldb_env::LEVELDB_STATUS_MAX, leveldb_env::LEVELDB_STATUS_MAX + 1, + base::Histogram::kUmaTargetedHistogramFlag); } LeveldbValueStore::~LeveldbValueStore() { @@ -331,6 +339,8 @@ scoped_ptr<ValueStore::Error> LeveldbValueStore::EnsureDbIsOpen() { leveldb::DB* db = NULL; leveldb::Status status = leveldb::DB::Open(options, db_path_.AsUTF8Unsafe(), &db); + if (open_histogram_) + open_histogram_->Add(leveldb_env::GetLevelDBStatusUMAValue(status)); if (!status.ok()) return ToValueStoreError(status, util::NoKey()); diff --git a/extensions/browser/value_store/leveldb_value_store.h b/extensions/browser/value_store/leveldb_value_store.h index e94e391..2901660 100644 --- a/extensions/browser/value_store/leveldb_value_store.h +++ b/extensions/browser/value_store/leveldb_value_store.h @@ -14,6 +14,10 @@ #include "extensions/browser/value_store/value_store.h" #include "third_party/leveldatabase/src/include/leveldb/db.h" +namespace base { +class HistogramBase; +} // namespace base + // Value store area, backed by a leveldb database. // All methods must be run on the FILE thread. class LeveldbValueStore : public ValueStore { @@ -24,7 +28,8 @@ class LeveldbValueStore : public ValueStore { // need to be notified of that, but we don't want to permanently give up. // // Must be created on the FILE thread. - explicit LeveldbValueStore(const base::FilePath& path); + LeveldbValueStore(const std::string& uma_client_name, + const base::FilePath& path); // Must be deleted on the FILE thread. ~LeveldbValueStore() override; @@ -91,6 +96,7 @@ class LeveldbValueStore : public ValueStore { // leveldb backend. scoped_ptr<leveldb::DB> db_; + base::HistogramBase* open_histogram_; DISALLOW_COPY_AND_ASSIGN(LeveldbValueStore); }; diff --git a/extensions/browser/value_store/leveldb_value_store_unittest.cc b/extensions/browser/value_store/leveldb_value_store_unittest.cc index 3c0fd53..0604499 100644 --- a/extensions/browser/value_store/leveldb_value_store_unittest.cc +++ b/extensions/browser/value_store/leveldb_value_store_unittest.cc @@ -18,8 +18,10 @@ namespace { +const char kDatabaseUMAClientName[] = "Test"; + ValueStore* Param(const base::FilePath& file_path) { - return new LeveldbValueStore(file_path); + return new LeveldbValueStore(kDatabaseUMAClientName, file_path); } } // namespace @@ -48,7 +50,10 @@ class LeveldbValueStoreUnitTest : public testing::Test { void CloseStore() { store_.reset(); } - void OpenStore() { store_.reset(new LeveldbValueStore(database_path())); } + void OpenStore() { + store_.reset( + new LeveldbValueStore(kDatabaseUMAClientName, database_path())); + } LeveldbValueStore* store() { return store_.get(); } const base::FilePath& database_path() { return database_dir_.path(); } diff --git a/extensions/browser/value_store/value_store_frontend.cc b/extensions/browser/value_store/value_store_frontend.cc index 41ebf13..33cdce7 100644 --- a/extensions/browser/value_store/value_store_frontend.cc +++ b/extensions/browser/value_store/value_store_frontend.cc @@ -17,12 +17,12 @@ class ValueStoreFrontend::Backend : public base::RefCountedThreadSafe<Backend> { public: Backend() : storage_(NULL) {} - void Init(const base::FilePath& db_path) { + void Init(const std::string& uma_client_name, const base::FilePath& db_path) { DCHECK_CURRENTLY_ON(BrowserThread::FILE); DCHECK(!storage_); TRACE_EVENT0("ValueStoreFrontend::Backend", "Init"); db_path_ = db_path; - storage_ = new LeveldbValueStore(db_path); + storage_ = new LeveldbValueStore(uma_client_name, db_path); } // This variant is useful for testing (using a mock ValueStore). @@ -98,9 +98,10 @@ ValueStoreFrontend::ValueStoreFrontend() : backend_(new Backend()) { } -ValueStoreFrontend::ValueStoreFrontend(const base::FilePath& db_path) +ValueStoreFrontend::ValueStoreFrontend(const std::string& uma_client_name, + const base::FilePath& db_path) : backend_(new Backend()) { - Init(db_path); + Init(uma_client_name, db_path); } ValueStoreFrontend::ValueStoreFrontend(scoped_ptr<ValueStore> value_store) @@ -114,10 +115,11 @@ ValueStoreFrontend::~ValueStoreFrontend() { DCHECK(CalledOnValidThread()); } -void ValueStoreFrontend::Init(const base::FilePath& db_path) { +void ValueStoreFrontend::Init(const std::string& uma_client_name, + const base::FilePath& db_path) { BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, - base::Bind(&ValueStoreFrontend::Backend::Init, - backend_, db_path)); + base::Bind(&ValueStoreFrontend::Backend::Init, + backend_, uma_client_name, db_path)); } void ValueStoreFrontend::Get(const std::string& key, diff --git a/extensions/browser/value_store/value_store_frontend.h b/extensions/browser/value_store/value_store_frontend.h index 1b93c7f..8eb1c1c 100644 --- a/extensions/browser/value_store/value_store_frontend.h +++ b/extensions/browser/value_store/value_store_frontend.h @@ -27,12 +27,13 @@ class ValueStoreFrontend typedef base::Callback<void(scoped_ptr<base::Value>)> ReadCallback; ValueStoreFrontend(); - explicit ValueStoreFrontend(const base::FilePath& db_path); + ValueStoreFrontend(const std::string& uma_client_name, + const base::FilePath& db_path); // This variant is useful for testing (using a mock ValueStore). explicit ValueStoreFrontend(scoped_ptr<ValueStore> value_store); ~ValueStoreFrontend(); - void Init(const base::FilePath& db_path); + void Init(const std::string& uma_client_name, const base::FilePath& db_path); // Retrieves a value from the database asynchronously, passing a copy to // |callback| when ready. NULL is passed if no matching entry is found. diff --git a/extensions/browser/value_store/value_store_frontend_unittest.cc b/extensions/browser/value_store/value_store_frontend_unittest.cc index c3e6f85..be65b7b 100644 --- a/extensions/browser/value_store/value_store_frontend_unittest.cc +++ b/extensions/browser/value_store/value_store_frontend_unittest.cc @@ -14,6 +14,8 @@ using content::BrowserThread; +const char kDatabaseUMAClientName[] = "Test"; + class ValueStoreFrontendTest : public testing::Test { public: ValueStoreFrontendTest() @@ -40,7 +42,7 @@ class ValueStoreFrontendTest : public testing::Test { // Reset the value store, reloading the DB from disk. void ResetStorage() { - storage_.reset(new ValueStoreFrontend(db_path_)); + storage_.reset(new ValueStoreFrontend(kDatabaseUMAClientName, db_path_)); } bool Get(const std::string& key, scoped_ptr<base::Value>* output) { |