]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/monitoring/perf_context_imp.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / rocksdb / monitoring / perf_context_imp.h
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/perf_context.h"
9 #include "util/stop_watch.h"
10
11 namespace rocksdb {
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
22
23 #if defined(NPERF_CONTEXT)
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
35 #define PERF_TIMER_STOP(metric) perf_step_timer_##metric.Stop();
36
37 #define PERF_TIMER_START(metric) perf_step_timer_##metric.Start();
38
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();
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(); \
50 }
51
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();
55
56 // Increase metric value
57 #define PERF_COUNTER_ADD(metric, value) \
58 if (perf_level >= PerfLevel::kEnableCount) { \
59 perf_context.metric += value; \
60 }
61
62 #endif
63
64 }