Coverage Report

Created: 2026-01-28 17:33

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
153k
DebugPoints* DebugPoints::instance() {
28
153k
    static DebugPoints instance;
29
153k
    return &instance;
30
153k
}
31
32
13
bool DebugPoints::is_enable(const std::string& name) {
33
13
    return get_debug_point(name) != nullptr;
34
13
}
35
36
153k
std::shared_ptr<DebugPoint> DebugPoints::get_debug_point(const std::string& name) {
37
153k
    if (!config::enable_debug_points) {
38
0
        return nullptr;
39
0
    }
40
153k
    auto map_ptr = _debug_points.load();
41
153k
    auto it = map_ptr->find(name);
42
153k
    if (it == map_ptr->end()) {
43
153k
        return nullptr;
44
153k
    }
45
46
75
    auto debug_point = it->second;
47
75
    if ((debug_point->expire_ms > 0 && MonotonicMillis() >= debug_point->expire_ms) ||
48
75
        (debug_point->execute_limit > 0 &&
49
74
         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
73
    return debug_point;
56
75
}
57
58
62
void DebugPoints::add(const std::string& name, std::shared_ptr<DebugPoint> debug_point) {
59
62
    update([&](DebugPointMap& new_points) { new_points[name] = debug_point; });
60
61
62
    std::ostringstream oss;
62
62
    oss << "{";
63
62
    for (auto [key, value] : debug_point->params) {
64
17
        oss << key << " : " << value << ", ";
65
17
    }
66
62
    oss << "}";
67
68
62
    LOG(INFO) << "add debug point: name=" << name << ", params=" << oss.str();
69
62
}
70
71
44
void DebugPoints::remove(const std::string& name) {
72
44
    bool exists = false;
73
44
    update([&](DebugPointMap& new_points) { exists = new_points.erase(name) > 0; });
74
75
44
    LOG(INFO) << "remove debug point: name=" << name << ", exists=" << exists;
76
44
}
77
78
106
void DebugPoints::update(std::function<void(DebugPointMap&)>&& handler) {
79
106
    auto old_points = _debug_points.load();
80
106
    while (true) {
81
106
        auto new_points = std::make_shared<DebugPointMap>(*old_points);
82
106
        handler(*new_points);
83
106
        if (_debug_points.compare_exchange_strong(
84
106
                    old_points, std::static_pointer_cast<const DebugPointMap>(new_points))) {
85
106
            break;
86
106
        }
87
106
    }
88
106
}
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