Commit 43f932e3 authored by Troy Hildebrandt's avatar Troy Hildebrandt Committed by Commit Bot

Give ProtoDatabase access to Level DB's approximate memory usage.

This pipes the call to GetProperty from ProtoDatabase through to
leveldb_proto LevelDB and finally onto the underlying Level DB, so we
can retrieve the value for tests and metrics.

Bug: 870813
Change-Id: I23f89685017eeae77e19c37847d6399cc8d6085f
Reviewed-on: https://chromium-review.googlesource.com/1169878
Commit-Queue: Troy Hildebrandt <thildebr@chromium.org>
Reviewed-by: default avatarTommy Nyquist <nyquist@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585252}
parent bd137b16
...@@ -93,10 +93,8 @@ leveldb::Status LevelDB::Init(const base::FilePath& database_dir, ...@@ -93,10 +93,8 @@ leveldb::Status LevelDB::Init(const base::FilePath& database_dir,
// reads/writes and the block cache should be empty. // reads/writes and the block cache should be empty.
uint64_t approx_mem = 0; uint64_t approx_mem = 0;
std::string usage_string; std::string usage_string;
if (db_->GetProperty("leveldb.approximate-memory-usage", &usage_string) && if (GetApproximateMemoryUse(&approx_mem))
base::StringToUint64(usage_string, &approx_mem)) {
approx_mem_histogram_->Add(approx_mem); approx_mem_histogram_->Add(approx_mem);
}
} }
} else { } else {
LOG(WARNING) << "Unable to open " << database_dir.value() << ": " LOG(WARNING) << "Unable to open " << database_dir.value() << ": "
...@@ -236,4 +234,10 @@ bool LevelDB::Destroy() { ...@@ -236,4 +234,10 @@ bool LevelDB::Destroy() {
return s.ok(); return s.ok();
} }
bool LevelDB::GetApproximateMemoryUse(uint64_t* approx_mem) {
std::string usage_string;
return (db_->GetProperty("leveldb.approximate-memory-usage", &usage_string) &&
base::StringToUint64(usage_string, approx_mem));
}
} // namespace leveldb_proto } // namespace leveldb_proto
...@@ -64,6 +64,10 @@ class LevelDB { ...@@ -64,6 +64,10 @@ class LevelDB {
// directory. // directory.
virtual bool Destroy(); virtual bool Destroy();
// Returns true if we successfully read the approximate memory usage property
// from the LevelDB.
bool GetApproximateMemoryUse(uint64_t* approx_mem);
private: private:
FRIEND_TEST_ALL_PREFIXES(ProtoDatabaseImplLevelDBTest, TestDBInitFail); FRIEND_TEST_ALL_PREFIXES(ProtoDatabaseImplLevelDBTest, TestDBInitFail);
......
...@@ -70,6 +70,8 @@ class ProtoDatabaseImpl : public ProtoDatabase<T> { ...@@ -70,6 +70,8 @@ class ProtoDatabaseImpl : public ProtoDatabase<T> {
const leveldb_env::Options& options, const leveldb_env::Options& options,
typename ProtoDatabase<T>::InitCallback callback); typename ProtoDatabase<T>::InitCallback callback);
bool GetApproximateMemoryUse(uint64_t* approx_mem);
private: private:
base::ThreadChecker thread_checker_; base::ThreadChecker thread_checker_;
...@@ -388,6 +390,11 @@ void ProtoDatabaseImpl<T>::GetEntry( ...@@ -388,6 +390,11 @@ void ProtoDatabaseImpl<T>::GetEntry(
std::move(entry))); std::move(entry)));
} }
template <typename T>
bool ProtoDatabaseImpl<T>::GetApproximateMemoryUse(uint64_t* approx_mem) {
return db_->GetApproximateMemoryUse(approx_mem);
}
} // namespace leveldb_proto } // namespace leveldb_proto
#endif // COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_IMPL_H_ #endif // COMPONENTS_LEVELDB_PROTO_PROTO_DATABASE_IMPL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment