Coverage Report

Created: 2026-03-16 04:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/util/pretty_printer.h
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
// This file is copied from
18
// https://github.com/apache/impala/blob/branch-2.9.0/be/src/util/pretty-printer.h
19
// and modified by Doris
20
21
#pragma once
22
23
#include <gen_cpp/RuntimeProfile_types.h>
24
25
#include <boost/algorithm/string.hpp>
26
#include <cmath>
27
#include <iomanip>
28
#include <sstream>
29
30
#include "core/binary_cast.hpp"
31
#include "util/cpu_info.h"
32
33
/// Truncate a double to offset decimal places.
34
211k
#define DOUBLE_TRUNCATE(val, offset) floor(val* pow(10, offset)) / pow(10, offset)
35
36
namespace doris {
37
38
/// Methods for printing numeric values with optional units, or other types with an
39
/// applicable operator<<.
40
class PrettyPrinter {
41
public:
42
0
    static std::string print(bool value, TUnit::type ignored, bool verbose = false) {
43
0
        std::stringstream ss;
44
0
        ss << std::boolalpha << value;
45
0
        return ss.str();
46
0
    }
47
48
    /// Prints the 'value' in a human friendly format depending on the data type.
49
    /// i.e. for bytes: 3145728 -> 3MB
50
    /// If verbose is true, this also prints the raw value (before unit conversion) for
51
    /// types where this is applicable.
52
    template <typename T>
53
    static typename std::enable_if<std::is_arithmetic<T>::value, std::string>::type print(
54
24.1M
            T value, TUnit::type unit, bool verbose = false) {
55
24.1M
        std::stringstream ss;
56
24.1M
        ss.flags(std::ios::fixed);
57
24.1M
        switch (unit) {
58
0
        case TUnit::NONE: {
59
            // TUnit::NONE is used as a special counter, it is just a label
60
            //         - PeakMemoryUsage:
61
            //              - BuildKeyArena: 0
62
            //              - ProbeKeyArena: 0
63
            // So do not need output its value
64
0
            return ss.str();
65
0
        }
66
67
4.16k
        case TUnit::UNIT: {
68
4.16k
            std::string nest_unit;
69
4.16k
            double output = get_unit(value, &nest_unit);
70
4.16k
            if (nest_unit.empty()) {
71
4.09k
                ss << value;
72
4.09k
            } else {
73
65
                ss << std::setprecision(PRECISION) << output << nest_unit;
74
65
            }
75
4.16k
            if (verbose) {
76
0
                ss << " (" << value << ")";
77
0
            }
78
4.16k
            break;
79
0
        }
80
81
0
        case TUnit::UNIT_PER_SECOND: {
82
0
            std::string nest_unit;
83
0
            double output = get_unit(value, &nest_unit);
84
0
            if (output == 0) {
85
0
                ss << "0";
86
0
            } else {
87
0
                ss << std::setprecision(PRECISION) << output << " " << nest_unit << "/sec";
88
0
            }
89
0
            break;
90
0
        }
91
92
0
        case TUnit::CPU_TICKS: {
93
0
            if (value < CpuInfo::cycles_per_ms()) {
94
0
                ss << std::setprecision(PRECISION) << (value / 1000.) << "K clock cycles";
95
0
            } else {
96
0
                value /= CpuInfo::cycles_per_ms();
97
0
                print_timems(value, &ss);
98
0
            }
99
0
            break;
100
0
        }
101
102
211k
        case TUnit::TIME_NS: {
103
211k
            ss << std::setprecision(TIME_NS_PRECISION);
104
211k
            if (value >= BILLION) {
105
                /// If the time is over a second, print it up to ms.
106
185
                value /= MILLION;
107
185
                print_timems(value, &ss);
108
211k
            } else if (value >= MILLION) {
109
                /// if the time is over a ms, print it up to microsecond in the unit of ms.
110
112k
                ss << DOUBLE_TRUNCATE(static_cast<double>(value) / MILLION, TIME_NS_PRECISION)
111
112k
                   << "ms";
112
112k
            } else if (value > 1000) {
113
                /// if the time is over a microsecond, print it using unit microsecond
114
5.11k
                ss << DOUBLE_TRUNCATE(static_cast<double>(value) / 1000, TIME_NS_PRECISION) << "us";
115
93.6k
            } else {
116
93.6k
                ss << DOUBLE_TRUNCATE(value, TIME_NS_PRECISION) << "ns";
117
93.6k
            }
118
211k
            break;
119
0
        }
120
121
0
        case TUnit::TIME_MS: {
122
0
            print_timems(value, &ss);
123
0
            break;
124
0
        }
125
126
0
        case TUnit::TIME_S: {
127
0
            print_timems(value * 1000, &ss);
128
0
            break;
129
0
        }
130
131
23.9M
        case TUnit::BYTES: {
132
23.9M
            std::string nest_unit;
133
23.9M
            double output = get_byte_unit(value, &nest_unit);
134
23.9M
            if (output == 0) {
135
6.97M
                ss << "0";
136
16.9M
            } else {
137
16.9M
                ss << std::setprecision(PRECISION) << output << " " << nest_unit;
138
16.9M
                if (verbose) {
139
0
                    ss << " (" << value << ")";
140
0
                }
141
16.9M
            }
142
23.9M
            break;
143
0
        }
144
145
0
        case TUnit::BYTES_PER_SECOND: {
146
0
            std::string nest_unit;
147
0
            double output = get_byte_unit(value, &nest_unit);
148
0
            ss << std::setprecision(PRECISION) << output << " " << nest_unit << "/sec";
149
0
            break;
150
0
        }
151
152
        /// TODO: Remove DOUBLE_VALUE. IMPALA-1649
153
0
        case TUnit::DOUBLE_VALUE: {
154
0
            double output = binary_cast<T, double>(value);
155
0
            ss << std::setprecision(PRECISION) << output << " ";
156
0
            break;
157
0
        }
158
159
0
        default:
160
0
            DCHECK(false) << "Unsupported TUnit: " << value;
161
0
            break;
162
24.1M
        }
163
24.1M
        return ss.str();
164
24.1M
    }
_ZN5doris13PrettyPrinter5printIlEENSt9enable_ifIXsr3std13is_arithmeticIT_EE5valueENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE4typeES3_NS_5TUnit4typeEb
Line
Count
Source
54
23.9M
            T value, TUnit::type unit, bool verbose = false) {
55
23.9M
        std::stringstream ss;
56
23.9M
        ss.flags(std::ios::fixed);
57
23.9M
        switch (unit) {
58
0
        case TUnit::NONE: {
59
            // TUnit::NONE is used as a special counter, it is just a label
60
            //         - PeakMemoryUsage:
61
            //              - BuildKeyArena: 0
62
            //              - ProbeKeyArena: 0
63
            // So do not need output its value
64
0
            return ss.str();
65
0
        }
66
67
4.16k
        case TUnit::UNIT: {
68
4.16k
            std::string nest_unit;
69
4.16k
            double output = get_unit(value, &nest_unit);
70
4.16k
            if (nest_unit.empty()) {
71
4.09k
                ss << value;
72
4.09k
            } else {
73
65
                ss << std::setprecision(PRECISION) << output << nest_unit;
74
65
            }
75
4.16k
            if (verbose) {
76
0
                ss << " (" << value << ")";
77
0
            }
78
4.16k
            break;
79
0
        }
80
81
0
        case TUnit::UNIT_PER_SECOND: {
82
0
            std::string nest_unit;
83
0
            double output = get_unit(value, &nest_unit);
84
0
            if (output == 0) {
85
0
                ss << "0";
86
0
            } else {
87
0
                ss << std::setprecision(PRECISION) << output << " " << nest_unit << "/sec";
88
0
            }
89
0
            break;
90
0
        }
91
92
0
        case TUnit::CPU_TICKS: {
93
0
            if (value < CpuInfo::cycles_per_ms()) {
94
0
                ss << std::setprecision(PRECISION) << (value / 1000.) << "K clock cycles";
95
0
            } else {
96
0
                value /= CpuInfo::cycles_per_ms();
97
0
                print_timems(value, &ss);
98
0
            }
99
0
            break;
100
0
        }
101
102
162k
        case TUnit::TIME_NS: {
103
162k
            ss << std::setprecision(TIME_NS_PRECISION);
104
162k
            if (value >= BILLION) {
105
                /// If the time is over a second, print it up to ms.
106
176
                value /= MILLION;
107
176
                print_timems(value, &ss);
108
162k
            } else if (value >= MILLION) {
109
                /// if the time is over a ms, print it up to microsecond in the unit of ms.
110
63.7k
                ss << DOUBLE_TRUNCATE(static_cast<double>(value) / MILLION, TIME_NS_PRECISION)
111
63.7k
                   << "ms";
112
98.7k
            } else if (value > 1000) {
113
                /// if the time is over a microsecond, print it using unit microsecond
114
5.09k
                ss << DOUBLE_TRUNCATE(static_cast<double>(value) / 1000, TIME_NS_PRECISION) << "us";
115
93.6k
            } else {
116
93.6k
                ss << DOUBLE_TRUNCATE(value, TIME_NS_PRECISION) << "ns";
117
93.6k
            }
118
162k
            break;
119
0
        }
120
121
0
        case TUnit::TIME_MS: {
122
0
            print_timems(value, &ss);
123
0
            break;
124
0
        }
125
126
0
        case TUnit::TIME_S: {
127
0
            print_timems(value * 1000, &ss);
128
0
            break;
129
0
        }
130
131
23.7M
        case TUnit::BYTES: {
132
23.7M
            std::string nest_unit;
133
23.7M
            double output = get_byte_unit(value, &nest_unit);
134
23.7M
            if (output == 0) {
135
6.89M
                ss << "0";
136
16.8M
            } else {
137
16.8M
                ss << std::setprecision(PRECISION) << output << " " << nest_unit;
138
16.8M
                if (verbose) {
139
0
                    ss << " (" << value << ")";
140
0
                }
141
16.8M
            }
142
23.7M
            break;
143
0
        }
144
145
0
        case TUnit::BYTES_PER_SECOND: {
146
0
            std::string nest_unit;
147
0
            double output = get_byte_unit(value, &nest_unit);
148
0
            ss << std::setprecision(PRECISION) << output << " " << nest_unit << "/sec";
149
0
            break;
150
0
        }
151
152
        /// TODO: Remove DOUBLE_VALUE. IMPALA-1649
153
0
        case TUnit::DOUBLE_VALUE: {
154
0
            double output = binary_cast<T, double>(value);
155
0
            ss << std::setprecision(PRECISION) << output << " ";
156
0
            break;
157
0
        }
158
159
0
        default:
160
0
            DCHECK(false) << "Unsupported TUnit: " << value;
161
0
            break;
162
23.9M
        }
163
23.9M
        return ss.str();
164
23.9M
    }
_ZN5doris13PrettyPrinter5printImEENSt9enable_ifIXsr3std13is_arithmeticIT_EE5valueENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE4typeES3_NS_5TUnit4typeEb
Line
Count
Source
54
186k
            T value, TUnit::type unit, bool verbose = false) {
55
186k
        std::stringstream ss;
56
186k
        ss.flags(std::ios::fixed);
57
186k
        switch (unit) {
58
0
        case TUnit::NONE: {
59
            // TUnit::NONE is used as a special counter, it is just a label
60
            //         - PeakMemoryUsage:
61
            //              - BuildKeyArena: 0
62
            //              - ProbeKeyArena: 0
63
            // So do not need output its value
64
0
            return ss.str();
65
0
        }
66
67
0
        case TUnit::UNIT: {
68
0
            std::string nest_unit;
69
0
            double output = get_unit(value, &nest_unit);
70
0
            if (nest_unit.empty()) {
71
0
                ss << value;
72
0
            } else {
73
0
                ss << std::setprecision(PRECISION) << output << nest_unit;
74
0
            }
75
0
            if (verbose) {
76
0
                ss << " (" << value << ")";
77
0
            }
78
0
            break;
79
0
        }
80
81
0
        case TUnit::UNIT_PER_SECOND: {
82
0
            std::string nest_unit;
83
0
            double output = get_unit(value, &nest_unit);
84
0
            if (output == 0) {
85
0
                ss << "0";
86
0
            } else {
87
0
                ss << std::setprecision(PRECISION) << output << " " << nest_unit << "/sec";
88
0
            }
89
0
            break;
90
0
        }
91
92
0
        case TUnit::CPU_TICKS: {
93
0
            if (value < CpuInfo::cycles_per_ms()) {
94
0
                ss << std::setprecision(PRECISION) << (value / 1000.) << "K clock cycles";
95
0
            } else {
96
0
                value /= CpuInfo::cycles_per_ms();
97
0
                print_timems(value, &ss);
98
0
            }
99
0
            break;
100
0
        }
101
102
48.8k
        case TUnit::TIME_NS: {
103
48.8k
            ss << std::setprecision(TIME_NS_PRECISION);
104
48.8k
            if (value >= BILLION) {
105
                /// If the time is over a second, print it up to ms.
106
9
                value /= MILLION;
107
9
                print_timems(value, &ss);
108
48.8k
            } else if (value >= MILLION) {
109
                /// if the time is over a ms, print it up to microsecond in the unit of ms.
110
48.8k
                ss << DOUBLE_TRUNCATE(static_cast<double>(value) / MILLION, TIME_NS_PRECISION)
111
48.8k
                   << "ms";
112
48.8k
            } else if (value > 1000) {
113
                /// if the time is over a microsecond, print it using unit microsecond
114
16
                ss << DOUBLE_TRUNCATE(static_cast<double>(value) / 1000, TIME_NS_PRECISION) << "us";
115
16
            } else {
116
2
                ss << DOUBLE_TRUNCATE(value, TIME_NS_PRECISION) << "ns";
117
2
            }
118
48.8k
            break;
119
0
        }
120
121
0
        case TUnit::TIME_MS: {
122
0
            print_timems(value, &ss);
123
0
            break;
124
0
        }
125
126
0
        case TUnit::TIME_S: {
127
0
            print_timems(value * 1000, &ss);
128
0
            break;
129
0
        }
130
131
137k
        case TUnit::BYTES: {
132
137k
            std::string nest_unit;
133
137k
            double output = get_byte_unit(value, &nest_unit);
134
137k
            if (output == 0) {
135
81.2k
                ss << "0";
136
81.2k
            } else {
137
55.9k
                ss << std::setprecision(PRECISION) << output << " " << nest_unit;
138
55.9k
                if (verbose) {
139
0
                    ss << " (" << value << ")";
140
0
                }
141
55.9k
            }
142
137k
            break;
143
0
        }
144
145
0
        case TUnit::BYTES_PER_SECOND: {
146
0
            std::string nest_unit;
147
0
            double output = get_byte_unit(value, &nest_unit);
148
0
            ss << std::setprecision(PRECISION) << output << " " << nest_unit << "/sec";
149
0
            break;
150
0
        }
151
152
        /// TODO: Remove DOUBLE_VALUE. IMPALA-1649
153
0
        case TUnit::DOUBLE_VALUE: {
154
0
            double output = binary_cast<T, double>(value);
155
0
            ss << std::setprecision(PRECISION) << output << " ";
156
0
            break;
157
0
        }
158
159
0
        default:
160
0
            DCHECK(false) << "Unsupported TUnit: " << value;
161
0
            break;
162
186k
        }
163
186k
        return ss.str();
164
186k
    }
