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).
7 #include "monitoring/perf_level_imp.h"
8 #include "rocksdb/env.h"
9 #include "util/stop_watch.h"
11 namespace ROCKSDB_NAMESPACE
{
15 explicit PerfStepTimer(
16 uint64_t* metric
, Env
* env
= nullptr, bool use_cpu_time
= false,
17 PerfLevel enable_level
= PerfLevel::kEnableTimeExceptForMutex
,
18 Statistics
* statistics
= nullptr, uint32_t ticker_type
= 0)
19 : perf_counter_enabled_(perf_level
>= enable_level
),
20 use_cpu_time_(use_cpu_time
),
21 env_((perf_counter_enabled_
|| statistics
!= nullptr)
22 ? ((env
!= nullptr) ? env
: Env::Default())
26 statistics_(statistics
),
27 ticker_type_(ticker_type
) {}
34 if (perf_counter_enabled_
|| statistics_
!= nullptr) {
41 return env_
->NowNanos();
43 return env_
->NowCPUNanos();
49 uint64_t now
= time_now();
50 *metric_
+= now
- start_
;
57 uint64_t duration
= time_now() - start_
;
58 if (perf_counter_enabled_
) {
62 if (statistics_
!= nullptr) {
63 RecordTick(statistics_
, ticker_type_
, duration
);
70 const bool perf_counter_enabled_
;
71 const bool use_cpu_time_
;
75 Statistics
* statistics_
;
76 uint32_t ticker_type_
;
79 } // namespace ROCKSDB_NAMESPACE