Skip to content

Commit

Permalink
Limit the number of vector values printed with printCompact
Browse files Browse the repository at this point in the history
Summary:
When printing out records, in particular with vector-vrs, we can have huge vectors of values, with many million values. Printing them out in a terminal makes the whole feature basically useless.
This diff limits the number of vector values printed out to 400.

Differential Revision: D54401272

fbshipit-source-id: d8899528e3f46e75c81bf008b6cce64829e09950
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Mar 2, 2024
1 parent 2125398 commit 87c3a1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
17 changes: 15 additions & 2 deletions vrs/DataLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,9 @@ size_t getCountPerLine(const T& value) {
ss << FORMAT(value, ss);
return max<size_t>(1, 96 / (ss.str().size() + 1));
}

const size_t kPrintCompactMaxVectorValues = 400; // arbitrary

} // namespace

template <typename T>
Expand Down Expand Up @@ -1369,7 +1372,7 @@ void DataPieceVector<T>::printCompact(ostream& out, const string& indent) const
vector<T> values;
get(values);
const size_t kCountPerLine = values.empty() ? 1 : getCountPerLine<T>(values.front());
for (size_t k = 0; k < values.size(); k++) {
for (size_t k = 0; k < min<size_t>(kPrintCompactMaxVectorValues, values.size()); k++) {
if (k % kCountPerLine == 0 && values.size() > kCountPerLine) {
out << "\n" << indent << " ";
} else {
Expand All @@ -1378,6 +1381,11 @@ void DataPieceVector<T>::printCompact(ostream& out, const string& indent) const
using namespace special_chars;
out << FORMAT(values[k], out);
}
if (values.size() > kPrintCompactMaxVectorValues) {
out << "\n"
<< indent << " ...and " << values.size() - kPrintCompactMaxVectorValues
<< " more values.";
}
if (getOffset() == DataLayout::kNotFound) {
out << "<unavailable>";
}
Expand All @@ -1390,14 +1398,19 @@ void DataPieceVector<string>::printCompact(ostream& out, const string& indent) c
out << indent << getLabel() << ": ";
vector<string> values;
get(values);
for (size_t k = 0; k < values.size(); k++) {
for (size_t k = 0; k < min<size_t>(kPrintCompactMaxVectorValues, values.size()); k++) {
if (k % kCountPerLine == 0 && values.size() > kCountPerLine) {
out << "\n" << indent << " ";
} else {
out << ' ';
}
out << '"' << compactString(values[k]) << '"';
}
if (values.size() > kPrintCompactMaxVectorValues) {
out << "\n"
<< indent << " ...and " << values.size() - kPrintCompactMaxVectorValues
<< " more values.";
}
if (getOffset() == DataLayout::kNotFound) {
out << "<unavailable>";
}
Expand Down
1 change: 0 additions & 1 deletion vrs/DataPieces.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include <cstring>

#include <algorithm>
#include <map>
#include <ostream>

Expand Down

0 comments on commit 87c3a1a

Please sign in to comment.