thread_status_util_debug.cc 986 B

1234567891011121314151617181920212223242526272829303132
  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. #include <atomic>
  6. #include "monitoring/thread_status_updater.h"
  7. #include "monitoring/thread_status_util.h"
  8. #include "rocksdb/env.h"
  9. namespace ROCKSDB_NAMESPACE {
  10. #ifndef NDEBUG
  11. // the delay for debugging purpose.
  12. static std::atomic<int> states_delay[ThreadStatus::NUM_STATE_TYPES];
  13. void ThreadStatusUtil::TEST_SetStateDelay(
  14. const ThreadStatus::StateType state, int micro) {
  15. states_delay[state].store(micro, std::memory_order_relaxed);
  16. }
  17. void ThreadStatusUtil::TEST_StateDelay(const ThreadStatus::StateType state) {
  18. auto delay = states_delay[state].load(std::memory_order_relaxed);
  19. if (delay > 0) {
  20. Env::Default()->SleepForMicroseconds(delay);
  21. }
  22. }
  23. #endif // !NDEBUG
  24. } // namespace ROCKSDB_NAMESPACE