[llvm-cov] Make 'adjustColumnWidths' do less work

This drops some redundant calls to get{UniqueSourceFiles,
CoveredFunctions}. We can figure out the right column widths without
re-doing this expensive work.

This isn't NFC, but I don't want to check in another binary *.covmapping
file with long filenames in it. I tested this locally on a project with
some long filenames (FileCheck).

llvm-svn: 281873
This commit is contained in:
Vedant Kumar 2016-09-19 00:38:16 +00:00
parent c6a118fd20
commit e723e6ad9c

View File

@ -89,14 +89,13 @@ size_t FileReportColumns[] = {25, 12, 18, 10, 12, 18, 10, 12, 18, 10};
size_t FunctionReportColumns[] = {25, 10, 8, 8, 10, 8, 8}; size_t FunctionReportColumns[] = {25, 10, 8, 8, 10, 8, 8};
/// \brief Adjust column widths to fit long file paths and function names. /// \brief Adjust column widths to fit long file paths and function names.
void adjustColumnWidths(const coverage::CoverageMapping &CM) { void adjustColumnWidths(ArrayRef<StringRef> Files,
for (StringRef Filename : CM.getUniqueSourceFiles()) { ArrayRef<StringRef> Functions) {
for (StringRef Filename : Files)
FileReportColumns[0] = std::max(FileReportColumns[0], Filename.size()); FileReportColumns[0] = std::max(FileReportColumns[0], Filename.size());
for (const auto &F : CM.getCoveredFunctions(Filename)) { for (StringRef Funcname : Functions)
FunctionReportColumns[0] = FunctionReportColumns[0] =
std::max(FunctionReportColumns[0], F.Name.size()); std::max(FunctionReportColumns[0], Funcname.size());
}
}
} }
/// \brief Prints a horizontal divider long enough to cover the given column /// \brief Prints a horizontal divider long enough to cover the given column
@ -205,13 +204,20 @@ void CoverageReport::render(const FunctionCoverageSummary &Function,
void CoverageReport::renderFunctionReports(ArrayRef<StringRef> Files, void CoverageReport::renderFunctionReports(ArrayRef<StringRef> Files,
raw_ostream &OS) { raw_ostream &OS) {
adjustColumnWidths(Coverage);
bool isFirst = true; bool isFirst = true;
for (StringRef Filename : Files) { for (StringRef Filename : Files) {
auto Functions = Coverage.getCoveredFunctions(Filename);
if (isFirst) if (isFirst)
isFirst = false; isFirst = false;
else else
OS << "\n"; OS << "\n";
std::vector<StringRef> Funcnames;
for (const auto &F : Functions)
Funcnames.emplace_back(F.Name);
adjustColumnWidths({}, Funcnames);
OS << "File '" << Filename << "':\n"; OS << "File '" << Filename << "':\n";
OS << column("Name", FunctionReportColumns[0]) OS << column("Name", FunctionReportColumns[0])
<< column("Regions", FunctionReportColumns[1], Column::RightAlignment) << column("Regions", FunctionReportColumns[1], Column::RightAlignment)
@ -224,7 +230,7 @@ void CoverageReport::renderFunctionReports(ArrayRef<StringRef> Files,
renderDivider(FunctionReportColumns, OS); renderDivider(FunctionReportColumns, OS);
OS << "\n"; OS << "\n";
FunctionCoverageSummary Totals("TOTAL"); FunctionCoverageSummary Totals("TOTAL");
for (const auto &F : Coverage.getCoveredFunctions(Filename)) { for (const auto &F : Functions) {
FunctionCoverageSummary Function = FunctionCoverageSummary::get(F); FunctionCoverageSummary Function = FunctionCoverageSummary::get(F);
++Totals.ExecutionCount; ++Totals.ExecutionCount;
Totals.RegionCoverage += Function.RegionCoverage; Totals.RegionCoverage += Function.RegionCoverage;
@ -267,7 +273,14 @@ void CoverageReport::renderFileReports(raw_ostream &OS) const {
void CoverageReport::renderFileReports(raw_ostream &OS, void CoverageReport::renderFileReports(raw_ostream &OS,
ArrayRef<StringRef> Files) const { ArrayRef<StringRef> Files) const {
adjustColumnWidths(Coverage); FileCoverageSummary Totals("TOTAL");
auto FileReports = prepareFileReports(Totals, Files);
std::vector<StringRef> Filenames;
for (const FileCoverageSummary &FCS : FileReports)
Filenames.emplace_back(FCS.Name);
adjustColumnWidths(Filenames, {});
OS << column("Filename", FileReportColumns[0]) OS << column("Filename", FileReportColumns[0])
<< column("Regions", FileReportColumns[1], Column::RightAlignment) << column("Regions", FileReportColumns[1], Column::RightAlignment)
<< column("Missed Regions", FileReportColumns[2], Column::RightAlignment) << column("Missed Regions", FileReportColumns[2], Column::RightAlignment)
@ -281,8 +294,6 @@ void CoverageReport::renderFileReports(raw_ostream &OS,
renderDivider(FileReportColumns, OS); renderDivider(FileReportColumns, OS);
OS << "\n"; OS << "\n";
FileCoverageSummary Totals("TOTAL");
auto FileReports = prepareFileReports(Totals, Files);
for (const FileCoverageSummary &FCS : FileReports) for (const FileCoverageSummary &FCS : FileReports)
render(FCS, OS); render(FCS, OS);