]>
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 | |
494da23a | 19 | extern thread_local PerfContext perf_context; |
11fdf7f2 TL |
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 | ||
494da23a TL |
44 | // Declare and set start time of the timer |
45 | #define PERF_TIMER_GUARD_WITH_ENV(metric, env) \ | |
46 | PerfStepTimer perf_step_timer_##metric(&(perf_context.metric), env); \ | |
47 | perf_step_timer_##metric.Start(); | |
48 | ||
49 | // Declare and set start time of the timer | |
50 | #define PERF_CPU_TIMER_GUARD(metric, env) \ | |
51 | PerfStepTimer perf_step_timer_##metric( \ | |
52 | &(perf_context.metric), env, true, \ | |
53 | PerfLevel::kEnableTimeAndCPUTimeExceptForMutex); \ | |
54 | perf_step_timer_##metric.Start(); | |
55 | ||
56 | #define PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(metric, condition, stats, \ | |
57 | ticker_type) \ | |
58 | PerfStepTimer perf_step_timer_##metric(&(perf_context.metric), nullptr, \ | |
59 | false, PerfLevel::kEnableTime, stats, \ | |
60 | ticker_type); \ | |
61 | if (condition) { \ | |
62 | perf_step_timer_##metric.Start(); \ | |
7c673cae FG |
63 | } |
64 | ||
65 | // Update metric with time elapsed since last START. start time is reset | |
66 | // to current timestamp. | |
11fdf7f2 | 67 | #define PERF_TIMER_MEASURE(metric) perf_step_timer_##metric.Measure(); |
7c673cae FG |
68 | |
69 | // Increase metric value | |
11fdf7f2 TL |
70 | #define PERF_COUNTER_ADD(metric, value) \ |
71 | if (perf_level >= PerfLevel::kEnableCount) { \ | |
72 | perf_context.metric += value; \ | |
73 | } | |
7c673cae | 74 | |
494da23a TL |
75 | // Increase metric value |
76 | #define PERF_COUNTER_BY_LEVEL_ADD(metric, value, level) \ | |
77 | if (perf_level >= PerfLevel::kEnableCount && \ | |
78 | perf_context.per_level_perf_context_enabled && \ | |
79 | perf_context.level_to_perf_context) { \ | |
80 | if ((*(perf_context.level_to_perf_context)).find(level) != \ | |
81 | (*(perf_context.level_to_perf_context)).end()) { \ | |
82 | (*(perf_context.level_to_perf_context))[level].metric += value; \ | |
83 | } \ | |
84 | else { \ | |
85 | PerfContextByLevel empty_context; \ | |
86 | (*(perf_context.level_to_perf_context))[level] = empty_context; \ | |
87 | (*(perf_context.level_to_perf_context))[level].metric += value; \ | |
88 | } \ | |
89 | } \ | |
90 | ||
7c673cae FG |
91 | #endif |
92 | ||
93 | } |