77a5a543a5
Summary: Now we're able to show more details about a compaction in GetThreadList() :) This patch allows GetThreadList() to report basic compaction operation properties. Basic compaction properties include: 1. job id 2. compaction input / output level 3. compaction property flags (is_manual, is_deletion, .. etc) 4. total input bytes 5. the number of bytes has been read currently. 6. the number of bytes has been written currently. Flush operation properties will be done in a seperate diff. Test Plan: /db_bench --threads=30 --num=1000000 --benchmarks=fillrandom --thread_status_per_interval=1 Sample output of tracking same job: ThreadID ThreadType cfName Operation ElapsedTime Stage State OperationProperties 140664171987072 Low Pri default Compaction 31.357 ms CompactionJob::FinishCompactionOutputFile BaseInputLevel 1 | BytesRead 2264663 | BytesWritten 1934241 | IsDeletion 0 | IsManual 0 | IsTrivialMove 0 | JobID 277 | OutputLevel 2 | TotalInputBytes 3964158 | ThreadID ThreadType cfName Operation ElapsedTime Stage State OperationProperties 140664171987072 Low Pri default Compaction 59.440 ms CompactionJob::FinishCompactionOutputFile BaseInputLevel 1 | BytesRead 2264663 | BytesWritten 1934241 | IsDeletion 0 | IsManual 0 | IsTrivialMove 0 | JobID 277 | OutputLevel 2 | TotalInputBytes 3964158 | ThreadID ThreadType cfName Operation ElapsedTime Stage State OperationProperties 140664171987072 Low Pri default Compaction 226.375 ms CompactionJob::Install BaseInputLevel 1 | BytesRead 3958013 | BytesWritten 3621940 | IsDeletion 0 | IsManual 0 | IsTrivialMove 0 | JobID 277 | OutputLevel 2 | TotalInputBytes 3964158 | Reviewers: sdong, rven, igor Reviewed By: igor Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D37653
154 lines
4.3 KiB
C++
154 lines
4.3 KiB
C++
// 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 <sstream>
|
|
|
|
#include "rocksdb/env.h"
|
|
#include "rocksdb/thread_status.h"
|
|
#include "util/logging.h"
|
|
#include "util/thread_operation.h"
|
|
|
|
namespace rocksdb {
|
|
|
|
#if ROCKSDB_USING_THREAD_STATUS
|
|
const std::string& ThreadStatus::GetThreadTypeName(
|
|
ThreadStatus::ThreadType thread_type) {
|
|
static std::string thread_type_names[NUM_THREAD_TYPES + 1] = {
|
|
"High Pri", "Low Pri", "User", "Unknown"};
|
|
return thread_type_names[thread_type];
|
|
}
|
|
|
|
const std::string& ThreadStatus::GetOperationName(
|
|
ThreadStatus::OperationType op_type) {
|
|
return global_operation_table[op_type].name;
|
|
}
|
|
|
|
const std::string& ThreadStatus::GetOperationStageName(
|
|
ThreadStatus::OperationStage stage) {
|
|
return global_op_stage_table[stage].name;
|
|
}
|
|
|
|
const std::string& ThreadStatus::GetStateName(
|
|
ThreadStatus::StateType state_type) {
|
|
return global_state_table[state_type].name;
|
|
}
|
|
|
|
const std::string ThreadStatus::MicrosToString(uint64_t micros) {
|
|
if (micros == 0) {
|
|
return "";
|
|
}
|
|
const int kBufferLen = 100;
|
|
char buffer[kBufferLen];
|
|
AppendHumanMicros(micros, buffer, kBufferLen, false);
|
|
return std::string(buffer);
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
std::map<std::string, uint64_t>
|
|
ThreadStatus::InterpretOperationProperties(
|
|
ThreadStatus::OperationType op_type, uint64_t* op_properties) {
|
|
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) {
|
|
if (op_type == OP_COMPACTION &&
|
|
i == COMPACTION_INPUT_OUTPUT_LEVEL) {
|
|
property_map.emplace(
|
|
"BaseInputLevel", op_properties[i] >> 32);
|
|
property_map.emplace(
|
|
"OutputLevel", op_properties[i] % (1LU << 32));
|
|
} else if (op_type == OP_COMPACTION &&
|
|
i == COMPACTION_PROP_FLAGS) {
|
|
property_map.emplace(
|
|
"IsManual", ((op_properties[i] & 2) >> 1));
|
|
property_map.emplace(
|
|
"IsDeletion", ((op_properties[i] & 4) >> 2));
|
|
property_map.emplace(
|
|
"IsTrivialMove", ((op_properties[i] & 8) >> 3));
|
|
} else {
|
|
property_map.emplace(
|
|
GetOperationPropertyName(op_type, i), op_properties[i]);
|
|
}
|
|
}
|
|
return property_map;
|
|
}
|
|
|
|
|
|
#else
|
|
|
|
const std::string& ThreadStatus::GetThreadTypeName(
|
|
ThreadStatus::ThreadType thread_type) {
|
|
static std::string dummy_str = "";
|
|
return dummy_str;
|
|
}
|
|
|
|
const std::string& ThreadStatus::GetOperationName(
|
|
ThreadStatus::OperationType op_type) {
|
|
static std::string dummy_str = "";
|
|
return dummy_str;
|
|
}
|
|
|
|
const std::string& ThreadStatus::GetOperationStageName(
|
|
ThreadStatus::OperationStage stage) {
|
|
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;
|
|
}
|
|
|
|
const std::string ThreadStatus::MicrosToString(
|
|
uint64_t op_elapsed_time) {
|
|
static std::string dummy_str = "";
|
|
return dummy_str;
|
|
}
|
|
|
|
const std::string& ThreadStatus::GetOperationPropertyName(
|
|
ThreadStatus::OperationType op_type, int i) {
|
|
static std::string dummy_str = "";
|
|
return dummy_str;
|
|
}
|
|
|
|
std::map<std::string, uint64_t>
|
|
ThreadStatus::InterpretOperationProperties(
|
|
ThreadStatus::OperationType op_type, uint64_t* op_properties) {
|
|
return std::map<std::string, uint64_t>();
|
|
}
|
|
|
|
#endif // ROCKSDB_USING_THREAD_STATUS
|
|
} // namespace rocksdb
|