1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under both the GPLv2 (found in the
3 // COPYING file in the root directory) and Apache 2.0 License
4 // (found in the LICENSE.Apache file in the root directory).
6 // This file defines the structures for thread operation and state.
7 // Thread operations are used to describe high level action of a
8 // thread such as doing compaction or flush, while thread state
9 // are used to describe lower-level action such as reading /
10 // writing a file or waiting for a mutex. Operations and states
11 // are designed to be independent. Typically, a thread usually involves
12 // in one operation and one state at any specific point in time.
18 #include "rocksdb/thread_status.h"
20 namespace ROCKSDB_NAMESPACE
{
22 #ifdef ROCKSDB_USING_THREAD_STATUS
24 // The structure that describes a major thread operation.
25 struct OperationInfo
{
26 const ThreadStatus::OperationType type
;
27 const std::string name
;
30 // The global operation table.
32 // When updating a status of a thread, the pointer of the OperationInfo
33 // of the current ThreadStatusData will be pointing to one of the
34 // rows in this global table.
36 // Note that it's not designed to be constant as in the future we
37 // might consider adding global count to the OperationInfo.
38 static OperationInfo global_operation_table
[] = {
39 {ThreadStatus::OP_UNKNOWN
, ""},
40 {ThreadStatus::OP_COMPACTION
, "Compaction"},
41 {ThreadStatus::OP_FLUSH
, "Flush"}};
43 struct OperationStageInfo
{
44 const ThreadStatus::OperationStage stage
;
45 const std::string name
;
48 // A table maintains the mapping from stage type to stage string.
49 // Note that the string must be changed accordingly when the
50 // associated function name changed.
51 static OperationStageInfo global_op_stage_table
[] = {
52 {ThreadStatus::STAGE_UNKNOWN
, ""},
53 {ThreadStatus::STAGE_FLUSH_RUN
, "FlushJob::Run"},
54 {ThreadStatus::STAGE_FLUSH_WRITE_L0
, "FlushJob::WriteLevel0Table"},
55 {ThreadStatus::STAGE_COMPACTION_PREPARE
, "CompactionJob::Prepare"},
56 {ThreadStatus::STAGE_COMPACTION_RUN
, "CompactionJob::Run"},
57 {ThreadStatus::STAGE_COMPACTION_PROCESS_KV
,
58 "CompactionJob::ProcessKeyValueCompaction"},
59 {ThreadStatus::STAGE_COMPACTION_INSTALL
, "CompactionJob::Install"},
60 {ThreadStatus::STAGE_COMPACTION_SYNC_FILE
,
61 "CompactionJob::FinishCompactionOutputFile"},
62 {ThreadStatus::STAGE_PICK_MEMTABLES_TO_FLUSH
,
63 "MemTableList::PickMemtablesToFlush"},
64 {ThreadStatus::STAGE_MEMTABLE_ROLLBACK
,
65 "MemTableList::RollbackMemtableFlush"},
66 {ThreadStatus::STAGE_MEMTABLE_INSTALL_FLUSH_RESULTS
,
67 "MemTableList::TryInstallMemtableFlushResults"},
70 // The structure that describes a state.
72 const ThreadStatus::StateType type
;
73 const std::string name
;
76 // The global state table.
78 // When updating a status of a thread, the pointer of the StateInfo
79 // of the current ThreadStatusData will be pointing to one of the
80 // rows in this global table.
81 static StateInfo global_state_table
[] = {
82 {ThreadStatus::STATE_UNKNOWN
, ""},
83 {ThreadStatus::STATE_MUTEX_WAIT
, "Mutex Wait"},
86 struct OperationProperty
{
91 static OperationProperty compaction_operation_properties
[] = {
92 {ThreadStatus::COMPACTION_JOB_ID
, "JobID"},
93 {ThreadStatus::COMPACTION_INPUT_OUTPUT_LEVEL
, "InputOutputLevel"},
94 {ThreadStatus::COMPACTION_PROP_FLAGS
, "Manual/Deletion/Trivial"},
95 {ThreadStatus::COMPACTION_TOTAL_INPUT_BYTES
, "TotalInputBytes"},
96 {ThreadStatus::COMPACTION_BYTES_READ
, "BytesRead"},
97 {ThreadStatus::COMPACTION_BYTES_WRITTEN
, "BytesWritten"},
100 static OperationProperty flush_operation_properties
[] = {
101 {ThreadStatus::FLUSH_JOB_ID
, "JobID"},
102 {ThreadStatus::FLUSH_BYTES_MEMTABLES
, "BytesMemtables"},
103 {ThreadStatus::FLUSH_BYTES_WRITTEN
, "BytesWritten"}};
107 struct OperationInfo
{};
111 #endif // ROCKSDB_USING_THREAD_STATUS
112 } // namespace ROCKSDB_NAMESPACE