Coverage Report

Created: 2026-03-19 10:12

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
106k
#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
19.6M
            T value, TUnit::type unit, bool verbose = false) {
55
19.6M
        std::stringstream ss;
56
19.6M
        ss.flags(std::ios::fixed);
57
19.6M
        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
3.29k
        case TUnit::UNIT: {
68
3.29k
            std::string nest_unit;
69
3.29k
            double output = get_unit(value, &nest_unit);
70
3.29k
            if (nest_unit.empty()) {
71
3.28k
                ss << value;
72
3.28k
            } else {
73
8
                ss << std::setprecision(PRECISION) << output << nest_unit;
74
8
            }
75
3.29k
            if (verbose) {
76
0
                ss << " (" << value << ")";
77
0
            }
78
3.29k
            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
106k
        case TUnit::TIME_NS: {
103
106k
            ss << std::setprecision(TIME_NS_PRECISION);
104
106k
            if (value >= BILLION) {
105
                /// If the time is over a second, print it up to ms.
106
28
                value /= MILLION;
107
28
                print_timems(value, &ss);
108
106k
            } else if (value >= MILLION) {
109
                /// if the time is over a ms, print it up to microsecond in the unit of ms.
110
55.0k
                ss << DOUBLE_TRUNCATE(static_cast<double>(value) / MILLION, TIME_NS_PRECISION)
111
55.0k
                   << "ms";
112
55.0k
            } else if (value > 1000) {
113
                /// if the time is over a microsecond, print it using unit microsecond
114
3.76k
                ss << DOUBLE_TRUNCATE(static_cast<double>(value) / 1000, TIME_NS_PRECISION) << "us";
115
47.6k
            } else {
116
47.6k
                ss << DOUBLE_TRUNCATE(value, TIME_NS_PRECISION) << "ns";
117
47.6k
            }
118
106k
            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
19.5M
        case TUnit::BYTES: {
132
19.5M
            std::string nest_unit;
133
19.5M
            double output = get_byte_unit(value, &nest_unit);
134
19.5M
            if (output == 0) {
135
5.55M
                ss << "0";
136
13.9M
            } else {
137
13.9M
                ss << std::setprecision(PRECISION) << output << " " << nest_unit;
138
13.9M
                if (verbose) {
139
0
                    ss << " (" << value << ")";
140
0
                }
141
13.9M
            }
142
19.5M
            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
19.6M
        }
163
19.6M
        return ss.str();
164
19.6M
    }
_ZN5doris13PrettyPrinter5printIlEENSt9enable_ifIXsr3std13is_arithmeticIT_EE5valueENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE4typeES3_NS_5TUnit4typeEb
Line
Count
Source
54
19.5M
            T value, TUnit::type unit, bool verbose = false) {
55
19.5M
        std::stringstream ss;
56
19.5M
        ss.flags(std::ios::fixed);
57
19.5M
        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
3.29k
        case TUnit::UNIT: {
68
3.29k
            std::string nest_unit;
69
3.29k
            double output = get_unit(value, &nest_unit);
70
3.29k
            if (nest_unit.empty()) {
71
3.28k
                ss << value;
72
3.28k
            } else {
73
8
                ss << std::setprecision(PRECISION) << output << nest_unit;
74
8
            }
75
3.29k
            if (verbose) {
76
0
                ss << " (" << value << ")";
77
0
            }
78
3.29k
            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
82.2k
        case TUnit::TIME_NS: {
103
82.2k
            ss << std::setprecision(TIME_NS_PRECISION);
104
82.2k
            if (value >= BILLION) {
105
                /// If the time is over a second, print it up to ms.
106
26
                value /= MILLION;
107
26
                print_timems(value, &ss);
108
82.2k
            } else if (value >= MILLION) {
109
                /// if the time is over a ms, print it up to microsecond in the unit of ms.
110
30.8k
                ss << DOUBLE_TRUNCATE(static_cast<double>(value) / MILLION, TIME_NS_PRECISION)
111
30.8k
                   << "ms";
112
51.4k
            } else if (value > 1000) {
113
                /// if the time is over a microsecond, print it using unit microsecond
114
3.75k
                ss << DOUBLE_TRUNCATE(static_cast<double>(value) / 1000, TIME_NS_PRECISION) << "us";
115
47.6k
            } else {
116
47.6k
                ss << DOUBLE_TRUNCATE(value, TIME_NS_PRECISION) << "ns";
117
47.6k
            }
118
82.2k
            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
19.5M
        case TUnit::BYTES: {
132
19.5M
            std::string nest_unit;
133
19.5M
            double output = get_byte_unit(value, &nest_unit);
134
19.5M
            if (output == 0) {
135
5.53M
                ss << "0";
136
13.9M
            } else {
137
13.9M
                ss << std::setprecision(PRECISION) << output << " " << nest_unit;
138
13.9M
                if (verbose) {
139
0
                    ss << " (" << value << ")";
140
0
                }
141
13.9M
            }
142
19.5M
            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
19.5M
        }
163
19.5M
        return ss.str();
164
19.5M
    }
_ZN5doris13PrettyPrinter5printImEENSt9enable_ifIXsr3std13is_arithmeticIT_EE5valueENSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE4typeES3_NS_5TUnit4typeEb
Line
Count
Source
54
49.9k
            T value, TUnit::type unit, bool verbose = false) {
55
49.9k
        std::stringstream ss;
56
49.9k
        ss.flags(std::ios::fixed);
57
49.9k
        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
24.3k
        case TUnit::TIME_NS: {
103
24.3k
            ss << std::setprecision(TIME_NS_PRECISION);
104
24.3k
            if (value >= BILLION) {
105
                /// If the time is over a second, print it up to ms.
106
2
                value /= MILLION;
107
2
                print_timems(value, &ss);
108
24.3k
            } else if (value >= MILLION) {
109
                /// if the time is over a ms, print it up to microsecond in the unit of ms.
110
24.2k
                ss << DOUBLE_TRUNCATE(static_cast<double>(value) / MILLION, TIME_NS_PRECISION)
111
24.2k
                   << "ms";
112
24.2k
            } else if (value > 1000) {
113
                /// if the time is over a microsecond, print it using unit microsecond
114
12
                ss << DOUBLE_TRUNCATE(static_cast<double>(value) / 1000, TIME_NS_PRECISION) << "us";
115
18.4E
            } else {
116
18.4E
                ss << DOUBLE_TRUNCATE(value, TIME_NS_PRECISION) << "ns";
117
18.4E
            }
118
24.3k
            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
25.6k
        case TUnit::BYTES: {
132
25.6k
            std::string nest_unit;
133
25.6k
            double output = get_byte_unit(value, &nest_unit);
134
25.6k
            if (output == 0) {
135
16.2k
                ss << "0";
136
16.2k
            } else {
137
9.38k
                ss << std::setprecision(PRECISION) << output << " " << nest_unit;
138
9.38k
                if (verbose) {
139
0
                    ss << " (" << value << ")";
140
0
                }
141
9.38k
            }
142
25.6k
            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
49.9k
        }
163
49.9k
        return ss.str();
164
49.9k
    }
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
80
            const T& value, TUnit::type unit) {
173
80
        std::stringstream ss;
174
80
        ss << std::boolalpha << value;
175
80
        return ss.str();
176
80
    }
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
18.9M
    static std::string print_bytes(int64_t value) {
193
18.9M
        return value >= 0 ? PrettyPrinter::print(value, TUnit::BYTES)
194
18.9M
                          : "-" + PrettyPrinter::print(std::abs(value), TUnit::BYTES);
195
18.9M
    }
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
19.5M
    static double get_byte_unit(T value, std::string* unit) {
214
19.5M
        if (value == 0) {
215
5.55M
            *unit = "";
216
5.55M
            return value;
217
13.9M
        } else if (value >= GIGABYTE) {
218
6.58M
            *unit = "GB";
219
6.58M
            return value / (double)GIGABYTE;
220
7.39M
        } else if (value >= MEGABYTE) {
221
6.46M
            *unit = "MB";
222
6.46M
            return value / (double)MEGABYTE;
223
6.46M
        } else if (value >= KILOBYTE) {
224
797k
            *unit = "KB";
225
797k
            return value / (double)KILOBYTE;
226
797k
        } else {
227
139k
            *unit = "B";
228
139k
            return value;
229
139k
        }
230
19.5M
    }
_ZN5doris13PrettyPrinter13get_byte_unitIlEEdT_PNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
213
19.5M
    static double get_byte_unit(T value, std::string* unit) {
214
19.5M
        if (value == 0) {
215
5.53M
            *unit = "";
216
5.53M
            return value;
217
13.9M
        } else if (value >= GIGABYTE) {
218
6.58M
            *unit = "GB";
219
6.58M
            return value / (double)GIGABYTE;
220
7.38M
        } else if (value >= MEGABYTE) {
221
6.45M
            *unit = "MB";
222
6.45M
            return value / (double)MEGABYTE;
223
6.45M
        } else if (value >= KILOBYTE) {
224
789k
            *unit = "KB";
225
789k
            return value / (double)KILOBYTE;
226
789k
        } else {
227
137k
            *unit = "B";
228
137k
            return value;
229
137k
        }
230
19.5M
    }
_ZN5doris13PrettyPrinter13get_byte_unitImEEdT_PNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
213
25.6k
    static double get_byte_unit(T value, std::string* unit) {
214
25.6k
        if (value == 0) {
215
16.2k
            *unit = "";
216
16.2k
            return value;
217
16.2k
        } else if (value >= GIGABYTE) {
218
0
            *unit = "GB";
219
0
            return value / (double)GIGABYTE;
220
9.38k
        } else if (value >= MEGABYTE) {
221
423
            *unit = "MB";
222
423
            return value / (double)MEGABYTE;
223
8.96k
        } else if (value >= KILOBYTE) {
224
7.54k
            *unit = "KB";
225
7.54k
            return value / (double)KILOBYTE;
226
7.54k
        } else {
227
1.41k
            *unit = "B";
228
1.41k
            return value;
229
1.41k
        }
230
25.6k
    }
231
232
    template <typename T>
233
3.29k
    static double get_unit(T value, std::string* unit) {
234
3.29k
        if (value >= BILLION) {
235
0
            *unit = "B";
236
0
            return value / (1. * BILLION);
237
3.29k
        } else if (value >= MILLION) {
238
5
            *unit = "M";
239
5
            return value / (1. * MILLION);
240
3.29k
        } else if (value >= THOUSAND) {
241
2
            *unit = "K";
242
2
            return value / (1. * THOUSAND);
243
3.28k
        } else {
244
3.28k
            *unit = "";
245
3.28k
            return value;
246
3.28k
        }
247
3.29k
    }
_ZN5doris13PrettyPrinter8get_unitIlEEdT_PNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
Line
Count
Source
233
3.29k
    static double get_unit(T value, std::string* unit) {
234
3.29k
        if (value >= BILLION) {
235
0
            *unit = "B";
236
0
            return value / (1. * BILLION);
237
3.29k
        } else if (value >= MILLION) {
238
5
            *unit = "M";
239
5
            return value / (1. * MILLION);
240
3.29k
        } else if (value >= THOUSAND) {
241
2
            *unit = "K";
242
2
            return value / (1. * THOUSAND);
243
3.28k
        } else {
244
3.28k
            *unit = "";
245
3.28k
            return value;
246
3.28k
        }
247
3.29k
    }
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
28
            const T& value, const int modulus) {
253
28
        return value % modulus;
254
28
    }
_ZN5doris13PrettyPrinter3modIlEEN5boost11enable_if_cIXsr5boost11is_integralIT_EE5valueElE4typeERKS4_i
Line
Count
Source
252
26
            const T& value, const int modulus) {
253
26
        return value % modulus;
254
26
    }
