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