From 678503ebcfc133442e69bace54e517296071c1ac Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Wed, 4 Feb 2015 01:47:32 -0800 Subject: [PATCH] Add utility functions for interpreting ThreadStatus Summary: Add ThreadStatus::GetOperationName() and ThreadStatus::GetStateName(), two utility functions that help interpreting ThreadStatus. Test Plan: ./thread_list_test Reviewers: sdong, rven, igor Reviewed By: igor Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D32793 --- include/rocksdb/thread_status.h | 10 +++++++++ util/thread_list_test.cc | 6 ++++++ util/thread_status_impl.cc | 38 +++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 util/thread_status_impl.cc diff --git a/include/rocksdb/thread_status.h b/include/rocksdb/thread_status.h index 57a87a21a..539321291 100644 --- a/include/rocksdb/thread_status.h +++ b/include/rocksdb/thread_status.h @@ -89,6 +89,16 @@ struct ThreadStatus { // The state (lower-level action) that the current thread is involved. const StateType state_type; + + // The followings are a set of utility functions for interpreting + // the information of ThreadStatus + + // Obtain the name of an operation given its type. + static const std::string& GetOperationName(OperationType op_type); + + // Obtain the name of a state given its type. + static const std::string& GetStateName(StateType state_type); }; + } // namespace rocksdb diff --git a/util/thread_list_test.cc b/util/thread_list_test.cc index 86ce1c4d9..737b78fe3 100644 --- a/util/thread_list_test.cc +++ b/util/thread_list_test.cc @@ -98,10 +98,16 @@ TEST(ThreadListTest, EventTables) { // verify the global tables for operations and states are properly indexed. for (int type = 0; type != ThreadStatus::NUM_OP_TYPES; ++type) { ASSERT_EQ(global_operation_table[type].type, type); + ASSERT_EQ(global_operation_table[type].name, + ThreadStatus::GetOperationName( + ThreadStatus::OperationType(type))); } for (int type = 0; type != ThreadStatus::NUM_STATE_TYPES; ++type) { ASSERT_EQ(global_state_table[type].type, type); + ASSERT_EQ(global_state_table[type].name, + ThreadStatus::GetStateName( + ThreadStatus::StateType(type))); } } diff --git a/util/thread_status_impl.cc b/util/thread_status_impl.cc new file mode 100644 index 000000000..faeadf302 --- /dev/null +++ b/util/thread_status_impl.cc @@ -0,0 +1,38 @@ +// Copyright (c) 2013, Facebook, Inc. All rights reserved. +// This source code is licensed under the BSD-style license found in the +// LICENSE file in the root directory of this source tree. An additional grant +// of patent rights can be found in the PATENTS file in the same directory. +// + +#include "rocksdb/thread_status.h" +#include "util/thread_operation.h" + +namespace rocksdb { + +#if ROCKSDB_USING_THREAD_STATUS +const std::string& ThreadStatus::GetOperationName( + ThreadStatus::OperationType op_type) { + return global_operation_table[op_type].name; +} + +const std::string& ThreadStatus::GetStateName( + ThreadStatus::StateType state_type) { + return global_state_table[state_type].name; +} + +#else + +const std::string& ThreadStatus::GetOperationName( + ThreadStatus::OperationType op_type) { + static std::string dummy_str = ""; + return dummy_str; +} + +const std::string& ThreadStatus::GetStateName( + ThreadStatus::StateType state_type) { + static std::string dummy_str = ""; + return dummy_str; +} + +#endif // ROCKSDB_USING_THREAD_STATUS +} // namespace rocksdb