X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fllvm-cov%2FCodeCoverage.cpp;h=4ff53301881d1b55069d71a99ceb1abccf4d2b9c;hb=69266c39908276c9ba636160d1ee9d985506ac98;hp=eef4732c9c58cc04df4796df2a65ff1dccf83c2d;hpb=6e5def6b3e4dc03de81dff9382abe8afa82e4f3f;p=oota-llvm.git diff --git a/tools/llvm-cov/CodeCoverage.cpp b/tools/llvm-cov/CodeCoverage.cpp index eef4732c9c5..4ff53301881 100644 --- a/tools/llvm-cov/CodeCoverage.cpp +++ b/tools/llvm-cov/CodeCoverage.cpp @@ -14,24 +14,23 @@ //===----------------------------------------------------------------------===// #include "RenderingSupport.h" -#include "CoverageViewOptions.h" #include "CoverageFilters.h" -#include "SourceCoverageView.h" -#include "CoverageSummary.h" #include "CoverageReport.h" -#include "llvm/ADT/StringRef.h" +#include "CoverageViewOptions.h" +#include "SourceCoverageView.h" #include "llvm/ADT/SmallString.h" -#include "llvm/ProfileData/InstrProfReader.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Triple.h" #include "llvm/ProfileData/CoverageMapping.h" -#include "llvm/ProfileData/CoverageMappingReader.h" +#include "llvm/ProfileData/InstrProfReader.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" -#include "llvm/Support/ManagedStatic.h" -#include "llvm/Support/MemoryObject.h" #include "llvm/Support/Format.h" +#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Path.h" -#include "llvm/Support/Signals.h" #include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/Process.h" +#include "llvm/Support/Signals.h" #include #include @@ -90,6 +89,7 @@ public: LoadedSourceFiles; bool CompareFilenamesOnly; StringMap RemappedFilenames; + llvm::Triple::ArchType CoverageArch; }; } @@ -116,8 +116,7 @@ CodeCoverageTool::getSourceFile(StringRef SourceFile) { error(EC.message(), SourceFile); return EC; } - LoadedSourceFiles.push_back( - std::make_pair(SourceFile, std::move(Buffer.get()))); + LoadedSourceFiles.emplace_back(SourceFile, std::move(Buffer.get())); return *LoadedSourceFiles.back().second; } @@ -195,8 +194,22 @@ CodeCoverageTool::createSourceFileView(StringRef SourceFile, return View; } +static bool modifiedTimeGT(StringRef LHS, StringRef RHS) { + sys::fs::file_status Status; + if (sys::fs::status(LHS, Status)) + return false; + auto LHSTime = Status.getLastModificationTime(); + if (sys::fs::status(RHS, Status)) + return false; + auto RHSTime = Status.getLastModificationTime(); + return LHSTime > RHSTime; +} + std::unique_ptr CodeCoverageTool::load() { - auto CoverageOrErr = CoverageMapping::load(ObjectFilename, PGOFilename); + if (modifiedTimeGT(ObjectFilename, PGOFilename)) + errs() << "warning: profile data may be out of date - object is newer\n"; + auto CoverageOrErr = CoverageMapping::load(ObjectFilename, PGOFilename, + CoverageArch); if (std::error_code EC = CoverageOrErr.getError()) { colored_ostream(errs(), raw_ostream::RED) << "error: Failed to load coverage: " << EC.message(); @@ -245,6 +258,9 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { cl::desc( "File with the profile data obtained after an instrumented run")); + cl::opt Arch( + "arch", cl::desc("architecture of the coverage mapping binary")); + cl::opt DebugDump("dump", cl::Optional, cl::desc("Show internal debug dump")); @@ -290,11 +306,19 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { "greater than the given threshold"), cl::cat(FilteringCategory)); + cl::opt UseColor( + "use-color", cl::desc("Emit colored output (default=autodetect)"), + cl::init(cl::BOU_UNSET)); + 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; + // Create the function filters if (!NameFilters.empty() || !NameRegexFilters.empty()) { auto NameFilterer = new CoverageFilters; @@ -325,12 +349,23 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { Filters.push_back(std::unique_ptr(StatFilterer)); } - for (const auto &File : InputSourceFiles) { - SmallString<128> Path(File); - if (std::error_code EC = sys::fs::make_absolute(Path)) { - errs() << "error: " << File << ": " << EC.message(); + if (Arch.empty()) + CoverageArch = llvm::Triple::ArchType::UnknownArch; + else { + CoverageArch = Triple(Arch).getArch(); + if (CoverageArch == llvm::Triple::ArchType::UnknownArch) { + errs() << "error: Unknown architecture: " << Arch << "\n"; return 1; } + } + + for (const auto &File : InputSourceFiles) { + SmallString<128> Path(File); + if (!CompareFilenamesOnly) + if (std::error_code EC = sys::fs::make_absolute(Path)) { + errs() << "error: " << File << ": " << EC.message(); + return 1; + } SourceFiles.push_back(Path.str()); } return 0; @@ -374,15 +409,10 @@ int CodeCoverageTool::show(int argc, const char **argv, cl::desc("Show function instantiations"), cl::cat(ViewCategory)); - cl::opt NoColors("no-colors", cl::Optional, - cl::desc("Don't show text colors"), cl::init(false), - cl::cat(ViewCategory)); - auto Err = commandLineParser(argc, argv); if (Err) return Err; - ViewOpts.Colors = !NoColors; ViewOpts.ShowLineNumbers = true; ViewOpts.ShowLineStats = ShowLineExecutionCounts.getNumOccurrences() != 0 || !ShowRegions || ShowBestLineRegionsCounts; @@ -448,37 +478,28 @@ int CodeCoverageTool::show(int argc, const char **argv, int CodeCoverageTool::report(int argc, const char **argv, CommandLineParserType commandLineParser) { - cl::opt NoColors("no-colors", cl::Optional, - cl::desc("Don't show text colors"), cl::init(false)); - auto Err = commandLineParser(argc, argv); if (Err) return Err; - ViewOpts.Colors = !NoColors; - auto Coverage = load(); if (!Coverage) return 1; - CoverageSummary Summarizer; - Summarizer.createSummaries(Coverage->getCoveredFunctions()); - CoverageReport Report(ViewOpts, Summarizer); - if (SourceFiles.empty() && Filters.empty()) { + CoverageReport Report(ViewOpts, std::move(Coverage)); + if (SourceFiles.empty()) Report.renderFileReports(llvm::outs()); - return 0; - } - - Report.renderFunctionReports(llvm::outs()); + else + Report.renderFunctionReports(SourceFiles, llvm::outs()); return 0; } -int show_main(int argc, const char **argv) { +int showMain(int argc, const char *argv[]) { CodeCoverageTool Tool; return Tool.run(CodeCoverageTool::Show, argc, argv); } -int report_main(int argc, const char **argv) { +int reportMain(int argc, const char *argv[]) { CodeCoverageTool Tool; return Tool.run(CodeCoverageTool::Report, argc, argv); }