be/src/io/cache/block_file_cache_profile.cpp
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | |
18 | | #include "io/cache/block_file_cache_profile.h" |
19 | | |
20 | | #include <functional> |
21 | | #include <memory> |
22 | | #include <string> |
23 | | |
24 | | #include "common/metrics/doris_metrics.h" |
25 | | |
26 | | namespace doris::io { |
27 | | |
28 | 0 | std::shared_ptr<AtomicStatistics> FileCacheMetrics::report() { |
29 | 0 | std::shared_ptr<AtomicStatistics> output_stats = std::make_shared<AtomicStatistics>(); |
30 | 0 | std::lock_guard lock(_mtx); |
31 | 0 | output_stats->num_io_bytes_read_from_cache += _statistics->num_io_bytes_read_from_cache; |
32 | 0 | output_stats->num_io_bytes_read_from_remote += _statistics->num_io_bytes_read_from_remote; |
33 | 0 | output_stats->num_io_bytes_read_from_peer += _statistics->num_io_bytes_read_from_peer; |
34 | 0 | return output_stats; |
35 | 0 | } |
36 | | |
37 | 9.84k | void FileCacheMetrics::update(FileCacheStatistics* input_stats) { |
38 | 9.84k | if (_statistics == nullptr) { |
39 | 1 | std::lock_guard<std::mutex> lock(_mtx); |
40 | 1 | if (_statistics == nullptr) { |
41 | 1 | _statistics = std::make_shared<AtomicStatistics>(); |
42 | 1 | register_entity(); |
43 | 1 | } |
44 | 1 | } |
45 | 9.84k | _statistics->num_io_bytes_read_from_cache += input_stats->bytes_read_from_local; |
46 | 9.84k | _statistics->num_io_bytes_read_from_remote += input_stats->bytes_read_from_remote; |
47 | 9.84k | _statistics->num_io_bytes_read_from_peer += input_stats->bytes_read_from_peer; |
48 | 9.84k | } |
49 | | |
50 | 1 | void FileCacheMetrics::register_entity() { |
51 | 1 | DorisMetrics::instance()->server_entity()->register_hook( |
52 | 1 | "block_file_cache", [this]() { update_metrics_callback(); }); |
53 | 1 | } |
54 | | |
55 | 0 | void FileCacheMetrics::update_metrics_callback() { |
56 | 0 | std::shared_ptr<AtomicStatistics> stats = report(); |
57 | 0 | DorisMetrics::instance()->num_io_bytes_read_from_cache->set_value( |
58 | 0 | stats->num_io_bytes_read_from_cache); |
59 | 0 | DorisMetrics::instance()->num_io_bytes_read_from_remote->set_value( |
60 | 0 | stats->num_io_bytes_read_from_remote); |
61 | 0 | DorisMetrics::instance()->num_io_bytes_read_from_peer->set_value( |
62 | 0 | stats->num_io_bytes_read_from_peer); |
63 | 0 | DorisMetrics::instance()->num_io_bytes_read_total->set_value( |
64 | 0 | stats->num_io_bytes_read_from_cache + stats->num_io_bytes_read_from_remote + |
65 | 0 | stats->num_io_bytes_read_from_peer); |
66 | 0 | } |
67 | | |
68 | 6 | FileCacheProfileReporter::FileCacheProfileReporter(RuntimeProfile* profile) { |
69 | 6 | static const char* cache_profile = "FileCache"; |
70 | 6 | ADD_TIMER_WITH_LEVEL(profile, cache_profile, 2); |
71 | 6 | num_local_io_total = |
72 | 6 | ADD_CHILD_COUNTER_WITH_LEVEL(profile, "NumLocalIOTotal", TUnit::UNIT, cache_profile, 1); |
73 | 6 | num_remote_io_total = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "NumRemoteIOTotal", TUnit::UNIT, |
74 | 6 | cache_profile, 1); |
75 | 6 | num_peer_io_total = |
76 | 6 | ADD_CHILD_COUNTER_WITH_LEVEL(profile, "NumPeerIOTotal", TUnit::UNIT, cache_profile, 1); |
77 | 6 | local_io_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "LocalIOUseTimer", cache_profile, 1); |
78 | 6 | remote_io_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "RemoteIOUseTimer", cache_profile, 1); |
79 | 6 | peer_io_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "PeerIOUseTimer", cache_profile, 1); |
80 | 6 | remote_wait_timer = |
81 | 6 | ADD_CHILD_TIMER_WITH_LEVEL(profile, "WaitOtherDownloaderTimer", cache_profile, 1); |
82 | 6 | write_cache_io_timer = |
83 | 6 | ADD_CHILD_TIMER_WITH_LEVEL(profile, "WriteCacheIOUseTimer", cache_profile, 1); |
84 | 6 | bytes_write_into_cache = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "BytesWriteIntoCache", |
85 | 6 | TUnit::BYTES, cache_profile, 1); |
86 | 6 | num_skip_cache_io_total = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "NumSkipCacheIOTotal", |
87 | 6 | TUnit::UNIT, cache_profile, 1); |
88 | 6 | bytes_scanned_from_cache = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "BytesScannedFromCache", |
89 | 6 | TUnit::BYTES, cache_profile, 1); |
90 | 6 | bytes_scanned_from_remote = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "BytesScannedFromRemote", |
91 | 6 | TUnit::BYTES, cache_profile, 1); |
92 | 6 | bytes_scanned_from_peer = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "BytesScannedFromPeer", |
93 | 6 | TUnit::BYTES, cache_profile, 1); |
94 | 6 | read_cache_file_directly_timer = |
95 | 6 | ADD_CHILD_TIMER_WITH_LEVEL(profile, "ReadCacheFileDirectlyTimer", cache_profile, 1); |
96 | 6 | cache_get_or_set_timer = |
97 | 6 | ADD_CHILD_TIMER_WITH_LEVEL(profile, "CacheGetOrSetTimer", cache_profile, 1); |
98 | 6 | lock_wait_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "LockWaitTimer", cache_profile, 1); |
99 | 6 | get_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "GetTimer", cache_profile, 1); |
100 | 6 | set_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "SetTimer", cache_profile, 1); |
101 | | |
102 | 6 | inverted_index_num_local_io_total = ADD_CHILD_COUNTER_WITH_LEVEL( |
103 | 6 | profile, "InvertedIndexNumLocalIOTotal", TUnit::UNIT, cache_profile, 1); |
104 | 6 | inverted_index_num_remote_io_total = ADD_CHILD_COUNTER_WITH_LEVEL( |
105 | 6 | profile, "InvertedIndexNumRemoteIOTotal", TUnit::UNIT, cache_profile, 1); |
106 | 6 | inverted_index_num_peer_io_total = ADD_CHILD_COUNTER_WITH_LEVEL( |
107 | 6 | profile, "InvertedIndexNumPeerIOTotal", TUnit::UNIT, cache_profile, 1); |
108 | 6 | inverted_index_bytes_scanned_from_cache = ADD_CHILD_COUNTER_WITH_LEVEL( |
109 | 6 | profile, "InvertedIndexBytesScannedFromCache", TUnit::BYTES, cache_profile, 1); |
110 | 6 | inverted_index_bytes_scanned_from_remote = ADD_CHILD_COUNTER_WITH_LEVEL( |
111 | 6 | profile, "InvertedIndexBytesScannedFromRemote", TUnit::BYTES, cache_profile, 1); |
112 | 6 | inverted_index_bytes_scanned_from_peer = ADD_CHILD_COUNTER_WITH_LEVEL( |
113 | 6 | profile, "InvertedIndexBytesScannedFromPeer", TUnit::BYTES, cache_profile, 1); |
114 | 6 | inverted_index_local_io_timer = |
115 | 6 | ADD_CHILD_TIMER_WITH_LEVEL(profile, "InvertedIndexLocalIOUseTimer", cache_profile, 1); |
116 | 6 | inverted_index_remote_io_timer = |
117 | 6 | ADD_CHILD_TIMER_WITH_LEVEL(profile, "InvertedIndexRemoteIOUseTimer", cache_profile, 1); |
118 | 6 | inverted_index_peer_io_timer = |
119 | 6 | ADD_CHILD_TIMER_WITH_LEVEL(profile, "InvertedIndexPeerIOUseTimer", cache_profile, 1); |
120 | 6 | inverted_index_io_timer = |
121 | 6 | ADD_CHILD_TIMER_WITH_LEVEL(profile, "InvertedIndexIOTimer", cache_profile, 1); |
122 | 6 | } |
123 | | |
124 | 6 | void FileCacheProfileReporter::update(const FileCacheStatistics* statistics) const { |
125 | 6 | COUNTER_UPDATE(num_local_io_total, statistics->num_local_io_total); |
126 | 6 | COUNTER_UPDATE(num_remote_io_total, statistics->num_remote_io_total); |
127 | 6 | COUNTER_UPDATE(num_peer_io_total, statistics->num_peer_io_total); |
128 | 6 | COUNTER_UPDATE(local_io_timer, statistics->local_io_timer); |
129 | 6 | COUNTER_UPDATE(remote_io_timer, statistics->remote_io_timer); |
130 | 6 | COUNTER_UPDATE(peer_io_timer, statistics->peer_io_timer); |
131 | 6 | COUNTER_UPDATE(remote_wait_timer, statistics->remote_wait_timer); |
132 | 6 | COUNTER_UPDATE(write_cache_io_timer, statistics->write_cache_io_timer); |
133 | 6 | COUNTER_UPDATE(bytes_write_into_cache, statistics->bytes_write_into_cache); |
134 | 6 | COUNTER_UPDATE(num_skip_cache_io_total, statistics->num_skip_cache_io_total); |
135 | 6 | COUNTER_UPDATE(bytes_scanned_from_cache, statistics->bytes_read_from_local); |
136 | 6 | COUNTER_UPDATE(bytes_scanned_from_remote, statistics->bytes_read_from_remote); |
137 | 6 | COUNTER_UPDATE(bytes_scanned_from_peer, statistics->bytes_read_from_peer); |
138 | 6 | COUNTER_UPDATE(read_cache_file_directly_timer, statistics->read_cache_file_directly_timer); |
139 | 6 | COUNTER_UPDATE(cache_get_or_set_timer, statistics->cache_get_or_set_timer); |
140 | 6 | COUNTER_UPDATE(lock_wait_timer, statistics->lock_wait_timer); |
141 | 6 | COUNTER_UPDATE(get_timer, statistics->get_timer); |
142 | 6 | COUNTER_UPDATE(set_timer, statistics->set_timer); |
143 | | |
144 | 6 | COUNTER_UPDATE(inverted_index_num_local_io_total, |
145 | 6 | statistics->inverted_index_num_local_io_total); |
146 | 6 | COUNTER_UPDATE(inverted_index_num_remote_io_total, |
147 | 6 | statistics->inverted_index_num_remote_io_total); |
148 | 6 | COUNTER_UPDATE(inverted_index_num_peer_io_total, statistics->inverted_index_num_peer_io_total); |
149 | 6 | COUNTER_UPDATE(inverted_index_bytes_scanned_from_cache, |
150 | 6 | statistics->inverted_index_bytes_read_from_local); |
151 | 6 | COUNTER_UPDATE(inverted_index_bytes_scanned_from_remote, |
152 | 6 | statistics->inverted_index_bytes_read_from_remote); |
153 | 6 | COUNTER_UPDATE(inverted_index_bytes_scanned_from_peer, |
154 | 6 | statistics->inverted_index_bytes_read_from_peer); |
155 | 6 | COUNTER_UPDATE(inverted_index_local_io_timer, statistics->inverted_index_local_io_timer); |
156 | 6 | COUNTER_UPDATE(inverted_index_remote_io_timer, statistics->inverted_index_remote_io_timer); |
157 | 6 | COUNTER_UPDATE(inverted_index_peer_io_timer, statistics->inverted_index_peer_io_timer); |
158 | 6 | COUNTER_UPDATE(inverted_index_io_timer, statistics->inverted_index_io_timer); |
159 | 6 | } |
160 | | |
161 | | } // namespace doris::io |