_ZN5doris13PrettyPrinter3modImEEN5boost11enable_if_cIXsr5boost11is_integralIT_EE5valueElE4typeERKS4_i
Line
Count
Source
252
2
            const T& value, const int modulus) {
253
2
        return value % modulus;
254
2
    }
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
28
    static void print_timems(T value, std::stringstream* ss) {
265
28
        DCHECK_GE(value, static_cast<T>(0));
266
28
        if (value == 0) {
267
0
            *ss << "0";
268
28
        } else {
269
28
            bool hour = false;
270
28
            bool minute = false;
271
28
            bool second = false;
272
28
            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
28
            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
28
            if (!hour && value >= SECOND) {
283
28
                *ss << static_cast<int64_t>(value / SECOND) << "s";
284
28
                value = mod(value, SECOND);
285
28
                second = true;
286
28
            }
287
28
            if (!hour && !minute) {
288
28
                if (second) *ss << std::setw(3) << std::setfill('0');
289
28
                *ss << static_cast<int64_t>(value) << "ms";
290
28
            }
291
28
        }
292
28
    }
_ZN5doris13PrettyPrinter12print_timemsIlEEvT_PNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE
Line
Count
Source
264
26
    static void print_timems(T value, std::stringstream* ss) {
265
26
        DCHECK_GE(value, static_cast<T>(0));
266
26
        if (value == 0) {
267
0
            *ss << "0";
268
26
        } else {
269
26
            bool hour = false;
270
26
            bool minute = false;
271
26
            bool second = false;
272
26
            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
26
            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
26
            if (!hour && value >= SECOND) {
283
26
                *ss << static_cast<int64_t>(value / SECOND) << "s";
284
26
                value = mod(value, SECOND);
285
26
                second = true;
286
26
            }
287
26
            if (!hour && !minute) {
288
26
                if (second) *ss << std::setw(3) << std::setfill('0');
289
26
                *ss << static_cast<int64_t>(value) << "ms";
290
26
            }
291
26
        }
292
26
    }
_ZN5doris13PrettyPrinter12print_timemsImEEvT_PNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE
Line
Count
Source
264
2
    static void print_timems(T value, std::stringstream* ss) {
265
2
        DCHECK_GE(value, static_cast<T>(0));
266
2
        if (value == 0) {
267
0
            *ss << "0";
268
2
        } else {
269
2
            bool hour = false;
270
2
            bool minute = false;
271
2
            bool second = false;
272
2
            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
2
            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
2
            if (!hour && value >= SECOND) {
283
2
                *ss << static_cast<int64_t>(value / SECOND) << "s";
284
2
                value = mod(value, SECOND);
285
2
                second = true;
286
2
            }
287
2
            if (!hour && !minute) {
288
2
                if (second) *ss << std::setw(3) << std::setfill('0');
289
2
                *ss << static_cast<int64_t>(value) << "ms";
290
2
            }
291
2
        }
292
2
    }
293
};
294
295
} // namespace doris