added to misc: timespec_to_stream_with_unit() for printing times either is seconds or miliseconds

master
Tomasz Sowa 2 years ago
parent 0f78968579
commit df3f04a951

@ -848,9 +848,9 @@ void App::MakePage()
calculate_timespec_diff(cur.request->timespec_ezc_engine_start, cur.request->timespec_ezc_engine_stop, diff);
pt::TextStream str;
timespec_to_stream(diff, str); // IMPROVEME in the future Log can be used directly
timespec_to_stream_with_unit(diff, str); // IMPROVEME in the future Log can be used directly
log << log3 << "App: ezc engine took: " << str << "s" << logend;
log << log3 << "App: ezc engine took: " << str << logend;
}
@ -2146,8 +2146,8 @@ void App::LogUserGroups()
void App::LogRequestTime()
{
pt::TextStream str;
timespec_to_stream(cur.request->timespec_req_diff, str);
log << log2 << "App: request took: " << str << "s" << logend;
timespec_to_stream_with_unit(cur.request->timespec_req_diff, str);
log << log2 << "App: request took: " << str << logend;
}

@ -1509,6 +1509,34 @@ void timespec_to_stream(timespec & val, pt::Stream & stream)
}
void timespec_to_stream_with_unit(timespec & val, pt::Stream & stream)
{
char buf[50];
bool is_ms = false;
double val_double = timespec_to_double(val);
if( val_double < 0.1 )
{
is_ms = true;
val_double = val_double * 1000;
}
sprintf(buf, "%f", val_double);
SetNonZeroDigitsAfterComma(buf, 2);
stream << buf;
if( is_ms )
{
stream << "ms";
}
else
{
stream << "s";
}
}
} // namespace Winix

@ -1013,7 +1013,7 @@ double timespec_to_double(timespec & val);
void timespec_to_stream(timespec & val, pt::Stream & stream);
void timespec_to_stream_with_unit(timespec & val, pt::Stream & stream);

Loading…
Cancel
Save