2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2015-02-04 10:47:32 +01:00
|
|
|
//
|
|
|
|
|
2015-05-07 07:50:35 +02:00
|
|
|
#include <sstream>
|
|
|
|
|
2015-03-10 22:51:28 +01:00
|
|
|
#include "rocksdb/env.h"
|
2015-02-04 10:47:32 +01:00
|
|
|
#include "rocksdb/thread_status.h"
|
2017-04-06 23:49:13 +02:00
|
|
|
#include "util/string_util.h"
|
2015-02-04 10:47:32 +01:00
|
|
|
#include "util/thread_operation.h"
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2015-02-04 10:47:32 +01:00
|
|
|
|
2016-12-14 03:22:00 +01:00
|
|
|
#ifdef ROCKSDB_USING_THREAD_STATUS
|
2017-12-14 23:41:59 +01:00
|
|
|
std::string ThreadStatus::GetThreadTypeName(
|
2015-03-06 20:22:06 +01:00
|
|
|
ThreadStatus::ThreadType thread_type) {
|
2017-12-14 23:41:59 +01:00
|
|
|
switch (thread_type) {
|
|
|
|
case ThreadStatus::ThreadType::HIGH_PRIORITY:
|
|
|
|
return "High Pri";
|
|
|
|
case ThreadStatus::ThreadType::LOW_PRIORITY:
|
|
|
|
return "Low Pri";
|
|
|
|
case ThreadStatus::ThreadType::USER:
|
|
|
|
return "User";
|
|
|
|
case ThreadStatus::ThreadType::BOTTOM_PRIORITY:
|
|
|
|
return "Bottom Pri";
|
|
|
|
case ThreadStatus::ThreadType::NUM_THREAD_TYPES:
|
|
|
|
assert(false);
|
2015-05-16 08:22:22 +02:00
|
|
|
}
|
2017-12-14 23:41:59 +01:00
|
|
|
return "Unknown";
|
2015-03-06 20:22:06 +01:00
|
|
|
}
|
|
|
|
|
2015-02-04 10:47:32 +01:00
|
|
|
const std::string& ThreadStatus::GetOperationName(
|
|
|
|
ThreadStatus::OperationType op_type) {
|
2015-05-16 08:22:22 +02:00
|
|
|
if (op_type < 0 || op_type >= NUM_OP_TYPES) {
|
|
|
|
return global_operation_table[OP_UNKNOWN].name;
|
|
|
|
}
|
2015-02-04 10:47:32 +01:00
|
|
|
return global_operation_table[op_type].name;
|
|
|
|
}
|
|
|
|
|
2015-03-13 18:45:40 +01:00
|
|
|
const std::string& ThreadStatus::GetOperationStageName(
|
|
|
|
ThreadStatus::OperationStage stage) {
|
2015-05-16 08:22:22 +02:00
|
|
|
if (stage < 0 || stage >= NUM_OP_STAGES) {
|
|
|
|
return global_op_stage_table[STAGE_UNKNOWN].name;
|
|
|
|
}
|
2015-03-13 18:45:40 +01:00
|
|
|
return global_op_stage_table[stage].name;
|
|
|
|
}
|
|
|
|
|
2015-02-04 10:47:32 +01:00
|
|
|
const std::string& ThreadStatus::GetStateName(
|
|
|
|
ThreadStatus::StateType state_type) {
|
2015-05-16 08:22:22 +02:00
|
|
|
if (state_type < 0 || state_type >= NUM_STATE_TYPES) {
|
|
|
|
return global_state_table[STATE_UNKNOWN].name;
|
|
|
|
}
|
2015-02-04 10:47:32 +01:00
|
|
|
return global_state_table[state_type].name;
|
|
|
|
}
|
|
|
|
|
2015-03-24 00:35:04 +01:00
|
|
|
const std::string ThreadStatus::MicrosToString(uint64_t micros) {
|
|
|
|
if (micros == 0) {
|
2015-03-10 22:51:28 +01:00
|
|
|
return "";
|
|
|
|
}
|
2015-03-24 00:35:04 +01:00
|
|
|
const int kBufferLen = 100;
|
|
|
|
char buffer[kBufferLen];
|
2015-03-30 20:28:25 +02:00
|
|
|
AppendHumanMicros(micros, buffer, kBufferLen, false);
|
2015-03-24 00:35:04 +01:00
|
|
|
return std::string(buffer);
|
2015-03-10 22:51:28 +01:00
|
|
|
}
|
|
|
|
|
2015-05-07 07:50:35 +02:00
|
|
|
const std::string& ThreadStatus::GetOperationPropertyName(
|
|
|
|
ThreadStatus::OperationType op_type, int i) {
|
|
|
|
static const std::string empty_str = "";
|
|
|
|
switch (op_type) {
|
|
|
|
case ThreadStatus::OP_COMPACTION:
|
|
|
|
if (i >= NUM_COMPACTION_PROPERTIES) {
|
|
|
|
return empty_str;
|
|
|
|
}
|
|
|
|
return compaction_operation_properties[i].name;
|
|
|
|
case ThreadStatus::OP_FLUSH:
|
|
|
|
if (i >= NUM_FLUSH_PROPERTIES) {
|
|
|
|
return empty_str;
|
|
|
|
}
|
|
|
|
return flush_operation_properties[i].name;
|
|
|
|
default:
|
|
|
|
return empty_str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
std::map<std::string, uint64_t> ThreadStatus::InterpretOperationProperties(
|
|
|
|
ThreadStatus::OperationType op_type, const uint64_t* op_properties) {
|
2015-05-07 07:50:35 +02:00
|
|
|
int num_properties;
|
|
|
|
switch (op_type) {
|
|
|
|
case OP_COMPACTION:
|
|
|
|
num_properties = NUM_COMPACTION_PROPERTIES;
|
|
|
|
break;
|
|
|
|
case OP_FLUSH:
|
|
|
|
num_properties = NUM_FLUSH_PROPERTIES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
num_properties = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::map<std::string, uint64_t> property_map;
|
|
|
|
for (int i = 0; i < num_properties; ++i) {
|
2018-04-13 02:55:14 +02:00
|
|
|
if (op_type == OP_COMPACTION && i == COMPACTION_INPUT_OUTPUT_LEVEL) {
|
|
|
|
property_map.insert({"BaseInputLevel", op_properties[i] >> 32});
|
2015-05-18 22:44:31 +02:00
|
|
|
property_map.insert(
|
2015-07-02 01:13:49 +02:00
|
|
|
{"OutputLevel", op_properties[i] % (uint64_t(1) << 32U)});
|
2018-04-13 02:55:14 +02:00
|
|
|
} else if (op_type == OP_COMPACTION && i == COMPACTION_PROP_FLAGS) {
|
|
|
|
property_map.insert({"IsManual", ((op_properties[i] & 2) >> 1)});
|
|
|
|
property_map.insert({"IsDeletion", ((op_properties[i] & 4) >> 2)});
|
|
|
|
property_map.insert({"IsTrivialMove", ((op_properties[i] & 8) >> 3)});
|
2015-05-07 07:50:35 +02:00
|
|
|
} else {
|
2015-05-18 22:44:31 +02:00
|
|
|
property_map.insert(
|
|
|
|
{GetOperationPropertyName(op_type, i), op_properties[i]});
|
2015-05-07 07:50:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return property_map;
|
|
|
|
}
|
|
|
|
|
2015-02-04 10:47:32 +01:00
|
|
|
#else
|
|
|
|
|
2017-12-14 23:41:59 +01:00
|
|
|
std::string ThreadStatus::GetThreadTypeName(
|
2018-04-13 02:55:14 +02:00
|
|
|
ThreadStatus::ThreadType /*thread_type*/) {
|
2015-03-06 20:22:06 +01:00
|
|
|
static std::string dummy_str = "";
|
|
|
|
return dummy_str;
|
|
|
|
}
|
|
|
|
|
2015-02-04 10:47:32 +01:00
|
|
|
const std::string& ThreadStatus::GetOperationName(
|
2018-04-13 02:55:14 +02:00
|
|
|
ThreadStatus::OperationType /*op_type*/) {
|
2015-02-04 10:47:32 +01:00
|
|
|
static std::string dummy_str = "";
|
|
|
|
return dummy_str;
|
|
|
|
}
|
|
|
|
|
2015-03-13 18:45:40 +01:00
|
|
|
const std::string& ThreadStatus::GetOperationStageName(
|
2018-04-13 02:55:14 +02:00
|
|
|
ThreadStatus::OperationStage /*stage*/) {
|
2015-03-13 18:45:40 +01:00
|
|
|
static std::string dummy_str = "";
|
|
|
|
return dummy_str;
|
|
|
|
}
|
|
|
|
|
2015-02-04 10:47:32 +01:00
|
|
|
const std::string& ThreadStatus::GetStateName(
|
2018-04-13 02:55:14 +02:00
|
|
|
ThreadStatus::StateType /*state_type*/) {
|
2015-02-04 10:47:32 +01:00
|
|
|
static std::string dummy_str = "";
|
|
|
|
return dummy_str;
|
|
|
|
}
|
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
const std::string ThreadStatus::MicrosToString(uint64_t /*op_elapsed_time*/) {
|
2015-03-11 21:02:46 +01:00
|
|
|
static std::string dummy_str = "";
|
|
|
|
return dummy_str;
|
|
|
|
}
|
|
|
|
|
2015-05-07 07:50:35 +02:00
|
|
|
const std::string& ThreadStatus::GetOperationPropertyName(
|
2018-04-13 02:55:14 +02:00
|
|
|
ThreadStatus::OperationType /*op_type*/, int /*i*/) {
|
2015-05-07 07:50:35 +02:00
|
|
|
static std::string dummy_str = "";
|
|
|
|
return dummy_str;
|
|
|
|
}
|
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
std::map<std::string, uint64_t> ThreadStatus::InterpretOperationProperties(
|
|
|
|
ThreadStatus::OperationType /*op_type*/,
|
|
|
|
const uint64_t* /*op_properties*/) {
|
2015-05-07 07:50:35 +02:00
|
|
|
return std::map<std::string, uint64_t>();
|
|
|
|
}
|
|
|
|
|
2015-02-04 10:47:32 +01:00
|
|
|
#endif // ROCKSDB_USING_THREAD_STATUS
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|