15 #ifndef IMPALA_UTIL_PRETTY_PRINTER_H
16 #define IMPALA_UTIL_PRETTY_PRINTER_H
18 #include <boost/algorithm/string.hpp>
23 #include "gen-cpp/RuntimeProfile_types.h"
33 static std::string
Print(
bool value, TUnit::type ignored,
bool verbose =
false) {
35 ss << std::boolalpha << value;
47 ss.flags(std::ios::fixed);
56 double output =
GetUnit(value, &unit);
60 ss << std::setprecision(PRECISION) << output <<
unit;
62 if (
verbose) ss <<
" (" << value <<
")";
66 case TUnit::UNIT_PER_SECOND: {
68 double output =
GetUnit(value, &unit);
72 ss << std::setprecision(PRECISION) << output <<
" " << unit <<
"/sec";
77 case TUnit::CPU_TICKS: {
79 ss << std::setprecision(PRECISION) << (value / 1000.) <<
"K clock cycles";
87 case TUnit::TIME_NS: {
95 ss << value / 1000 <<
"." << Mod(value, 1000) <<
"ms";
96 }
else if (value > 1000) {
98 ss << value / 1000 <<
"." << Mod(value, 1000) <<
"us";
105 case TUnit::TIME_MS: {
110 case TUnit::TIME_S: {
121 ss << std::setprecision(PRECISION) << output <<
" " <<
unit;
122 if (
verbose) ss <<
" (" << value <<
")";
127 case TUnit::BYTES_PER_SECOND: {
130 ss << std::setprecision(PRECISION) << output <<
" " << unit <<
"/sec";
135 case TUnit::DOUBLE_VALUE: {
136 double output = *
reinterpret_cast<double*
>(&value);
137 ss << std::setprecision(PRECISION) << output <<
" ";
142 DCHECK(
false) <<
"Unsupported TUnit: " << value;
154 Print(const T& value, TUnit::type
unit) {
155 std::stringstream ss;
156 ss << std::boolalpha << value;
161 template <
typename I>
162 static void PrintStringList(
const I& iterable, TUnit::type unit,
163 std::stringstream* out) {
164 std::vector<std::string> strings;
165 for (
typename I::const_iterator it = iterable.begin(); it != iterable.end(); ++it) {
166 std::stringstream ss;
168 strings.push_back(ss.str());
171 (*out) <<
"[" << boost::algorithm::join(strings,
", ") <<
"]";
175 static std::string PrintBytes(int64_t value) {
180 static const int PRECISION = 2;
193 template <
typename T>
213 template <
typename T>
214 static double GetUnit(T value, std::string* unit) {
231 template <
typename T>
236 template <
typename T>
238 return fmod(value, 1. * modulus);
242 template <
typename T>
244 DCHECK_GE(value, static_cast<T>(0));
252 *ss << static_cast<int64_t>(value /
HOUR) <<
"h";
253 value = Mod(value,
HOUR);
257 *ss << static_cast<int64_t>(value /
MINUTE) <<
"m";
258 value = Mod(value,
MINUTE);
261 if (!hour && value >=
SECOND) {
262 *ss << static_cast<int64_t>(value /
SECOND) <<
"s";
263 value = Mod(value,
SECOND);
266 if (!hour && !minute) {
267 if (second) *ss << std::setw(3) << std::setfill(
'0');
268 *ss << static_cast<int64_t>(value) <<
"ms";
static ENABLE_IF_ARITHMETIC(T, std::string) Print(T value
static void PrintTimeMs(T value, std::stringstream *ss)
Print the value (time in ms) to ss.
static const int64_t KILOBYTE
#define ENABLE_IF_NOT_ARITHMETIC(type_param, return_type)
static const int64_t MINUTE
static TUnit::type bool verbose
static const int64_t GIGABYTE
static double GetByteUnit(T value, std::string *unit)
static const int64_t BILLION
static std::string Print(bool value, TUnit::type ignored, bool verbose=false)
static int64_t cycles_per_ms()
Returns the number of cpu cycles per millisecond.
static const int64_t SECOND
static const int64_t MILLION
static const int64_t MEGABYTE
static const int64_t HOUR
static const int modulus return value modulus
static ENABLE_IF_INTEGRAL(T, int64_t) Mod(const T &value
Utility to perform integer modulo if T is integral, otherwise to use fmod().
static ENABLE_IF_FLOAT(T, double) Mod(const T &value
static double GetUnit(T value, std::string *unit)
static const int64_t THOUSAND