Coverage Report

Created: 2026-07-10 18:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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
    std::atomic<int64_t> inverted_index_bytes_read_from_remote = 0;
42
    std::atomic<int64_t> segment_footer_index_bytes_read_from_remote = 0;
43
};
44
class FileCacheMetrics {
45
public:
46
718k
    static FileCacheMetrics& instance() {
47
718k
        static FileCacheMetrics s_metrics;
48
718k
        return s_metrics;
49
718k
    }
50
51
1
    FileCacheMetrics() {
52
1
        FileCacheStatistics stats;
53
1
        update(&stats);
54
1
    }
55
56
    void update(FileCacheStatistics* stats);
57
    std::shared_ptr<AtomicStatistics> report();
58
59
private:
60
    void register_entity();
61
    void update_metrics_callback();
62
63
private:
64
    std::mutex _mtx;
65
    // use shared_ptr for concurrent
66
    std::shared_ptr<AtomicStatistics> _statistics;
67
};
68
69
FileCacheStatistics diff_file_cache_statistics(const FileCacheStatistics& current,
70
                                               const FileCacheStatistics& previous);
71
72
struct FileCacheProfileReporter {
73
    RuntimeProfile* _profile = nullptr;
74
    RuntimeProfile::Counter* num_local_io_total = nullptr;
75
    RuntimeProfile::Counter* num_remote_io_total = nullptr;
76
    RuntimeProfile::Counter* num_peer_io_total = nullptr;
77
    RuntimeProfile::Counter* local_io_timer = nullptr;
78
    RuntimeProfile::Counter* bytes_scanned_from_cache = nullptr;
79
    RuntimeProfile::Counter* bytes_scanned_from_remote = nullptr;
80
    RuntimeProfile::Counter* bytes_scanned_from_peer = nullptr;
81
    RuntimeProfile::Counter* remote_io_timer = nullptr;
82
    RuntimeProfile::Counter* peer_io_timer = nullptr;
83
    RuntimeProfile::Counter* remote_wait_timer = nullptr;
84
    RuntimeProfile::Counter* write_cache_io_timer = nullptr;
85
    RuntimeProfile::Counter* bytes_write_into_cache = nullptr;
86
    RuntimeProfile::Counter* num_skip_cache_io_total = nullptr;
87
    RuntimeProfile::Counter* read_cache_file_directly_timer = nullptr;
88
    RuntimeProfile::Counter* cache_get_or_set_timer = nullptr;
89
    RuntimeProfile::Counter* lock_wait_timer = nullptr;
90
    RuntimeProfile::Counter* get_timer = nullptr;
91
    RuntimeProfile::Counter* set_timer = nullptr;
92
93
    RuntimeProfile::Counter* inverted_index_num_local_io_total = nullptr;
94
    RuntimeProfile::Counter* inverted_index_num_remote_io_total = nullptr;
95
    RuntimeProfile::Counter* inverted_index_num_peer_io_total = nullptr;
96
    RuntimeProfile::Counter* inverted_index_bytes_scanned_from_cache = nullptr;
97
    RuntimeProfile::Counter* inverted_index_bytes_scanned_from_remote = nullptr;
98
    RuntimeProfile::Counter* inverted_index_bytes_scanned_from_peer = nullptr;
99
    RuntimeProfile::Counter* inverted_index_local_io_timer = nullptr;
100
    RuntimeProfile::Counter* inverted_index_remote_io_timer = nullptr;
101
    RuntimeProfile::Counter* inverted_index_peer_io_timer = nullptr;
102
    RuntimeProfile::Counter* inverted_index_io_timer = nullptr;
103
104
    RuntimeProfile::Counter* segment_footer_index_num_local_io_total = nullptr;
105
    RuntimeProfile::Counter* segment_footer_index_num_remote_io_total = nullptr;
106
    RuntimeProfile::Counter* segment_footer_index_num_peer_io_total = nullptr;
107
    RuntimeProfile::Counter* segment_footer_index_bytes_scanned_from_cache = nullptr;
108
    RuntimeProfile::Counter* segment_footer_index_bytes_scanned_from_remote = nullptr;
109
    RuntimeProfile::Counter* segment_footer_index_bytes_scanned_from_peer = nullptr;
110
    RuntimeProfile::Counter* segment_footer_index_local_io_timer = nullptr;
111
    RuntimeProfile::Counter* segment_footer_index_remote_io_timer = nullptr;
112
    RuntimeProfile::Counter* segment_footer_index_peer_io_timer = nullptr;
113
114
    // Cross-CG / Same-CG peer read counters
115
    RuntimeProfile::Counter* num_cross_cg_peer_io_total = nullptr;
116
    RuntimeProfile::Counter* bytes_scanned_from_cross_cg_peer = nullptr;
117
    RuntimeProfile::Counter* cross_cg_peer_io_timer = nullptr;
118
    RuntimeProfile::Counter* num_same_cg_peer_io_total = nullptr;
119
    RuntimeProfile::Counter* bytes_scanned_from_same_cg_peer = nullptr;
120
    RuntimeProfile::Counter* same_cg_peer_io_timer = nullptr;
121
    RuntimeProfile::Counter* num_peer_race_peer_win = nullptr;
122
    RuntimeProfile::Counter* num_peer_race_s3_win = nullptr;
123
    RuntimeProfile::Counter* num_peer_lazy_fetch = nullptr;
124
    RuntimeProfile::Counter* peer_lazy_fetch_timer = nullptr;
125
126
    FileCacheProfileReporter(RuntimeProfile* profile);
127
    void update(const FileCacheStatistics* statistics) const;
128
};
129
130
} // namespace io
131
} // namespace doris