165
166
    /// For non-arithmetics, just write the value as a string and return it.
167
    //
168
    /// TODO: There's no good is_string equivalent, so there's a needless copy for strings
169
    /// here.
170
    template <typename T>
171
    static typename std::enable_if<!std::is_arithmetic<T>::value, std::string>::type print(
172
1.17k
            const T& value, TUnit::type unit) {
173
1.17k
        std::stringstream ss;
174
1.17k
        ss << std::boolalpha << value;
175
1.17k
        return ss.str();
176
1.17k
    }
177
178
    /// Utility method to print an iterable type to a stringstream like [v1, v2, v3]
179
    template <typename I>
180
    static void print_stringList(const I& iterable, TUnit::type unit, std::stringstream* out) {
181
        std::vector<std::string> strings;
182
        for (typename I::const_iterator it = iterable.begin(); it != iterable.end(); ++it) {
183
            std::stringstream ss;
184
            ss << PrettyPrinter::print(*it, unit);
185
            strings.push_back(ss.str());
186
        }
187
188
        (*out) << "[" << boost::algorithm::join(strings, ", ") << "]";
189
    }
190
191
    /// Convenience method
192
22.8M
    static std::string print_bytes(int64_t value) {
193
22.8M
        return value >= 0 ? PrettyPrinter::print(value, TUnit::BYTES)
194
22.8M
                          : "-" + PrettyPrinter::print(std::abs(value), TUnit::BYTES);
195
22.8M
    }
