Coverage Report

Created: 2026-10-29 20:07

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