thread_operation.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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).
  5. //
  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.
  13. #pragma once
  14. #include "rocksdb/thread_status.h"
  15. #include <string>
  16. namespace ROCKSDB_NAMESPACE {
  17. #ifdef ROCKSDB_USING_THREAD_STATUS
  18. // The structure that describes a major thread operation.
  19. struct OperationInfo {
  20. const ThreadStatus::OperationType type;
  21. const std::string name;
  22. };
  23. // The global operation table.
  24. //
  25. // When updating a status of a thread, the pointer of the OperationInfo
  26. // of the current ThreadStatusData will be pointing to one of the
  27. // rows in this global table.
  28. //
  29. // Note that it's not designed to be constant as in the future we
  30. // might consider adding global count to the OperationInfo.
  31. static OperationInfo global_operation_table[] = {
  32. {ThreadStatus::OP_UNKNOWN, ""},
  33. {ThreadStatus::OP_COMPACTION, "Compaction"},
  34. {ThreadStatus::OP_FLUSH, "Flush"}
  35. };
  36. struct OperationStageInfo {
  37. const ThreadStatus::OperationStage stage;
  38. const std::string name;
  39. };
  40. // A table maintains the mapping from stage type to stage string.
  41. // Note that the string must be changed accordingly when the
  42. // associated function name changed.
  43. static OperationStageInfo global_op_stage_table[] = {
  44. {ThreadStatus::STAGE_UNKNOWN, ""},
  45. {ThreadStatus::STAGE_FLUSH_RUN,
  46. "FlushJob::Run"},
  47. {ThreadStatus::STAGE_FLUSH_WRITE_L0,
  48. "FlushJob::WriteLevel0Table"},
  49. {ThreadStatus::STAGE_COMPACTION_PREPARE,
  50. "CompactionJob::Prepare"},
  51. {ThreadStatus::STAGE_COMPACTION_RUN,
  52. "CompactionJob::Run"},
  53. {ThreadStatus::STAGE_COMPACTION_PROCESS_KV,
  54. "CompactionJob::ProcessKeyValueCompaction"},
  55. {ThreadStatus::STAGE_COMPACTION_INSTALL,
  56. "CompactionJob::Install"},
  57. {ThreadStatus::STAGE_COMPACTION_SYNC_FILE,
  58. "CompactionJob::FinishCompactionOutputFile"},
  59. {ThreadStatus::STAGE_PICK_MEMTABLES_TO_FLUSH,
  60. "MemTableList::PickMemtablesToFlush"},
  61. {ThreadStatus::STAGE_MEMTABLE_ROLLBACK,
  62. "MemTableList::RollbackMemtableFlush"},
  63. {ThreadStatus::STAGE_MEMTABLE_INSTALL_FLUSH_RESULTS,
  64. "MemTableList::TryInstallMemtableFlushResults"},
  65. };
  66. // The structure that describes a state.
  67. struct StateInfo {
  68. const ThreadStatus::StateType type;
  69. const std::string name;
  70. };
  71. // The global state table.
  72. //
  73. // When updating a status of a thread, the pointer of the StateInfo
  74. // of the current ThreadStatusData will be pointing to one of the
  75. // rows in this global table.
  76. static StateInfo global_state_table[] = {
  77. {ThreadStatus::STATE_UNKNOWN, ""},
  78. {ThreadStatus::STATE_MUTEX_WAIT, "Mutex Wait"},
  79. };
  80. struct OperationProperty {
  81. int code;
  82. std::string name;
  83. };
  84. static OperationProperty compaction_operation_properties[] = {
  85. {ThreadStatus::COMPACTION_JOB_ID, "JobID"},
  86. {ThreadStatus::COMPACTION_INPUT_OUTPUT_LEVEL, "InputOutputLevel"},
  87. {ThreadStatus::COMPACTION_PROP_FLAGS, "Manual/Deletion/Trivial"},
  88. {ThreadStatus::COMPACTION_TOTAL_INPUT_BYTES, "TotalInputBytes"},
  89. {ThreadStatus::COMPACTION_BYTES_READ, "BytesRead"},
  90. {ThreadStatus::COMPACTION_BYTES_WRITTEN, "BytesWritten"},
  91. };
  92. static OperationProperty flush_operation_properties[] = {
  93. {ThreadStatus::FLUSH_JOB_ID, "JobID"},
  94. {ThreadStatus::FLUSH_BYTES_MEMTABLES, "BytesMemtables"},
  95. {ThreadStatus::FLUSH_BYTES_WRITTEN, "BytesWritten"}
  96. };
  97. #else
  98. struct OperationInfo {
  99. };
  100. struct StateInfo {
  101. };
  102. #endif // ROCKSDB_USING_THREAD_STATUS
  103. } // namespace ROCKSDB_NAMESPACE