196
197
private:
198
    static const int PRECISION = 2;
199
    static const int TIME_NS_PRECISION = 3;
200
    static const int64_t KILOBYTE = 1024;
201
    static const int64_t MEGABYTE = KILOBYTE * 1024;
202
    static const int64_t GIGABYTE = MEGABYTE * 1024;
203
204
    static const int64_t SECOND = 1000;
205
    static const int64_t MINUTE = SECOND * 60;
206
    static const int64_t HOUR = MINUTE * 60;
207
208
    static const int64_t THOUSAND = 1000;
209
    static const int64_t MILLION = THOUSAND * 1000;
210
    static const int64_t BILLION = MILLION * 1000;
211
212
    template <typename T>
213
23.9M
    static double get_byte_unit(T value, std::string* unit) {
214
23.9M
        if (value == 0) {
215
6.97M
            *unit = "";
216
6.97M
            return value;
217
16.9M
        } else if (value >= GIGABYTE) {
218
8.11M
            *unit = "GB";
219
8.11M
            return value / (double)GIGABYTE;
220
8.82M
        } else if (value >= MEGABYTE) {
221
7.27M
            *unit = "MB";
222
7.27M
            return value / (double)MEGABYTE;
223
7.27M
        } else if (value >= KILOBYTE) {
224
1.36M
            *unit = "KB";
225
1.36M
            return value / (double)KILOBYTE;
226
1.36M
        } else {
227
182k
            *unit = "B";
228
182k
            return value;
229
182k
        }
230
23.9M
    }
