Coverage Report

Created: 2026-03-13 14:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/util/debug_points.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 "util/debug_points.h"
19
20
#include "common/logging.h"
21
#include "util/time.h"
22
23
namespace doris {
24
25
8
DebugPoints::DebugPoints() : _debug_points(std::make_shared<const DebugPointMap>()) {}
26
27
271M
DebugPoints* DebugPoints::instance() {
28
271M
    static DebugPoints instance;
29
271M
    return &instance;
30
271M
}
31
32
1.77k
bool DebugPoints::is_enable(const std::string& name) {
33
1.77k
    return get_debug_point(name) != nullptr;
34
1.77k
}
35
36
271M
std::shared_ptr<DebugPoint> DebugPoints::get_debug_point(const std::string& name) {
37
271M
    if (!config::enable_debug_points) {
38
0
        return nullptr;
39
0
    }
40
271M
    auto map_ptr = _debug_points.load();
41
271M
    auto it = map_ptr->find(name);
42
273M
    if (it == map_ptr->end()) {
43
273M
        return nullptr;
44
273M
    }
45
46
18.4E
    auto debug_point = it->second;
47
18.4E
    if ((debug_point->expire_ms > 0 && MonotonicMillis() >= debug_point->expire_ms) ||
48
18.4E
        (debug_point->execute_limit > 0 &&
49
78
         debug_point->execute_num.fetch_add(1, std::memory_order_relaxed) >=
50
4
                 debug_point->execute_limit)) {
51
2
        remove(name);
52
2
        return nullptr;
53
2
    }
54
55
18.4E
    return debug_point;
56
18.4E
}
57
58
66
void DebugPoints::add(const std::string& name, std::shared_ptr<DebugPoint> debug_point) {
59
66
    update([&](DebugPointMap& new_points) { new_points[name] = debug_point; });
60
61
66
    std::ostringstream oss;
62
66
    oss << "{";
63
66
    for (auto [key, value] : debug_point->params) {
64
17
        oss << key << " : " << value << ", ";
65
17
    }
66
66
    oss << "}";
67
68
66
    LOG(INFO) << "add debug point: name=" << name << ", params=" << oss.str();
69
66
}
70
71
54
void DebugPoints::remove(const std::string& name) {
72
54
    bool exists = false;
73
54
    update([&](DebugPointMap& new_points) { exists = new_points.erase(name) > 0; });
74
75
54
    LOG(INFO) << "remove debug point: name=" << name << ", exists=" << exists;
76
54
}
77
78
120
void DebugPoints::update(std::function<void(DebugPointMap&)>&& handler) {
79
120
    auto old_points = _debug_points.load();
80
120
    while (true) {
81
120
        auto new_points = std::make_shared<DebugPointMap>(*old_points);
82
120
        handler(*new_points);
83
120
        if (_debug_points.compare_exchange_strong(
84
120
                    old_points, std::static_pointer_cast<const DebugPointMap>(new_points))) {
85
120
            break;
86
120
        }
87
120
    }
88
120
}
89
90
10
void DebugPoints::clear() {
91
10
    _debug_points.store(std::make_shared<const DebugPointMap>());
92
    LOG(INFO) << "clear debug points";
93
10
}
94
95
} // namespace doris