iostats_context_imp.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #if !defined(NIOSTATS_CONTEXT)
  10. namespace ROCKSDB_NAMESPACE {
  11. extern thread_local IOStatsContext iostats_context;
  12. } // namespace ROCKSDB_NAMESPACE
  13. // increment a specific counter by the specified value
  14. #define IOSTATS_ADD(metric, value) \
  15. if (!iostats_context.disable_iostats) { \
  16. iostats_context.metric += value; \
  17. }
  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, clock) \
  32. PerfStepTimer iostats_step_timer_##metric( \
  33. &(iostats_context.metric), clock, true, \
  34. PerfLevel::kEnableTimeAndCPUTimeExceptForMutex); \
  35. iostats_step_timer_##metric.Start();
  36. #define IOSTATS_SET_DISABLE(disable) (iostats_context.disable_iostats = disable)
  37. #else // !NIOSTATS_CONTEXT
  38. #define IOSTATS_ADD(metric, value)
  39. #define IOSTATS_ADD_IF_POSITIVE(metric, value)
  40. #define IOSTATS_RESET(metric)
  41. #define IOSTATS_RESET_ALL()
  42. #define IOSTATS_SET_THREAD_POOL_ID(value)
  43. #define IOSTATS_THREAD_POOL_ID()
  44. #define IOSTATS(metric) 0
  45. #define IOSTATS_SET_DISABLE(disable)
  46. #define IOSTATS_TIMER_GUARD(metric)
  47. #define IOSTATS_CPU_TIMER_GUARD(metric, clock) static_cast<void>(clock)
  48. #endif // !NIOSTATS_CONTEXT