_ZN5doris13PrettyPrinter13get_byte_unitIlEEdT_PNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
213
23.7M
    static double get_byte_unit(T value, std::string* unit) {
214
23.7M
        if (value == 0) {
215
6.89M
            *unit = "";
216
6.89M
            return value;
217
16.8M
        } else if (value >= GIGABYTE) {
218
8.11M
            *unit = "GB";
219
8.11M
            return value / (double)GIGABYTE;
220
8.76M
        } else if (value >= MEGABYTE) {
221
7.27M
            *unit = "MB";
222
7.27M
            return value / (double)MEGABYTE;
223
7.27M
        } else if (value >= KILOBYTE) {
224
1.30M
            *unit = "KB";
225
1.30M
            return value / (double)KILOBYTE;
226
1.30M
        } else {
227
181k
            *unit = "B";
228
181k
            return value;
229
181k
        }
230
23.7M
    }
_ZN5doris13PrettyPrinter13get_byte_unitImEEdT_PNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
213
137k
    static double get_byte_unit(T value, std::string* unit) {
214
137k
        if (value == 0) {
215
81.2k
            *unit = "";
216
81.2k
            return value;
217
81.2k
        } else if (value >= GIGABYTE) {
218
0
            *unit = "GB";
219
0
            return value / (double)GIGABYTE;
220
55.9k
        } else if (value >= MEGABYTE) {
221
355
            *unit = "MB";
222
355
            return value / (double)MEGABYTE;
223
55.6k
        } else if (value >= KILOBYTE) {
224
54.3k
            *unit = "KB";
225
54.3k
            return value / (double)KILOBYTE;
226
54.3k
        } else {
227
1.29k
            *unit = "B";
228
1.29k
            return value;
229
1.29k
        }
230
137k
    }
