]>
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 | ||
f67539c2 | 11 | namespace ROCKSDB_NAMESPACE { |
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 | 24 | |
7c673cae FG |
25 | #define PERF_TIMER_STOP(metric) |
26 | #define PERF_TIMER_START(metric) | |
f67539c2 TL |
27 | #define PERF_TIMER_GUARD(metric) |
28 | #define PERF_TIMER_GUARD_WITH_ENV(metric, env) | |
29 | #define PERF_CPU_TIMER_GUARD(metric, env) | |
30 | #define PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(metric, condition, stats, \ | |
31 | ticker_type) | |
32 | #define PERF_TIMER_MEASURE(metric) | |
7c673cae | 33 | #define PERF_COUNTER_ADD(metric, value) |
f67539c2 | 34 | #define PERF_COUNTER_BY_LEVEL_ADD(metric, value, level) |
7c673cae FG |
35 | |
36 | #else | |
37 | ||
38 | // Stop the timer and update the metric | |
11fdf7f2 | 39 | #define PERF_TIMER_STOP(metric) perf_step_timer_##metric.Stop(); |
7c673cae | 40 | |
11fdf7f2 | 41 | #define PERF_TIMER_START(metric) perf_step_timer_##metric.Start(); |
7c673cae FG |
42 | |
43 | // Declare and set start time of the timer | |
11fdf7f2 TL |
44 | #define PERF_TIMER_GUARD(metric) \ |
45 | PerfStepTimer perf_step_timer_##metric(&(perf_context.metric)); \ | |
46 | perf_step_timer_##metric.Start(); | |
47 | ||
494da23a TL |
48 | // Declare and set start time of the timer |
49 | #define PERF_TIMER_GUARD_WITH_ENV(metric, env) \ | |
50 | PerfStepTimer perf_step_timer_##metric(&(perf_context.metric), env); \ | |
51 | perf_step_timer_##metric.Start(); | |
52 | ||
53 | // Declare and set start time of the timer | |
54 | #define PERF_CPU_TIMER_GUARD(metric, env) \ | |
55 | PerfStepTimer perf_step_timer_##metric( \ | |
56 | &(perf_context.metric), env, true, \ | |
57 | PerfLevel::kEnableTimeAndCPUTimeExceptForMutex); \ | |
58 | perf_step_timer_##metric.Start(); | |
59 | ||
60 | #define PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(metric, condition, stats, \ | |
61 | ticker_type) \ | |
62 | PerfStepTimer perf_step_timer_##metric(&(perf_context.metric), nullptr, \ | |
63 | false, PerfLevel::kEnableTime, stats, \ | |
64 | ticker_type); \ | |
65 | if (condition) { \ | |
66 | perf_step_timer_##metric.Start(); \ | |
7c673cae FG |
67 | } |
68 | ||
69 | // Update metric with time elapsed since last START. start time is reset | |
70 | // to current timestamp. | |
11fdf7f2 | 71 | #define PERF_TIMER_MEASURE(metric) perf_step_timer_##metric.Measure(); |
7c673cae FG |
72 | |
73 | // Increase metric value | |
11fdf7f2 TL |
74 | #define PERF_COUNTER_ADD(metric, value) \ |
75 | if (perf_level >= PerfLevel::kEnableCount) { \ | |
76 | perf_context.metric += value; \ | |
77 | } | |
7c673cae | 78 | |
494da23a TL |
79 | // Increase metric value |
80 | #define PERF_COUNTER_BY_LEVEL_ADD(metric, value, level) \ | |
81 | if (perf_level >= PerfLevel::kEnableCount && \ | |
82 | perf_context.per_level_perf_context_enabled && \ | |
83 | perf_context.level_to_perf_context) { \ | |
84 | if ((*(perf_context.level_to_perf_context)).find(level) != \ | |
85 | (*(perf_context.level_to_perf_context)).end()) { \ | |
86 | (*(perf_context.level_to_perf_context))[level].metric += value; \ | |
87 | } \ | |
88 | else { \ | |
89 | PerfContextByLevel empty_context; \ | |
90 | (*(perf_context.level_to_perf_context))[level] = empty_context; \ | |
91 | (*(perf_context.level_to_perf_context))[level].metric += value; \ | |
92 | } \ | |
93 | } \ | |
94 | ||
7c673cae FG |
95 | #endif |
96 | ||
f67539c2 | 97 | } // namespace ROCKSDB_NAMESPACE |