stats: allow printing vectors on a single line

This patch adds a new flag to specify if the data values for a given vector
should be printed in one line in the stats.txt file. The default behavior
will be to print the data in multiple lines. It makes changes to print
functions to enforce this behavior.
This commit is contained in:
Nilay Vaish 2013-06-09 07:29:57 -05:00
parent b5d315518c
commit f2b5b4c8cc
2 changed files with 42 additions and 15 deletions

View file

@ -57,6 +57,8 @@ const FlagsType dist = 0x0080;
const FlagsType nozero = 0x0100; const FlagsType nozero = 0x0100;
/** Don't print if this is NAN */ /** Don't print if this is NAN */
const FlagsType nonan = 0x0200; const FlagsType nonan = 0x0200;
/** Print all values on a single line. Useful only for histograms. */
const FlagsType oneline = 0x0400;
/** Mask of flags that can't be set directly */ /** Mask of flags that can't be set directly */
const FlagsType __reserved = init | display; const FlagsType __reserved = init | display;

View file

@ -194,7 +194,7 @@ struct ScalarPrint
Result cdf; Result cdf;
void update(Result val, Result total); void update(Result val, Result total);
void operator()(ostream &stream) const; void operator()(ostream &stream, bool oneLine = false) const;
}; };
void void
@ -208,7 +208,7 @@ ScalarPrint::update(Result val, Result total)
} }
void void
ScalarPrint::operator()(ostream &stream) const ScalarPrint::operator()(ostream &stream, bool oneLine) const
{ {
if ((flags.isSet(nozero) && value == 0.0) || if ((flags.isSet(nozero) && value == 0.0) ||
(flags.isSet(nonan) && std::isnan(value))) (flags.isSet(nonan) && std::isnan(value)))
@ -222,14 +222,19 @@ ScalarPrint::operator()(ostream &stream) const
if (!std::isnan(cdf)) if (!std::isnan(cdf))
ccprintf(cdfstr, "%.2f%%", cdf * 100.0); ccprintf(cdfstr, "%.2f%%", cdf * 100.0);
ccprintf(stream, "%-40s %12s %10s %10s", name, if (oneLine) {
ValueToString(value, precision), pdfstr.str(), cdfstr.str()); ccprintf(stream, " |%12s %10s %10s",
ValueToString(value, precision), pdfstr.str(), cdfstr.str());
} else {
ccprintf(stream, "%-40s %12s %10s %10s", name,
ValueToString(value, precision), pdfstr.str(), cdfstr.str());
if (descriptions) { if (descriptions) {
if (!desc.empty()) if (!desc.empty())
ccprintf(stream, " # %s", desc); ccprintf(stream, " # %s", desc);
}
stream << endl;
} }
stream << endl;
} }
struct VectorPrint struct VectorPrint
@ -279,15 +284,31 @@ VectorPrint::operator()(std::ostream &stream) const
return; return;
} }
for (off_type i = 0; i < _size; ++i) { if ((!flags.isSet(nozero)) || (total != 0)) {
if (havesub && (i >= subnames.size() || subnames[i].empty())) if (flags.isSet(oneline)) {
continue; ccprintf(stream, "%-40s", name);
print.flags = print.flags & (~nozero);
}
print.name = base + (havesub ? subnames[i] : to_string(i)); for (off_type i = 0; i < _size; ++i) {
print.desc = subdescs.empty() ? desc : subdescs[i]; if (havesub && (i >= subnames.size() || subnames[i].empty()))
continue;
print.update(vec[i], _total); print.name = base + (havesub ? subnames[i] : to_string(i));
print(stream); print.desc = subdescs.empty() ? desc : subdescs[i];
print.update(vec[i], _total);
print(stream, flags.isSet(oneline));
}
if (flags.isSet(oneline)) {
if (descriptions) {
if (!desc.empty())
ccprintf(stream, " # %s", desc);
}
stream << endl;
}
} }
if (flags.isSet(::Stats::total)) { if (flags.isSet(::Stats::total)) {
@ -298,6 +319,10 @@ VectorPrint::operator()(std::ostream &stream) const
print.value = total; print.value = total;
print(stream); print(stream);
} }
if (flags.isSet(oneline) && ((!flags.isSet(nozero)) || (total != 0))) {
stream << endl;
}
} }
struct DistPrint struct DistPrint