231
232
    template <typename T>
233
4.15k
    static double get_unit(T value, std::string* unit) {
234
4.15k
        if (value >= BILLION) {
235
0
            *unit = "B";
236
0
            return value / (1. * BILLION);
237
4.15k
        } else if (value >= MILLION) {
238
5
            *unit = "M";
239
5
            return value / (1. * MILLION);
240
4.15k
        } else if (value >= THOUSAND) {
241
57
            *unit = "K";
242
57
            return value / (1. * THOUSAND);
243
4.09k
        } else {
244
4.09k
            *unit = "";
245
4.09k
            return value;
246
4.09k
        }
247
4.15k
    }
_ZN5doris13PrettyPrinter8get_unitIlEEdT_PNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
233
4.15k
    static double get_unit(T value, std::string* unit) {
234
4.15k
        if (value >= BILLION) {
235
0
            *unit = "B";
236
0
            return value / (1. * BILLION);
237
4.15k
        } else if (value >= MILLION) {
238
5
            *unit = "M";
239
5
            return value / (1. * MILLION);
240
4.15k
        } else if (value >= THOUSAND) {
241
57
            *unit = "K";
242
57
            return value / (1. * THOUSAND);
243
4.09k
        } else {
244
4.09k
            *unit = "";
245
4.09k
            return value;
246
4.09k
        }
247
4.15k
    }
