[PATCH] D12647: [llvm-cov] Add -full-filenames option

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 11:55:08 PDT 2015


Vedant Kumar <vsk at apple.com> writes:
> vsk created this revision.
> vsk added a reviewer: bogner.
> vsk added a subscriber: llvm-commits.
>
> Add an option to llvm-cov which forces it to print entire file paths
> when dumping file coverage reports, instead of truncated paths. The
> default behavior is unchanged.

The default behaviour is terrible. If we're going to try to make these
things narrow enough for a terminal it would be better to strip a common
prefix or split these by directory or something. I'd probably just
remove the strange truncating mode entirely for now.

> Before:
> $ llvm-cov report -instr-profile test.out.profdata test.out          
> Filename                    Regions    Miss   Cover Functions  Executed
> -----------------------------------------------------------------------
> ...op/coverage/test.quuux         4       1  75.00%         2   100.00%
> -----------------------------------------------------------------------
> TOTAL                             4       1  75.00%         2   100.00%
>
> After:
> $ llvm-cov report -full-filenames -instr-profile test.out.profdata test.out
> Filename Regions Miss Cover Functions Executed
> -----------------------------------------------------------------------------------
> /Users/vk/Desktop/coverage/test.quuux 4 1 75.00% 2 100.00%
> -----------------------------------------------------------------------------------
> TOTAL 4 1 75.00% 2 100.00%
>
> http://reviews.llvm.org/D12647
>
> Files:
>   tools/llvm-cov/CodeCoverage.cpp
>   tools/llvm-cov/CoverageReport.cpp
>   tools/llvm-cov/CoverageViewOptions.h
>
>
> Index: tools/llvm-cov/CoverageViewOptions.h
> ===================================================================
> --- tools/llvm-cov/CoverageViewOptions.h
> +++ tools/llvm-cov/CoverageViewOptions.h
> @@ -24,6 +24,7 @@
>    bool ShowLineStatsOrRegionMarkers;
>    bool ShowExpandedRegions;
>    bool ShowFunctionInstantiations;
> +  bool ShowFullFilenames;
>  
>    /// \brief Change the output's stream color if the colors are enabled.
>    ColoredRawOstream colored_ostream(raw_ostream &OS,
> Index: tools/llvm-cov/CoverageReport.cpp
> ===================================================================
> --- tools/llvm-cov/CoverageReport.cpp
> +++ tools/llvm-cov/CoverageReport.cpp
> @@ -20,7 +20,7 @@
>  namespace {
>  /// \brief Helper struct which prints trimmed and aligned columns.
>  struct Column {
> -  enum TrimKind { NoTrim, LeftTrim, RightTrim };
> +  enum TrimKind { NoTrim, WidthTrim, LeftTrim, RightTrim };
>  
>    enum AlignmentKind { LeftAlignment, RightAlignment };
>  
> @@ -30,7 +30,7 @@
>    AlignmentKind Alignment;
>  
>    Column(StringRef Str, unsigned Width)
> -      : Str(Str), Width(Width), Trim(NoTrim), Alignment(LeftAlignment) {}
> +      : Str(Str), Width(Width), Trim(WidthTrim), Alignment(LeftAlignment) {}
>  
>    Column &set(TrimKind Value) {
>      Trim = Value;
> @@ -44,6 +44,7 @@
>  
>    void render(raw_ostream &OS) const;
>  };
> +
>  raw_ostream &operator<<(raw_ostream &OS, const Column &Value) {
>    Value.render(OS);
>    return OS;
> @@ -64,6 +65,9 @@
>  
>    switch (Trim) {
>    case NoTrim:
> +    OS << Str;
> +    break;
> +  case WidthTrim:
>      OS << Str.substr(0, Width);
>      break;
>    case LeftTrim:
> @@ -84,8 +88,8 @@
>    return Column(Str, Width).set(Value);
>  }
>  
> -static const unsigned FileReportColumns[] = {25, 10, 8, 8, 10, 10};
> -static const unsigned FunctionReportColumns[] = {25, 10, 8, 8, 10, 8, 8};
> +static size_t FileReportColumns[] = {25, 10, 8, 8, 10, 10};
> +static size_t FunctionReportColumns[] = {25, 10, 8, 8, 10, 8, 8};
>  
>  /// \brief Prints a horizontal divider which spans across the given columns.
>  template <typename T, size_t N>
> @@ -108,8 +112,10 @@
>  }
>  
>  void CoverageReport::render(const FileCoverageSummary &File, raw_ostream &OS) {
> -  OS << column(File.Name, FileReportColumns[0], Column::LeftTrim)
> -     << format("%*u", FileReportColumns[1], (unsigned)File.RegionCoverage.NumRegions);
> +  OS << column(File.Name, FileReportColumns[0],
> +               Options.ShowFullFilenames ? Column::NoTrim : Column::LeftTrim)
> +     << format("%*u", FileReportColumns[1],
> +               (unsigned)File.RegionCoverage.NumRegions);
>    Options.colored_ostream(OS, File.RegionCoverage.isFullyCovered()
>                                    ? raw_ostream::GREEN
>                                    : raw_ostream::RED)
> @@ -191,6 +197,11 @@
>  }
>  
>  void CoverageReport::renderFileReports(raw_ostream &OS) {
> +  if (Options.ShowFullFilenames) {
> +    for (StringRef Filename : Coverage->getUniqueSourceFiles()) {
> +      FileReportColumns[0] = std::max(FileReportColumns[0], Filename.size());
> +    }
> +  }
>    OS << column("Filename", FileReportColumns[0])
>       << column("Regions", FileReportColumns[1], Column::RightAlignment)
>       << column("Miss", FileReportColumns[2], Column::RightAlignment)
> Index: tools/llvm-cov/CodeCoverage.cpp
> ===================================================================
> --- tools/llvm-cov/CodeCoverage.cpp
> +++ tools/llvm-cov/CodeCoverage.cpp
> @@ -310,14 +310,20 @@
>        "use-color", cl::desc("Emit colored output (default=autodetect)"),
>        cl::init(cl::BOU_UNSET));
>  
> +  cl::opt<bool> ShowFullFilenames(
> +      "full-filenames", cl::Optional,
> +      cl::desc("Show full filenames in the coverage report (default=false)"),
> +      cl::init(false));
> +
>    auto commandLineParser = [&, this](int argc, const char **argv) -> int {
>      cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n");
>      ViewOpts.Debug = DebugDump;
>      CompareFilenamesOnly = FilenameEquivalence;
>  
>      ViewOpts.Colors = UseColor == cl::BOU_UNSET
>                            ? sys::Process::StandardOutHasColors()
>                            : UseColor == cl::BOU_TRUE;
> +    ViewOpts.ShowFullFilenames = ShowFullFilenames;
>  
>      // Create the function filters
>      if (!NameFilters.empty() || !NameRegexFilters.empty()) {


More information about the llvm-commits mailing list