Coverage Report

Created: 2026-03-19 18:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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
18.2k
void FileCacheMetrics::update(FileCacheStatistics* input_stats) {
38
18.2k
    if (_statistics == nullptr) {
39
2
        std::lock_guard<std::mutex> lock(_mtx);
40
2
        if (_statistics == nullptr) {
41
2
            _statistics = std::make_shared<AtomicStatistics>();
42
2
            register_entity();
43
2
        }
44
2
    }
45
18.2k
    _statistics->num_io_bytes_read_from_cache += input_stats->bytes_read_from_local;
46
18.2k
    _statistics->num_io_bytes_read_from_remote += input_stats->bytes_read_from_remote;
47
18.2k
    _statistics->num_io_bytes_read_from_peer += input_stats->bytes_read_from_peer;
48
18.2k
}
49
50
2
void FileCacheMetrics::register_entity() {
51
2
    DorisMetrics::instance()->server_entity()->register_hook(
52
2
            "block_file_cache", [this]() { update_metrics_callback(); });
53
2
}
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
12
FileCacheProfileReporter::FileCacheProfileReporter(RuntimeProfile* profile) {
69
12
    static const char* cache_profile = "FileCache";
70
12
    ADD_TIMER_WITH_LEVEL(profile, cache_profile, 2);
71
12
    num_local_io_total =
72
12
            ADD_CHILD_COUNTER_WITH_LEVEL(profile, "NumLocalIOTotal", TUnit::UNIT, cache_profile, 1);
73
12
    num_remote_io_total = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "NumRemoteIOTotal", TUnit::UNIT,
74
12
                                                       cache_profile, 1);
75
12
    num_peer_io_total =
76
12
            ADD_CHILD_COUNTER_WITH_LEVEL(profile, "NumPeerIOTotal", TUnit::UNIT, cache_profile, 1);
77
12
    local_io_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "LocalIOUseTimer", cache_profile, 1);
78
12
    remote_io_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "RemoteIOUseTimer", cache_profile, 1);
79
12
    peer_io_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "PeerIOUseTimer", cache_profile, 1);
80
12
    remote_wait_timer =
81
12
            ADD_CHILD_TIMER_WITH_LEVEL(profile, "WaitOtherDownloaderTimer", cache_profile, 1);
82
12
    write_cache_io_timer =
83
12
            ADD_CHILD_TIMER_WITH_LEVEL(profile, "WriteCacheIOUseTimer", cache_profile, 1);
84
12
    bytes_write_into_cache = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "BytesWriteIntoCache",
85
12
                                                          TUnit::BYTES, cache_profile, 1);
86
12
    num_skip_cache_io_total = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "NumSkipCacheIOTotal",
87
12
                                                           TUnit::UNIT, cache_profile, 1);
88
12
    bytes_scanned_from_cache = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "BytesScannedFromCache",
89
12
                                                            TUnit::BYTES, cache_profile, 1);
90
12
    bytes_scanned_from_remote = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "BytesScannedFromRemote",
91
12
                                                             TUnit::BYTES, cache_profile, 1);
92
12
    bytes_scanned_from_peer = ADD_CHILD_COUNTER_WITH_LEVEL(profile, "BytesScannedFromPeer",
93
12
                                                           TUnit::BYTES, cache_profile, 1);
94
12
    read_cache_file_directly_timer =
95
12
            ADD_CHILD_TIMER_WITH_LEVEL(profile, "ReadCacheFileDirectlyTimer", cache_profile, 1);
96
12
    cache_get_or_set_timer =
97
12
            ADD_CHILD_TIMER_WITH_LEVEL(profile, "CacheGetOrSetTimer", cache_profile, 1);
98
12
    lock_wait_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "LockWaitTimer", cache_profile, 1);
99
12
    get_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "GetTimer", cache_profile, 1);
100
12
    set_timer = ADD_CHILD_TIMER_WITH_LEVEL(profile, "SetTimer", cache_profile, 1);
101
102
12
    inverted_index_num_local_io_total = ADD_CHILD_COUNTER_WITH_LEVEL(
103
12
            profile, "InvertedIndexNumLocalIOTotal", TUnit::UNIT, cache_profile, 1);
104
12
    inverted_index_num_remote_io_total = ADD_CHILD_COUNTER_WITH_LEVEL(
105
12
            profile, "InvertedIndexNumRemoteIOTotal", TUnit::UNIT, cache_profile, 1);
106
12
    inverted_index_num_peer_io_total = ADD_CHILD_COUNTER_WITH_LEVEL(
107
12
            profile, "InvertedIndexNumPeerIOTotal", TUnit::UNIT, cache_profile, 1);
108
12
    inverted_index_bytes_scanned_from_cache = ADD_CHILD_COUNTER_WITH_LEVEL(
109
12
            profile, "InvertedIndexBytesScannedFromCache", TUnit::BYTES, cache_profile, 1);