Unexecuted instantiation: _ZN5doris13PrettyPrinter8get_unitImEEdT_PNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
248
249
    /// Utility to perform integer modulo if T is integral, otherwise to use fmod().
250
    template <typename T>
251
    static typename boost::enable_if_c<boost::is_integral<T>::value, int64_t>::type mod(
252
185
            const T& value, const int modulus) {
253
185
        return value % modulus;
254
185
    }
_ZN5doris13PrettyPrinter3modIlEEN5boost11enable_if_cIXsr5boost11is_integralIT_EE5valueElE4typeERKS4_i
Line
Count
Source
252
176
            const T& value, const int modulus) {
253
176
        return value % modulus;
254
176
    }
_ZN5doris13PrettyPrinter3modImEEN5boost11enable_if_cIXsr5boost11is_integralIT_EE5valueElE4typeERKS4_i
Line
Count
Source
252
9
            const T& value, const int modulus) {
253
9
        return value % modulus;
254
9
    }
255
256
    template <typename T>
257
    static typename boost::enable_if_c<!boost::is_integral<T>::value, double>::type mod(
258
            const T& value, int modulus) {
259
        return fmod(value, 1. * modulus);
260
    }
261
262
    /// Print the value (time in ms) to ss
263
    template <typename T>
264
185
    static void print_timems(T value, std::stringstream* ss) {
265
185
        DCHECK_GE(value, static_cast<T>(0));
266
185
        if (value == 0) {
267
0
            *ss << "0";
268
185
        } else {
269
185
            bool hour = false;
270
185
            bool minute = false;
271
185
            bool second = false;
272
185
            if (value >= HOUR) {
273
0
                *ss << static_cast<int64_t>(value / HOUR) << "h";
274
0
                value = mod(value, HOUR);
275
0
                hour = true;
276
0
            }
277
185
            if (value >= MINUTE) {
278
0
                *ss << static_cast<int64_t>(value / MINUTE) << "m";
279
0
                value = mod(value, MINUTE);
280
0
                minute = true;
281
0
            }
282
185
            if (!hour && value >= SECOND) {
283
185
                *ss << static_cast<int64_t>(value / SECOND) << "s";
284
185
                value = mod(value, SECOND);
285
185
                second = true;
286
185
            }
287
185
            if (!hour && !minute) {
288
185
                if (second) *ss << std::setw(3) << std::setfill('0');
289
185
                *ss << static_cast<int64_t>(value) << "ms";
290
185
            }
291
185
        }
292
185
    }
