From 36de0e535920e2d8ac70d21284587a28ed2b89a7 Mon Sep 17 00:00:00 2001 From: sdong Date: Thu, 10 Jul 2014 11:35:07 -0700 Subject: [PATCH] Add a function to return current perf level Summary: Add a function to return the perf level. It is to allow a wrapper of DB to increase the perf level and restore the original perf level after finishing the function call. Test Plan: Add a verification in db_test Reviewers: yhchiang, igor, ljin Reviewed By: ljin Subscribers: xjin, dhruba, leveldb Differential Revision: https://reviews.facebook.net/D19551 --- db/db_test.cc | 2 ++ include/rocksdb/perf_context.h | 3 +++ util/perf_context.cc | 4 ++++ 3 files changed, 9 insertions(+) diff --git a/db/db_test.cc b/db/db_test.cc index 3af33270ef..4bc2942a8d 100644 --- a/db/db_test.cc +++ b/db/db_test.cc @@ -2355,6 +2355,7 @@ TEST(DBTest, NumImmutableMemTable) { std::string big_value(1000000 * 2, 'x'); std::string num; SetPerfLevel(kEnableTime);; + ASSERT_TRUE(GetPerfLevel() == kEnableTime); ASSERT_OK(dbfull()->Put(writeOpt, handles_[1], "k1", big_value)); ASSERT_TRUE(dbfull()->GetProperty(handles_[1], @@ -2417,6 +2418,7 @@ TEST(DBTest, NumImmutableMemTable) { // break if we change the default skiplist implementation ASSERT_EQ(num, "200"); SetPerfLevel(kDisable); + ASSERT_TRUE(GetPerfLevel() == kDisable); } while (ChangeCompactOptions()); } diff --git a/include/rocksdb/perf_context.h b/include/rocksdb/perf_context.h index 0704ea2108..e96d09d2a6 100644 --- a/include/rocksdb/perf_context.h +++ b/include/rocksdb/perf_context.h @@ -20,6 +20,9 @@ enum PerfLevel { // set the perf stats level void SetPerfLevel(PerfLevel level); +// get current perf stats level +PerfLevel GetPerfLevel(); + // A thread local context for gathering performance counter efficiently // and transparently. diff --git a/util/perf_context.cc b/util/perf_context.cc index 264b10d738..5443471d5b 100644 --- a/util/perf_context.cc +++ b/util/perf_context.cc @@ -22,6 +22,10 @@ void SetPerfLevel(PerfLevel level) { perf_level = level; } +PerfLevel GetPerfLevel() { + return perf_level; +} + void PerfContext::Reset() { #if !defined(NPERF_CONTEXT) && !defined(IOS_CROSS_COMPILE) user_key_comparison_count = 0;