X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FStatistics.cc;h=a96b33ba44f878dc304c82359b27eba9866c991a;hb=f214d8c456b57c851066b6dd437049938f8a91ee;hp=0b6ab8f51ebc9921cef0a986431b38769d7bc72b;hpb=f2f5d59e83863f3b513950173baee1b6da2aee3c;p=senf.git diff --git a/Utils/Statistics.cc b/Utils/Statistics.cc index 0b6ab8f..a96b33b 100644 --- a/Utils/Statistics.cc +++ b/Utils/Statistics.cc @@ -80,20 +80,52 @@ senf::StatisticsBase::output(unsigned n) return OutputProxy(this, &(i->second)); } +// +// generate an engineering style notation i +// +char *format_eng( float f) +{ + static char buf[16]; + if( f > 0){ + int n = 0; + while( f >= 1000.0f){ + f /= 1000.f; + n+=3; + } + + sprintf( buf, " %3.2fe%+03d", f, n); + } + else if( f < 0){ + int n = 0; + while( f <= -1000.0f){ + f *= 1000.f; + n+=3; + } + + sprintf( buf, "%3.2fe%+03d", f, n); + } + else{ + sprintf( buf, " 0.00"); + } + + return buf; +} + + prefix_ void senf::StatisticsBase::consoleList(unsigned level, std::ostream & os) const { - os << boost::format("%s%-5d%|15t| %12g %12g %12g\n") - % std::string(2*level,' ') % rank() % min() % avg() % max(); + os << boost::format("%s%-5d%|15t| %12s %12s %12s\n") + % std::string(2*level,' ') % rank() % format_eng(min()) % format_eng(avg()) % format_eng(max()); { OutputMap::const_iterator i (outputs_.begin()); OutputMap::const_iterator i_end (outputs_.end()); for (; i != i_end; ++i) - os << boost::format(" %3d %12g %12g %12g\n") + os << boost::format(" %3d %12s %12s %12s\n") % i->second.n - % (i->second.min/i->second.n) - % (i->second.avg/i->second.n) - % (i->second.max/i->second.n); + % format_eng(i->second.min/i->second.n) + % format_eng(i->second.avg/i->second.n) + % format_eng(i->second.max/i->second.n); } { Children::const_iterator i (children_.begin());