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/iostats_context_imp.h"
8 #include "rocksdb/env.h"
10 namespace ROCKSDB_NAMESPACE
{
12 #ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
13 __thread IOStatsContext iostats_context
;
16 IOStatsContext
* get_iostats_context() {
17 #ifdef ROCKSDB_SUPPORT_THREAD_LOCAL
18 return &iostats_context
;
24 void IOStatsContext::Reset() {
25 thread_pool_id
= Env::Priority::TOTAL
;
33 prepare_write_nanos
= 0;
38 #define IOSTATS_CONTEXT_OUTPUT(counter) \
39 if (!exclude_zero_counters || counter > 0) { \
40 ss << #counter << " = " << counter << ", "; \
43 std::string
IOStatsContext::ToString(bool exclude_zero_counters
) const {
44 std::ostringstream ss
;
45 IOSTATS_CONTEXT_OUTPUT(thread_pool_id
);
46 IOSTATS_CONTEXT_OUTPUT(bytes_read
);
47 IOSTATS_CONTEXT_OUTPUT(bytes_written
);
48 IOSTATS_CONTEXT_OUTPUT(open_nanos
);
49 IOSTATS_CONTEXT_OUTPUT(allocate_nanos
);
50 IOSTATS_CONTEXT_OUTPUT(write_nanos
);
51 IOSTATS_CONTEXT_OUTPUT(read_nanos
);
52 IOSTATS_CONTEXT_OUTPUT(range_sync_nanos
);
53 IOSTATS_CONTEXT_OUTPUT(fsync_nanos
);
54 IOSTATS_CONTEXT_OUTPUT(prepare_write_nanos
);
55 IOSTATS_CONTEXT_OUTPUT(logger_nanos
);
57 std::string str
= ss
.str();
58 str
.erase(str
.find_last_not_of(", ") + 1);
62 } // namespace ROCKSDB_NAMESPACE