MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / setColorForTimeBasedMetricsProgress

Function setColorForTimeBasedMetricsProgress

src/Client/ProgressTable.cpp:134–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134std::string_view setColorForTimeBasedMetricsProgress(ProfileEvents::ValueType value_type, double progress)
135{
136 /// Time units in a second.
137 auto units = [](ProfileEvents::ValueType t) -> double
138 {
139 switch (t)
140 {
141 case ProfileEvents::ValueType::Milliseconds:
142 return 1e3;
143 case ProfileEvents::ValueType::Microseconds:
144 return 1e6;
145 case ProfileEvents::ValueType::Nanoseconds:
146 return 1e9;
147 default:
148 throw Exception(ErrorCodes::LOGICAL_ERROR, "Wrong value type, expecting time units");
149 }
150 }(value_type);
151
152 constexpr std::array<std::string_view, 5> colors = {
153 "\033[38;5;236m", /// Dark Grey
154 "\033[38;5;250m", /// Light Grey
155 "\033[38;5;34m", /// Green
156 "\033[38;5;226m", /// Yellow
157 "\033[1;33m" /// Bold
158 };
159
160 const std::array<double, 4> thresholds = {0.001 * units, 0.01 * units, 0.1 * units, 1.0 * units};
161
162 auto dist = std::upper_bound(thresholds.begin(), thresholds.end(), progress) - thresholds.begin();
163 return colors[dist];
164}
165
166std::string_view setColorForDocumentation()
167{

Callers 1

writeTableMethod · 0.85

Calls 3

ExceptionClass · 0.70
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected