]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
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). | |
7c673cae FG |
5 | // |
6 | #pragma once | |
7 | #include "monitoring/perf_step_timer.h" | |
8 | #include "rocksdb/perf_context.h" | |
9 | #include "util/stop_watch.h" | |
10 | ||
11 | namespace rocksdb { | |
11fdf7f2 TL |
12 | #if defined(NPERF_CONTEXT) || !defined(ROCKSDB_SUPPORT_THREAD_LOCAL) |
13 | extern PerfContext perf_context; | |
14 | #else | |
15 | #if defined(OS_SOLARIS) | |
16 | extern __thread PerfContext perf_context_; | |
17 | #define perf_context (*get_perf_context()) | |
18 | #else | |
19 | extern __thread PerfContext perf_context; | |
20 | #endif | |
21 | #endif | |
7c673cae | 22 | |
11fdf7f2 | 23 | #if defined(NPERF_CONTEXT) |
7c673cae FG |
24 | |
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) | |
31 | ||
32 | #else | |
33 | ||
34 | // Stop the timer and update the metric | |
11fdf7f2 | 35 | #define PERF_TIMER_STOP(metric) perf_step_timer_##metric.Stop(); |
7c673cae | 36 | |
11fdf7f2 | 37 | #define PERF_TIMER_START(metric) perf_step_timer_##metric.Start(); |
7c673cae FG |
38 | |
39 | // Declare and set start time of the timer | |
11fdf7f2 TL |
40 | #define PERF_TIMER_GUARD(metric) \ |
41 | PerfStepTimer perf_step_timer_##metric(&(perf_context.metric)); \ | |
42 | perf_step_timer_##metric.Start(); | |
43 | ||
44 | #define PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(metric, condition, stats, \ | |
45 | ticker_type) \ | |
46 | PerfStepTimer perf_step_timer_##metric(&(perf_context.metric), true, stats, \ | |
47 | ticker_type); \ | |
48 | if (condition) { \ | |
49 | perf_step_timer_##metric.Start(); \ | |
7c673cae FG |
50 | } |
51 | ||
52 | // Update metric with time elapsed since last START. start time is reset | |
53 | // to current timestamp. | |
11fdf7f2 | 54 | #define PERF_TIMER_MEASURE(metric) perf_step_timer_##metric.Measure(); |
7c673cae FG |
55 | |
56 | // Increase metric value | |
11fdf7f2 TL |
57 | #define PERF_COUNTER_ADD(metric, value) \ |
58 | if (perf_level >= PerfLevel::kEnableCount) { \ | |
59 | perf_context.metric += value; \ | |
60 | } | |
7c673cae FG |
61 | |
62 | #endif | |
63 | ||
64 | } |