From 87c3a1ac5b08ba4b43200b0f4817f5435f89288a Mon Sep 17 00:00:00 2001 From: Georges Berenger Date: Fri, 1 Mar 2024 20:26:34 -0800 Subject: [PATCH] Limit the number of vector values printed with printCompact 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 --- vrs/DataLayout.cpp | 17 +++++++++++++++-- vrs/DataPieces.h | 1 - 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/vrs/DataLayout.cpp b/vrs/DataLayout.cpp index e2313678..6586dd62 100644 --- a/vrs/DataLayout.cpp +++ b/vrs/DataLayout.cpp @@ -1141,6 +1141,9 @@ size_t getCountPerLine(const T& value) { ss << FORMAT(value, ss); return max(1, 96 / (ss.str().size() + 1)); } + +const size_t kPrintCompactMaxVectorValues = 400; // arbitrary + } // namespace template @@ -1369,7 +1372,7 @@ void DataPieceVector::printCompact(ostream& out, const string& indent) const vector values; get(values); const size_t kCountPerLine = values.empty() ? 1 : getCountPerLine(values.front()); - for (size_t k = 0; k < values.size(); k++) { + for (size_t k = 0; k < min(kPrintCompactMaxVectorValues, values.size()); k++) { if (k % kCountPerLine == 0 && values.size() > kCountPerLine) { out << "\n" << indent << " "; } else { @@ -1378,6 +1381,11 @@ void DataPieceVector::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 << ""; } @@ -1390,7 +1398,7 @@ void DataPieceVector::printCompact(ostream& out, const string& indent) c out << indent << getLabel() << ": "; vector values; get(values); - for (size_t k = 0; k < values.size(); k++) { + for (size_t k = 0; k < min(kPrintCompactMaxVectorValues, values.size()); k++) { if (k % kCountPerLine == 0 && values.size() > kCountPerLine) { out << "\n" << indent << " "; } else { @@ -1398,6 +1406,11 @@ void DataPieceVector::printCompact(ostream& out, const string& indent) c } out << '"' << compactString(values[k]) << '"'; } + if (values.size() > kPrintCompactMaxVectorValues) { + out << "\n" + << indent << " ...and " << values.size() - kPrintCompactMaxVectorValues + << " more values."; + } if (getOffset() == DataLayout::kNotFound) { out << ""; } diff --git a/vrs/DataPieces.h b/vrs/DataPieces.h index e382a310..3b09b936 100644 --- a/vrs/DataPieces.h +++ b/vrs/DataPieces.h @@ -21,7 +21,6 @@ #include -#include #include #include