Coverage Report

Created: 2026-03-16 13:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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 <gen_cpp/HeartbeatService_types.h>
22
#include <gen_cpp/PlanNodes_types.h>
23
#include <stdint.h>
24
25
#include <cstring>
26
#include <iomanip>
27
#include <map>
28
#include <sstream> // IWYU pragma: keep
29
#include <utility>
30
31
#include "common/version_internal.h"
32
#include "fmt/core.h"
33
#include "util/uid_util.h"
34
35
namespace doris {
36
37
935k
std::string print_plan_node_type(const TPlanNodeType::type& type) {
38
935k
    std::map<int, const char*>::const_iterator i;
39
935k
    i = _TPlanNodeType_VALUES_TO_NAMES.find(type);
40
41
935k
    if (i != _TPlanNodeType_VALUES_TO_NAMES.end()) {
42
934k
        return i->second;
43
934k
    }
44
45
392
    return "Invalid plan node type";
46
935k
}
47
48
12
std::string get_build_version(bool compact) {
49
12
    std::stringstream ss;
50
    // clang-format off
51
12
    ss << version::doris_build_version()
52
12
#if defined(__x86_64__) || defined(_M_X64)
53
12
#ifdef __AVX2__
54
12
       << "(AVX2)"
55
#else
56
       << "(SSE4.2)"
57
#endif
58
#elif defined(__aarch64__)
59
       << "(AArch64)"
60
#endif
61
#ifdef NDEBUG
62
       << " RELEASE"
63
#else
64
12
       << " DEBUG"
65
12
#if defined(ADDRESS_SANITIZER)
66
12
       << " with ASAN"
67
#elif defined(LEAK_SANITIZER)
68
       << " with LSAN"
69
#elif defined(THREAD_SANITIZER)
70
       << " with TSAN"
71
#elif defined(UNDEFINED_BEHAVIOR_SANITIZER)
72
       << " with UBSAN"
73
#elif defined(MEMORY_SANITIZER)
74
       << " with MSAN"
75
#elif defined(BLACKLIST_SANITIZER)
76
       << " with BLSAN"
77
#endif
78
12
#endif
79
12
       << (version::doris_feature_list().empty() ? "" : " features: " + version::doris_feature_list())
80
12
       << " (build " << version::doris_build_hash() << ")";
81
    // clang-format on
82
83
12
    if (!compact) {
84
10
        ss << std::endl
85
10
           << "Built on " << version::doris_build_time() << " by " << version::doris_build_info();
86
10
    }
87
88
12
    return ss.str();
89
12
}
90
91
5.18k
std::string get_short_version() {
92
5.18k
    static std::string short_version(std::string(version::doris_build_version()) + "-" +
93
5.18k
                                     version::doris_build_short_hash());
94
5.18k
    return short_version;
95
5.18k
}
96
97
11
std::string get_version_string(bool compact) {
98
11
    std::stringstream ss;
99
11
    ss << " version " << get_build_version(compact);
100
11
    return ss.str();
101
11
}
102
103
52
std::string hexdump(const char* buf, int len) {
104
52
    std::stringstream ss;
105
52
    ss << std::hex << std::uppercase;
106
435
    for (int i = 0; i < len; ++i) {
107
383
        ss << std::setfill('0') << std::setw(2) << ((uint16_t)buf[i] & 0xff);
108
383
    }
109
52
    return ss.str();
110
52
}
111
112
9
bvar::Status<uint64_t> be_version_metrics("doris_be_version", [] {
113
9
    std::stringstream ss;
114
9
    ss << version::doris_build_version_major() << 0 << version::doris_build_version_minor() << 0
115
9
       << version::doris_build_version_patch();
116
9
    if (version::doris_build_version_hotfix() > 0) {
117
0
        ss << 0 << version::doris_build_version_hotfix();
118
0
    }
119
9
    return std::strtoul(ss.str().c_str(), nullptr, 10);
120
9
}());
121
122
2.75k
std::string PrintThriftNetworkAddress(const TNetworkAddress& add) {
123
2.75k
    std::stringstream ss;
124
2.75k
    add.printTo(ss);
125
2.75k
    return ss.str();
126
2.75k
}
127
128
119
std::string PrintFrontendInfos(const std::vector<TFrontendInfo>& fe_infos) {
129
119
    std::stringstream ss;
130
119
    const size_t count = fe_infos.size();
131
132
238
    for (int i = 0; i < count; ++i) {
133
119
        fe_infos[i].printTo(ss);
134
119
        ss << ' ';
135
119
    }
136
137
119
    return ss.str();
138
119
}
139
140
9
std::string PrintFrontendInfo(const TFrontendInfo& fe_info) {
141
9
    std::stringstream ss;
142
9
    fe_info.printTo(ss);
143
9
    return ss.str();
144
9
}
145
146
3
std::string PrintInstanceStandardInfo(const TUniqueId& qid, const TUniqueId& iid) {
147
3
    return fmt::format("{}|{}", print_id(qid), print_id(iid));
148
3
}
149
150
} // namespace doris