110
12
    inverted_index_bytes_scanned_from_remote = ADD_CHILD_COUNTER_WITH_LEVEL(
111
12
            profile, "InvertedIndexBytesScannedFromRemote", TUnit::BYTES, cache_profile, 1);
112
12
    inverted_index_bytes_scanned_from_peer = ADD_CHILD_COUNTER_WITH_LEVEL(
113
12
            profile, "InvertedIndexBytesScannedFromPeer", TUnit::BYTES, cache_profile, 1);
114
12
    inverted_index_local_io_timer =
115
12
            ADD_CHILD_TIMER_WITH_LEVEL(profile, "InvertedIndexLocalIOUseTimer", cache_profile, 1);
116
12
    inverted_index_remote_io_timer =
117
12
            ADD_CHILD_TIMER_WITH_LEVEL(profile, "InvertedIndexRemoteIOUseTimer", cache_profile, 1);
118
12
    inverted_index_peer_io_timer =
119
12
            ADD_CHILD_TIMER_WITH_LEVEL(profile, "InvertedIndexPeerIOUseTimer", cache_profile, 1);
120
12
    inverted_index_io_timer =
121
12
            ADD_CHILD_TIMER_WITH_LEVEL(profile, "InvertedIndexIOTimer", cache_profile, 1);
122
12
}
123
124
12
void FileCacheProfileReporter::update(const FileCacheStatistics* statistics) const {
125
12
    COUNTER_UPDATE(num_local_io_total, statistics->num_local_io_total);
126
12
    COUNTER_UPDATE(num_remote_io_total, statistics->num_remote_io_total);
127
12
    COUNTER_UPDATE(num_peer_io_total, statistics->num_peer_io_total);
128
12
    COUNTER_UPDATE(local_io_timer, statistics->local_io_timer);
129
12
    COUNTER_UPDATE(remote_io_timer, statistics->remote_io_timer);
130
12
    COUNTER_UPDATE(peer_io_timer, statistics->peer_io_timer);
131
12
    COUNTER_UPDATE(remote_wait_timer, statistics->remote_wait_timer);
132
12
    COUNTER_UPDATE(write_cache_io_timer, statistics->write_cache_io_timer);
133
12
    COUNTER_UPDATE(bytes_write_into_cache, statistics->bytes_write_into_cache);
134
12
    COUNTER_UPDATE(num_skip_cache_io_total, statistics->num_skip_cache_io_total);
135
12
    COUNTER_UPDATE(bytes_scanned_from_cache, statistics->bytes_read_from_local);
136
12
    COUNTER_UPDATE(bytes_scanned_from_remote, statistics->bytes_read_from_remote);
137
12
    COUNTER_UPDATE(bytes_scanned_from_peer, statistics->bytes_read_from_peer);
138
12
    COUNTER_UPDATE(read_cache_file_directly_timer, statistics->read_cache_file_directly_timer);
139
12
    COUNTER_UPDATE(cache_get_or_set_timer, statistics->cache_get_or_set_timer);
140
12
    COUNTER_UPDATE(lock_wait_timer, statistics->lock_wait_timer);
141
12
    COUNTER_UPDATE(get_timer, statistics->get_timer);
142
12
    COUNTER_UPDATE(set_timer, statistics->set_timer);
143
144
12
    COUNTER_UPDATE(inverted_index_num_local_io_total,
145
12
                   statistics->inverted_index_num_local_io_total);
146
12
    COUNTER_UPDATE(inverted_index_num_remote_io_total,
147
12
                   statistics->inverted_index_num_remote_io_total);
148
12
    COUNTER_UPDATE(inverted_index_num_peer_io_total, statistics->inverted_index_num_peer_io_total);
149
12
    COUNTER_UPDATE(inverted_index_bytes_scanned_from_cache,
150
12
                   statistics->inverted_index_bytes_read_from_local);
151
12
    COUNTER_UPDATE(inverted_index_bytes_scanned_from_remote,
152
12
                   statistics->inverted_index_bytes_read_from_remote);
153
12
    COUNTER_UPDATE(inverted_index_bytes_scanned_from_peer,
154
12
                   statistics->inverted_index_bytes_read_from_peer);
155
12
    COUNTER_UPDATE(inverted_index_local_io_timer, statistics->inverted_index_local_io_timer);
156
12
    COUNTER_UPDATE(inverted_index_remote_io_timer, statistics->inverted_index_remote_io_timer);
157
12
    COUNTER_UPDATE(inverted_index_peer_io_timer, statistics->inverted_index_peer_io_timer);
158
12
    COUNTER_UPDATE(inverted_index_io_timer, statistics->inverted_index_io_timer);
159
12
}
160
161
} // namespace doris::io