be/src/io/cache/block_file_cache_profile.h
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 | | #pragma once |
19 | | |
20 | | #include <gen_cpp/Metrics_types.h> |
21 | | |
22 | | #include <atomic> |
23 | | #include <cstdint> |
24 | | #include <memory> |
25 | | #include <mutex> |
26 | | #include <unordered_map> |
27 | | |
28 | | #include "common/metrics/doris_metrics.h" |
29 | | #include "common/metrics/metrics.h" |
30 | | #include "io/io_common.h" |
31 | | #include "runtime/runtime_profile.h" |
32 | | #include "storage/olap_common.h" |
33 | | |
34 | | namespace doris { |
35 | | namespace io { |
36 | | |
37 | | struct AtomicStatistics { |
38 | | std::atomic<int64_t> num_io_bytes_read_from_cache = 0; |
39 | | std::atomic<int64_t> num_io_bytes_read_from_remote = 0; |
40 | | std::atomic<int64_t> num_io_bytes_read_from_peer = 0; |
41 | | }; |
42 | | class FileCacheMetrics { |
43 | | public: |
44 | 9.79k | static FileCacheMetrics& instance() { |
45 | 9.79k | static FileCacheMetrics s_metrics; |
46 | 9.79k | return s_metrics; |
47 | 9.79k | } |
48 | | |
49 | 1 | FileCacheMetrics() { |
50 | 1 | FileCacheStatistics stats; |
51 | 1 | update(&stats); |
52 | 1 | } |
53 | | |
54 | | void update(FileCacheStatistics* stats); |
55 | | |
56 | | private: |
57 | | std::shared_ptr<AtomicStatistics> report(); |
58 | | void register_entity(); |
59 | | void update_metrics_callback(); |
60 | | |
61 | | private: |
62 | | std::mutex _mtx; |
63 | | // use shared_ptr for concurrent |
64 | | std::shared_ptr<AtomicStatistics> _statistics; |
65 | | }; |
66 | | |
67 | | struct FileCacheProfileReporter { |
68 | | RuntimeProfile::Counter* num_local_io_total = nullptr; |
69 | | RuntimeProfile::Counter* num_remote_io_total = nullptr; |
70 | | RuntimeProfile::Counter* num_peer_io_total = nullptr; |
71 | | RuntimeProfile::Counter* local_io_timer = nullptr; |
72 | | RuntimeProfile::Counter* bytes_scanned_from_cache = nullptr; |
73 | | RuntimeProfile::Counter* bytes_scanned_from_remote = nullptr; |
74 | | RuntimeProfile::Counter* bytes_scanned_from_peer = nullptr; |
75 | | RuntimeProfile::Counter* remote_io_timer = nullptr; |
76 | | RuntimeProfile::Counter* peer_io_timer = nullptr; |
77 | | RuntimeProfile::Counter* remote_wait_timer = nullptr; |
78 | | RuntimeProfile::Counter* write_cache_io_timer = nullptr; |
79 | | RuntimeProfile::Counter* bytes_write_into_cache = nullptr; |
80 | | RuntimeProfile::Counter* num_skip_cache_io_total = nullptr; |
81 | | RuntimeProfile::Counter* read_cache_file_directly_timer = nullptr; |
82 | | RuntimeProfile::Counter* cache_get_or_set_timer = nullptr; |
83 | | RuntimeProfile::Counter* lock_wait_timer = nullptr; |
84 | | RuntimeProfile::Counter* get_timer = nullptr; |
85 | | RuntimeProfile::Counter* set_timer = nullptr; |
86 | | |
87 | | RuntimeProfile::Counter* inverted_index_num_local_io_total = nullptr; |
88 | | RuntimeProfile::Counter* inverted_index_num_remote_io_total = nullptr; |
89 | | RuntimeProfile::Counter* inverted_index_num_peer_io_total = nullptr; |
90 | | RuntimeProfile::Counter* inverted_index_bytes_scanned_from_cache = nullptr; |
91 | | RuntimeProfile::Counter* inverted_index_bytes_scanned_from_remote = nullptr; |
92 | | RuntimeProfile::Counter* inverted_index_bytes_scanned_from_peer = nullptr; |
93 | | RuntimeProfile::Counter* inverted_index_local_io_timer = nullptr; |
94 | | RuntimeProfile::Counter* inverted_index_remote_io_timer = nullptr; |
95 | | RuntimeProfile::Counter* inverted_index_peer_io_timer = nullptr; |
96 | | RuntimeProfile::Counter* inverted_index_io_timer = nullptr; |
97 | | |
98 | | FileCacheProfileReporter(RuntimeProfile* profile); |
99 | | void update(const FileCacheStatistics* statistics) const; |
100 | | }; |
101 | | |
102 | | } // namespace io |
103 | | } // namespace doris |