llvm.org GIT mirror llvm / c6945d9
llvm-cov: Don't use llvm::outs() in library code Nothing in lib/ should be using llvm::outs() directly. Thread it in from the caller instead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226961 91177308-0d34-0410-b5e6-96231b3b80d8 Justin Bogner 5 years ago
3 changed file(s) with 53 addition(s) and 50 deletion(s). Raw diff Collapse all Expand all
405405 }
406406 void setRunCount(uint32_t Runs) { RunCount = Runs; }
407407 void setProgramCount(uint32_t Programs) { ProgramCount = Programs; }
408 void print(StringRef MainFilename, StringRef GCNOFile, StringRef GCDAFile);
408 void print(raw_ostream &OS, StringRef MainFilename, StringRef GCNOFile,
409 StringRef GCDAFile);
409410
410411 private:
411412 std::string getCoveragePath(StringRef Filename, StringRef MainFilename);
418419 void printUncondBranchInfo(raw_ostream &OS, uint32_t &EdgeNo,
419420 uint64_t Count) const;
420421
421 void printCoverage(const GCOVCoverage &Coverage) const;
422 void printFuncCoverage() const;
423 void printFileCoverage() const;
422 void printCoverage(raw_ostream &OS, const GCOVCoverage &Coverage) const;
423 void printFuncCoverage(raw_ostream &OS) const;
424 void printFileCoverage(raw_ostream &OS) const;
424425
425426 const GCOVOptions &Options;
426427 StringMap LineInfo;
561561 }
562562
563563 /// print - Print source files with collected line count information.
564 void FileInfo::print(StringRef MainFilename, StringRef GCNOFile,
565 StringRef GCDAFile) {
564 void FileInfo::print(raw_ostream &InfoOS, StringRef MainFilename,
565 StringRef GCNOFile, StringRef GCDAFile) {
566566 for (const auto &LI : LineInfo) {
567567 StringRef Filename = LI.first();
568568 auto AllLines = LineConsumer(Filename);
569569
570570 std::string CoveragePath = getCoveragePath(Filename, MainFilename);
571 std::unique_ptr S = openCoveragePath(CoveragePath);
572 raw_ostream &OS = *S;
573
574 OS << " -: 0:Source:" << Filename << "\n";
575 OS << " -: 0:Graph:" << GCNOFile << "\n";
576 OS << " -: 0:Data:" << GCDAFile << "\n";
577 OS << " -: 0:Runs:" << RunCount << "\n";
578 OS << " -: 0:Programs:" << ProgramCount << "\n";
571 std::unique_ptr CovStream = openCoveragePath(CoveragePath);
572 raw_ostream &CovOS = *CovStream;
573
574 CovOS << " -: 0:Source:" << Filename << "\n";
575 CovOS << " -: 0:Graph:" << GCNOFile << "\n";
576 CovOS << " -: 0:Data:" << GCDAFile << "\n";
577 CovOS << " -: 0:Runs:" << RunCount << "\n";
578 CovOS << " -: 0:Programs:" << ProgramCount << "\n";
579579
580580 const LineData &Line = LI.second;
581581 GCOVCoverage FileCoverage(Filename);
584584 if (Options.BranchInfo) {
585585 FunctionLines::const_iterator FuncsIt = Line.Functions.find(LineIndex);
586586 if (FuncsIt != Line.Functions.end())
587 printFunctionSummary(OS, FuncsIt->second);
587 printFunctionSummary(CovOS, FuncsIt->second);
588588 }
589589
590590 BlockLines::const_iterator BlocksIt = Line.Blocks.find(LineIndex);
591591 if (BlocksIt == Line.Blocks.end()) {
592592 // No basic blocks are on this line. Not an executable line of code.
593 OS << " -:";
594 AllLines.printNext(OS, LineIndex + 1);
593 CovOS << " -:";
594 AllLines.printNext(CovOS, LineIndex + 1);
595595 } else {
596596 const BlockVector &Blocks = BlocksIt->second;
597597
644644 }
645645
646646 if (LineCount == 0)
647 OS << " #####:";
647 CovOS << " #####:";
648648 else {
649 OS << format("%9" PRIu64 ":", LineCount);
649 CovOS << format("%9" PRIu64 ":", LineCount);
650650 ++FileCoverage.LinesExec;
651651 }
652652 ++FileCoverage.LogicalLines;
653653
654 AllLines.printNext(OS, LineIndex + 1);
654 AllLines.printNext(CovOS, LineIndex + 1);
655655
656656 uint32_t BlockNo = 0;
657657 uint32_t EdgeNo = 0;
660660 if (Block->getLastLine() != LineIndex + 1)
661661 continue;
662662 if (Options.AllBlocks)
663 printBlockInfo(OS, *Block, LineIndex, BlockNo);
663 printBlockInfo(CovOS, *Block, LineIndex, BlockNo);
664664 if (Options.BranchInfo) {
665665 size_t NumEdges = Block->getNumDstEdges();
666666 if (NumEdges > 1)
667 printBranchInfo(OS, *Block, FileCoverage, EdgeNo);
667 printBranchInfo(CovOS, *Block, FileCoverage, EdgeNo);
668668 else if (Options.UncondBranch && NumEdges == 1)
669 printUncondBranchInfo(OS, EdgeNo, (*Block->dst_begin())->Count);
669 printUncondBranchInfo(CovOS, EdgeNo,
670 (*Block->dst_begin())->Count);
670671 }
671672 }
672673 }
676677
677678 // FIXME: There is no way to detect calls given current instrumentation.
678679 if (Options.FuncCoverage)
679 printFuncCoverage();
680 printFileCoverage();
680 printFuncCoverage(InfoOS);
681 printFileCoverage(InfoOS);
681682 return;
682683 }
683684
747748
748749 // printCoverage - Print generic coverage info used by both printFuncCoverage
749750 // and printFileCoverage.
750 void FileInfo::printCoverage(const GCOVCoverage &Coverage) const {
751 outs() << format("Lines executed:%.2f%% of %u\n",
752 double(Coverage.LinesExec) * 100 / Coverage.LogicalLines,
753 Coverage.LogicalLines);
751 void FileInfo::printCoverage(raw_ostream &OS,
752 const GCOVCoverage &Coverage) const {
753 OS << format("Lines executed:%.2f%% of %u\n",
754 double(Coverage.LinesExec) * 100 / Coverage.LogicalLines,
755 Coverage.LogicalLines);
754756 if (Options.BranchInfo) {
755757 if (Coverage.Branches) {
756 outs() << format("Branches executed:%.2f%% of %u\n",
757 double(Coverage.BranchesExec) * 100 / Coverage.Branches,
758 Coverage.Branches);
759 outs() << format("Taken at least once:%.2f%% of %u\n",
760 double(Coverage.BranchesTaken) * 100 / Coverage.Branches,
761 Coverage.Branches);
758 OS << format("Branches executed:%.2f%% of %u\n",
759 double(Coverage.BranchesExec) * 100 / Coverage.Branches,
760 Coverage.Branches);
761 OS << format("Taken at least once:%.2f%% of %u\n",
762 double(Coverage.BranchesTaken) * 100 / Coverage.Branches,
763 Coverage.Branches);
762764 } else {
763 outs() << "No branches\n";
764 }
765 outs() << "No calls\n"; // to be consistent with gcov
765 OS << "No branches\n";
766 }
767 OS << "No calls\n"; // to be consistent with gcov
766768 }
767769 }
768770
769771 // printFuncCoverage - Print per-function coverage info.
770 void FileInfo::printFuncCoverage() const {
772 void FileInfo::printFuncCoverage(raw_ostream &OS) const {
771773 for (const auto &FC : FuncCoverages) {
772774 const GCOVCoverage &Coverage = FC.second;
773 outs() << "Function '" << Coverage.Name << "'\n";
774 printCoverage(Coverage);
775 outs() << "\n";
775 OS << "Function '" << Coverage.Name << "'\n";
776 printCoverage(OS, Coverage);
777 OS << "\n";
776778 }
777779 }
778780
779781 // printFileCoverage - Print per-file coverage info.
780 void FileInfo::printFileCoverage() const {
782 void FileInfo::printFileCoverage(raw_ostream &OS) const {
781783 for (const auto &FC : FileCoverages) {
782784 const std::string &Filename = FC.first;
783785 const GCOVCoverage &Coverage = FC.second;
784 outs() << "File '" << Coverage.Name << "'\n";
785 printCoverage(Coverage);
786 OS << "File '" << Coverage.Name << "'\n";
787 printCoverage(OS, Coverage);
786788 if (!Options.NoOutput)
787 outs() << Coverage.Name << ":creating '" << Filename << "'\n";
788 outs() << "\n";
789 }
790 }
789 OS << Coverage.Name << ":creating '" << Filename << "'\n";
790 OS << "\n";
791 }
792 }
7979
8080 FileInfo FI(Options);
8181 GF.collectLineCounts(FI);
82 FI.print(SourceFile, GCNO, GCDA);
82 FI.print(llvm::outs(), SourceFile, GCNO, GCDA);
8383 }
8484
8585 int gcovMain(int argc, const char *argv[]) {