thread_operation.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 <string>
  15. #include "rocksdb/thread_status.h"
  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. {ThreadStatus::OP_DBOPEN, "DBOpen"},
  36. {ThreadStatus::OP_GET, "Get"},
  37. {ThreadStatus::OP_MULTIGET, "MultiGet"},
  38. {ThreadStatus::OP_DBITERATOR, "DBIterator"},
  39. {ThreadStatus::OP_VERIFY_DB_CHECKSUM, "VerifyDBChecksum"},
  40. {ThreadStatus::OP_VERIFY_FILE_CHECKSUMS, "VerifyFileChecksums"},
  41. {ThreadStatus::OP_GETENTITY, "GetEntity"},
  42. {ThreadStatus::OP_MULTIGETENTITY, "MultiGetEntity"},
  43. {ThreadStatus::OP_GET_FILE_CHECKSUMS_FROM_CURRENT_MANIFEST,
  44. "GetFileChecksumsFromCurrentManifest"},
  45. };
  46. struct OperationStageInfo {
  47. const ThreadStatus::OperationStage stage;
  48. const std::string name;
  49. };
  50. // A table maintains the mapping from stage type to stage string.
  51. // Note that the string must be changed accordingly when the
  52. // associated function name changed.
  53. static OperationStageInfo global_op_stage_table[] = {
  54. {ThreadStatus::STAGE_UNKNOWN, ""},
  55. {ThreadStatus::STAGE_FLUSH_RUN, "FlushJob::Run"},
  56. {ThreadStatus::STAGE_FLUSH_WRITE_L0, "FlushJob::WriteLevel0Table"},
  57. {ThreadStatus::STAGE_COMPACTION_PREPARE, "CompactionJob::Prepare"},
  58. {ThreadStatus::STAGE_COMPACTION_RUN, "CompactionJob::Run"},
  59. {ThreadStatus::STAGE_COMPACTION_PROCESS_KV,
  60. "CompactionJob::ProcessKeyValueCompaction"},
  61. {ThreadStatus::STAGE_COMPACTION_INSTALL, "CompactionJob::Install"},
  62. {ThreadStatus::STAGE_COMPACTION_SYNC_FILE,
  63. "CompactionJob::FinishCompactionOutputFile"},
  64. {ThreadStatus::STAGE_PICK_MEMTABLES_TO_FLUSH,
  65. "MemTableList::PickMemtablesToFlush"},
  66. {ThreadStatus::STAGE_MEMTABLE_ROLLBACK,
  67. "MemTableList::RollbackMemtableFlush"},
  68. {ThreadStatus::STAGE_MEMTABLE_INSTALL_FLUSH_RESULTS,
  69. "MemTableList::TryInstallMemtableFlushResults"},
  70. };
  71. // The structure that describes a state.
  72. struct StateInfo {
  73. const ThreadStatus::StateType type;
  74. const std::string name;
  75. };
  76. // The global state table.
  77. //
  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"},
  84. };
  85. struct OperationProperty {
  86. int code;
  87. std::string name;
  88. };
  89. static OperationProperty compaction_operation_properties[] = {
  90. {ThreadStatus::COMPACTION_JOB_ID, "JobID"},
  91. {ThreadStatus::COMPACTION_INPUT_OUTPUT_LEVEL, "InputOutputLevel"},
  92. {ThreadStatus::COMPACTION_PROP_FLAGS, "Manual/Deletion/Trivial"},
  93. {ThreadStatus::COMPACTION_TOTAL_INPUT_BYTES, "TotalInputBytes"},
  94. {ThreadStatus::COMPACTION_BYTES_READ, "BytesRead"},
  95. {ThreadStatus::COMPACTION_BYTES_WRITTEN, "BytesWritten"},
  96. };
  97. static OperationProperty flush_operation_properties[] = {
  98. {ThreadStatus::FLUSH_JOB_ID, "JobID"},
  99. {ThreadStatus::FLUSH_BYTES_MEMTABLES, "BytesMemtables"},
  100. {ThreadStatus::FLUSH_BYTES_WRITTEN, "BytesWritten"}};
  101. #else
  102. struct OperationInfo {};
  103. struct StateInfo {};
  104. #endif // ROCKSDB_USING_THREAD_STATUS
  105. } // namespace ROCKSDB_NAMESPACE