1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same 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.
16 #include "rocksdb/thread_status.h"
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"}
44 struct OperationStageInfo
{
45 const ThreadStatus::OperationStage stage
;
46 const std::string name
;
49 // A table maintains the mapping from stage type to stage string.
50 // Note that the string must be changed accordingly when the
51 // associated function name changed.
52 static OperationStageInfo global_op_stage_table
[] = {
53 {ThreadStatus::STAGE_UNKNOWN
, ""},
54 {ThreadStatus::STAGE_FLUSH_RUN
,
56 {ThreadStatus::STAGE_FLUSH_WRITE_L0
,
57 "FlushJob::WriteLevel0Table"},
58 {ThreadStatus::STAGE_COMPACTION_PREPARE
,
59 "CompactionJob::Prepare"},
60 {ThreadStatus::STAGE_COMPACTION_RUN
,
61 "CompactionJob::Run"},
62 {ThreadStatus::STAGE_COMPACTION_PROCESS_KV
,
63 "CompactionJob::ProcessKeyValueCompaction"},
64 {ThreadStatus::STAGE_COMPACTION_INSTALL
,
65 "CompactionJob::Install"},
66 {ThreadStatus::STAGE_COMPACTION_SYNC_FILE
,
67 "CompactionJob::FinishCompactionOutputFile"},
68 {ThreadStatus::STAGE_PICK_MEMTABLES_TO_FLUSH
,
69 "MemTableList::PickMemtablesToFlush"},
70 {ThreadStatus::STAGE_MEMTABLE_ROLLBACK
,
71 "MemTableList::RollbackMemtableFlush"},
72 {ThreadStatus::STAGE_MEMTABLE_INSTALL_FLUSH_RESULTS
,
73 "MemTableList::InstallMemtableFlushResults"},
76 // The structure that describes a state.
78 const ThreadStatus::StateType type
;
79 const std::string name
;
82 // The global state table.
84 // When updating a status of a thread, the pointer of the StateInfo
85 // of the current ThreadStatusData will be pointing to one of the
86 // rows in this global table.
87 static StateInfo global_state_table
[] = {
88 {ThreadStatus::STATE_UNKNOWN
, ""},
89 {ThreadStatus::STATE_MUTEX_WAIT
, "Mutex Wait"},
92 struct OperationProperty
{
97 static OperationProperty compaction_operation_properties
[] = {
98 {ThreadStatus::COMPACTION_JOB_ID
, "JobID"},
99 {ThreadStatus::COMPACTION_INPUT_OUTPUT_LEVEL
, "InputOutputLevel"},
100 {ThreadStatus::COMPACTION_PROP_FLAGS
, "Manual/Deletion/Trivial"},
101 {ThreadStatus::COMPACTION_TOTAL_INPUT_BYTES
, "TotalInputBytes"},
102 {ThreadStatus::COMPACTION_BYTES_READ
, "BytesRead"},
103 {ThreadStatus::COMPACTION_BYTES_WRITTEN
, "BytesWritten"},
106 static OperationProperty flush_operation_properties
[] = {
107 {ThreadStatus::FLUSH_JOB_ID
, "JobID"},
108 {ThreadStatus::FLUSH_BYTES_MEMTABLES
, "BytesMemtables"},
109 {ThreadStatus::FLUSH_BYTES_WRITTEN
, "BytesWritten"}
114 struct OperationInfo
{
120 #endif // ROCKSDB_USING_THREAD_STATUS
121 } // namespace rocksdb