Coverage Report

Created: 2026-10-14 20:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/util/debug_util.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_util.h"
19
20
#include <bvar/bvar.h>
21
#include <bvar/multi_dimension.h>
22
#include <gen_cpp/HeartbeatService_types.h>
23
#include <gen_cpp/PlanNodes_types.h>
24
#include <gflags/gflags.h>
25
#include <stdint.h>
26
27
#include <cstdlib>
28
#include <cstring>
29
#include <iomanip>
30
#include <list>
31
#include <map>
32
#include <sstream> // IWYU pragma: keep
33
#include <string>
34
#include <utility>
35
36
#include "common/check.h"
37
#include "common/config.h"
38
#include "common/version_internal.h"
39
#include "fmt/core.h"
40
#include "util/uid_util.h"
41
42
namespace doris {
43
44
96.3k
std::string print_plan_node_type(const TPlanNodeType::type& type) {
45
96.3k
    std::map<int, const char*>::const_iterator i;
46
96.3k
    i = _TPlanNodeType_VALUES_TO_NAMES.find(type);
47
48
96.3k
    if (i != _TPlanNodeType_VALUES_TO_NAMES.end()) {
49
96.3k
        return i->second;
50
96.3k
    }
51
52
0
    return "Invalid plan node type";
53
96.3k
}
54
55
0
std::string get_build_version(bool compact) {
56
0
    std::stringstream ss;
57
    // clang-format off
58
0
    ss << version::doris_build_version()
59
0
#if defined(__x86_64__) || defined(_M_X64)
60
0
#ifdef __AVX2__
61
0
       << "(AVX2)"
62
#else
63
       << "(SSE4.2)"
64
#endif
65
#elif defined(__aarch64__)
66
       << "(AArch64)"
67
#endif
68
#ifdef NDEBUG
69
       << " RELEASE"
70
#else
71
0
       << " DEBUG"
72
0
#if defined(ADDRESS_SANITIZER)
73
0
       << " with ASAN"
74
#elif defined(LEAK_SANITIZER)
75
       << " with LSAN"
76
#elif defined(THREAD_SANITIZER)
77
       << " with TSAN"
78
#elif defined(UNDEFINED_BEHAVIOR_SANITIZER)
79
       << " with UBSAN"
80
#elif defined(MEMORY_SANITIZER)
81
       << " with MSAN"
82
#elif defined(BLACKLIST_SANITIZER)
83
       << " with BLSAN"
84
#endif
85
0
#endif
86
0
       << (version::doris_feature_list().empty() ? "" : " features: " + version::doris_feature_list())
87
0
       << " (build " << version::doris_build_hash() << ")";
88
    // clang-format on
89
90
0
    if (!compact) {
91
0
        ss << std::endl
92
0
           << "Built on " << version::doris_build_time() << " by " << version::doris_build_info();
93
0
    }
94
95
0
    return ss.str();
96
0
}
97
98
29
std::string get_short_version() {
99
29
    static std::string short_version(std::string(version::doris_build_version()) + "-" +
100
29
                                     version::doris_build_short_hash());
101
29
    return short_version;
102
29
}
103
104
0
std::string get_version_string(bool compact) {
105
0
    std::stringstream ss;
106
0
    ss << " version " << get_build_version(compact);
107
0
    return ss.str();
108
0
}
109
110
88
std::string hexdump(const char* buf, int len) {
111
88
    std::stringstream ss;
112
88
    ss << std::hex << std::uppercase;
113
982
    for (int i = 0; i < len; ++i) {
114
894
        ss << std::setfill('0') << std::setw(2) << ((uint16_t)buf[i] & 0xff);
115
894
    }
116
88
    return ss.str();
117
88
}
118
119
namespace {
120
121
1
uint64_t get_be_version_metric_value() {
122
1
    std::stringstream ss;
123
1
    ss << version::doris_build_version_major() << 0 << version::doris_build_version_minor() << 0
124
1
       << version::doris_build_version_patch();
125
1
    if (version::doris_build_version_hotfix() > 0) {
126
0
        ss << 0 << version::doris_build_version_hotfix();
127
0
    }
128
1
    return std::strtoul(ss.str().c_str(), nullptr, 10);
129
1
}
130
131
} // namespace
132
133
1
void init_be_version_metrics() {
134
    // MultiDimension metrics are omitted from /brpc_metrics while this brpc flag is 0.
135
1
    DORIS_CHECK(
136
1
            !google::SetCommandLineOption("bvar_max_dump_multi_dimension_metric_number",
137
1
                                          config::bvar_max_dump_multi_dimension_metric_num.c_str())
138
1
                     .empty());
139
140
1
    static const bool initialized = [] {
141
1
        static bvar::MultiDimension<bvar::Status<uint64_t>> metrics(
142
1
                "doris_be_version", {"version", "major", "minor", "patch", "hotfix", "short_hash"});
143
1
        auto* metric = metrics.get_stats(
144
1
                std::list<std::string> {version::doris_build_version(),
145
1
                                        std::to_string(version::doris_build_version_major()),
146
1
                                        std::to_string(version::doris_build_version_minor()),
147
1
                                        std::to_string(version::doris_build_version_patch()),
148
1
                                        std::to_string(version::doris_build_version_hotfix()),
149
1
                                        version::doris_build_short_hash()});
150
1
        DORIS_CHECK(metric != nullptr);
151
1
        metric->set_value(get_be_version_metric_value());
152
1
        return true;
153
1
    }();
154
1
    static_cast<void>(initialized);
155
1
}
156
157
0
std::string PrintThriftNetworkAddress(const TNetworkAddress& add) {
158
0
    std::stringstream ss;
159
0
    add.printTo(ss);
160
0
    return ss.str();
161
0
}
162
163
0
std::string PrintFrontendInfos(const std::vector<TFrontendInfo>& fe_infos) {
164
0
    std::stringstream ss;
165
0
    const size_t count = fe_infos.size();
166
167
0
    for (int i = 0; i < count; ++i) {
168
0
        fe_infos[i].printTo(ss);
169
0
        ss << ' ';
170
0
    }
171
172
0
    return ss.str();
173
0
}
174
175
9
std::string PrintFrontendInfo(const TFrontendInfo& fe_info) {
176
9
    std::stringstream ss;
177
9
    fe_info.printTo(ss);
178
9
    return ss.str();
179
9
}
180
181
20
std::string PrintInstanceStandardInfo(const TUniqueId& qid, const TUniqueId& iid) {
182
20
    return fmt::format("{}|{}", print_id(qid), print_id(iid));
183
20
}
184
185
} // namespace doris