]>
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/iostats_context.h" | |
9 | ||
11fdf7f2 TL |
10 | #ifdef ROCKSDB_SUPPORT_THREAD_LOCAL |
11 | namespace rocksdb { | |
12 | extern __thread IOStatsContext iostats_context; | |
13 | } // namespace rocksdb | |
7c673cae FG |
14 | |
15 | // increment a specific counter by the specified value | |
11fdf7f2 | 16 | #define IOSTATS_ADD(metric, value) (iostats_context.metric += value) |
7c673cae FG |
17 | |
18 | // Increase metric value only when it is positive | |
19 | #define IOSTATS_ADD_IF_POSITIVE(metric, value) \ | |
20 | if (value > 0) { IOSTATS_ADD(metric, value); } | |
21 | ||
22 | // reset a specific counter to zero | |
11fdf7f2 | 23 | #define IOSTATS_RESET(metric) (iostats_context.metric = 0) |
7c673cae FG |
24 | |
25 | // reset all counters to zero | |
11fdf7f2 | 26 | #define IOSTATS_RESET_ALL() (iostats_context.Reset()) |
7c673cae | 27 | |
11fdf7f2 | 28 | #define IOSTATS_SET_THREAD_POOL_ID(value) \ |
7c673cae FG |
29 | (iostats_context.thread_pool_id = value) |
30 | ||
11fdf7f2 | 31 | #define IOSTATS_THREAD_POOL_ID() (iostats_context.thread_pool_id) |
7c673cae | 32 | |
11fdf7f2 | 33 | #define IOSTATS(metric) (iostats_context.metric) |
7c673cae FG |
34 | |
35 | // Declare and set start time of the timer | |
11fdf7f2 TL |
36 | #define IOSTATS_TIMER_GUARD(metric) \ |
37 | PerfStepTimer iostats_step_timer_##metric(&(iostats_context.metric)); \ | |
38 | iostats_step_timer_##metric.Start(); | |
7c673cae | 39 | |
11fdf7f2 | 40 | #else // ROCKSDB_SUPPORT_THREAD_LOCAL |
7c673cae FG |
41 | |
42 | #define IOSTATS_ADD(metric, value) | |
43 | #define IOSTATS_ADD_IF_POSITIVE(metric, value) | |
44 | #define IOSTATS_RESET(metric) | |
45 | #define IOSTATS_RESET_ALL() | |
46 | #define IOSTATS_SET_THREAD_POOL_ID(value) | |
47 | #define IOSTATS_THREAD_POOL_ID() | |
48 | #define IOSTATS(metric) 0 | |
49 | ||
50 | #define IOSTATS_TIMER_GUARD(metric) | |
51 | ||
11fdf7f2 | 52 | #endif // ROCKSDB_SUPPORT_THREAD_LOCAL |