Coverage Report

Created: 2026-08-11 00:26

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