_ZN5doris13PrettyPrinter12print_timemsIlEEvT_PNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE
Line
Count
Source
264
176
    static void print_timems(T value, std::stringstream* ss) {
265
176
        DCHECK_GE(value, static_cast<T>(0));
266
176
        if (value == 0) {
267
0
            *ss << "0";
268
176
        } else {
269
176
            bool hour = false;
270
176
            bool minute = false;
271
176
            bool second = false;
272
176
            if (value >= HOUR) {
273
0
                *ss << static_cast<int64_t>(value / HOUR) << "h";
274
0
                value = mod(value, HOUR);
275
0
                hour = true;
276
0
            }
277
176
            if (value >= MINUTE) {
278
0
                *ss << static_cast<int64_t>(value / MINUTE) << "m";
279
0
                value = mod(value, MINUTE);
280
0
                minute = true;
281
0
            }
282
176
            if (!hour && value >= SECOND) {
283
176
                *ss << static_cast<int64_t>(value / SECOND) << "s";
284
176
                value = mod(value, SECOND);
285
176
                second = true;
286
176
            }
287
176
            if (!hour && !minute) {
288
176
                if (second) *ss << std::setw(3) << std::setfill('0');
289
176
                *ss << static_cast<int64_t>(value) << "ms";
290
176
            }
291
176
        }
292
176
    }
_ZN5doris13PrettyPrinter12print_timemsImEEvT_PNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE
Line
Count
Source
264
9
    static void print_timems(T value, std::stringstream* ss) {
265
9
        DCHECK_GE(value, static_cast<T>(0));
266
9
        if (value == 0) {
267
0
            *ss << "0";
268
9
        } else {
269
9
            bool hour = false;
270
9
            bool minute = false;
271
9
            bool second = false;
272
9
            if (value >= HOUR) {
273
0
                *ss << static_cast<int64_t>(value / HOUR) << "h";
274
0
                value = mod(value, HOUR);
275
0
                hour = true;
276
0
            }
277
9
            if (value >= MINUTE) {
278
0
                *ss << static_cast<int64_t>(value / MINUTE) << "m";
279
0
                value = mod(value, MINUTE);
280
0
                minute = true;
281
0
            }
282
9
            if (!hour && value >= SECOND) {
283
9
                *ss << static_cast<int64_t>(value / SECOND) << "s";
284
9
                value = mod(value, SECOND);
285
9
                second = true;
286
9
            }
287
9
            if (!hour && !minute) {
288
9
                if (second) *ss << std::setw(3) << std::setfill('0');
289
9
                *ss << static_cast<int64_t>(value) << "ms";
290
9
            }
291
9
        }
292
9
    }
293
};
294
295
} // namespace doris