iostats_context_imp.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. #pragma once
  7. #include "monitoring/perf_step_timer.h"
  8. #include "rocksdb/iostats_context.h"
  9. #ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
  10. namespace ROCKSDB_NAMESPACE {
  11. extern __thread IOStatsContext iostats_context;
  12. } // namespace ROCKSDB_NAMESPACE
  13. // increment a specific counter by the specified value
  14. #define IOSTATS_ADD(metric, value) (iostats_context.metric += value)
  15. // Increase metric value only when it is positive
  16. #define IOSTATS_ADD_IF_POSITIVE(metric, value) \
  17. if (value > 0) { IOSTATS_ADD(metric, value); }
  18. // reset a specific counter to zero
  19. #define IOSTATS_RESET(metric) (iostats_context.metric = 0)
  20. // reset all counters to zero
  21. #define IOSTATS_RESET_ALL() (iostats_context.Reset())
  22. #define IOSTATS_SET_THREAD_POOL_ID(value) \
  23. (iostats_context.thread_pool_id = value)
  24. #define IOSTATS_THREAD_POOL_ID() (iostats_context.thread_pool_id)
  25. #define IOSTATS(metric) (iostats_context.metric)
  26. // Declare and set start time of the timer
  27. #define IOSTATS_TIMER_GUARD(metric) \
  28. PerfStepTimer iostats_step_timer_##metric(&(iostats_context.metric)); \
  29. iostats_step_timer_##metric.Start();
  30. // Declare and set start time of the timer
  31. #define IOSTATS_CPU_TIMER_GUARD(metric, env) \
  32. PerfStepTimer iostats_step_timer_##metric( \
  33. &(iostats_context.metric), env, true, \
  34. PerfLevel::kEnableTimeAndCPUTimeExceptForMutex); \
  35. iostats_step_timer_##metric.Start();
  36. #else // ROCKSDB_SUPPORT_THREAD_LOCAL
  37. #define IOSTATS_ADD(metric, value)
  38. #define IOSTATS_ADD_IF_POSITIVE(metric, value)
  39. #define IOSTATS_RESET(metric)
  40. #define IOSTATS_RESET_ALL()
  41. #define IOSTATS_SET_THREAD_POOL_ID(value)
  42. #define IOSTATS_THREAD_POOL_ID()
  43. #define IOSTATS(metric) 0
  44. #define IOSTATS_TIMER_GUARD(metric)
  45. #define IOSTATS_CPU_TIMER_GUARD(metric, env) static_cast<void>(env)
  46. #endif // ROCKSDB_SUPPORT_THREAD_LOCAL