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).
7 #include "monitoring/perf_step_timer.h"
8 #include "rocksdb/perf_context.h"
9 #include "util/stop_watch.h"
12 #if defined(NPERF_CONTEXT) || !defined(ROCKSDB_SUPPORT_THREAD_LOCAL)
13 extern PerfContext perf_context
;
15 #if defined(OS_SOLARIS)
16 extern __thread PerfContext perf_context_
;
17 #define perf_context (*get_perf_context())
19 extern __thread PerfContext perf_context
;
23 #if defined(NPERF_CONTEXT)
25 #define PERF_TIMER_GUARD(metric)
26 #define PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(metric, condition)
27 #define PERF_TIMER_MEASURE(metric)
28 #define PERF_TIMER_STOP(metric)
29 #define PERF_TIMER_START(metric)
30 #define PERF_COUNTER_ADD(metric, value)
34 // Stop the timer and update the metric
35 #define PERF_TIMER_STOP(metric) perf_step_timer_##metric.Stop();
37 #define PERF_TIMER_START(metric) perf_step_timer_##metric.Start();
39 // Declare and set start time of the timer
40 #define PERF_TIMER_GUARD(metric) \
41 PerfStepTimer perf_step_timer_##metric(&(perf_context.metric)); \
42 perf_step_timer_##metric.Start();
44 #define PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(metric, condition, stats, \
46 PerfStepTimer perf_step_timer_##metric(&(perf_context.metric), true, stats, \
49 perf_step_timer_##metric.Start(); \
52 // Update metric with time elapsed since last START. start time is reset
53 // to current timestamp.
54 #define PERF_TIMER_MEASURE(metric) perf_step_timer_##metric.Measure();
56 // Increase metric value
57 #define PERF_COUNTER_ADD(metric, value) \
58 if (perf_level >= PerfLevel::kEnableCount) { \
59 perf_context.metric += value; \