1 //===- GCOV.cpp - LLVM coverage tool --------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // GCOV implements the interface to read and write coverage files that use
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Support/GCOV.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/Support/Debug.h"
18 #include "llvm/Support/FileSystem.h"
19 #include "llvm/Support/Format.h"
20 #include "llvm/Support/MemoryObject.h"
21 #include "llvm/Support/Path.h"
22 #include "llvm/Support/system_error.h"
26 //===----------------------------------------------------------------------===//
27 // GCOVFile implementation.
29 /// readGCNO - Read GCNO buffer.
30 bool GCOVFile::readGCNO(GCOVBuffer &Buffer) {
31 if (!Buffer.readGCNOFormat()) return false;
32 if (!Buffer.readGCOVVersion(Version)) return false;
34 if (!Buffer.readInt(Checksum)) return false;
36 if (!Buffer.readFunctionTag()) break;
37 auto GFun = make_unique<GCOVFunction>(*this);
38 if (!GFun->readGCNO(Buffer, Version))
40 Functions.push_back(std::move(GFun));
43 GCNOInitialized = true;
47 /// readGCDA - Read GCDA buffer. It is required that readGCDA() can only be
48 /// called after readGCNO().
49 bool GCOVFile::readGCDA(GCOVBuffer &Buffer) {
50 assert(GCNOInitialized && "readGCDA() can only be called after readGCNO()");
51 if (!Buffer.readGCDAFormat()) return false;
52 GCOV::GCOVVersion GCDAVersion;
53 if (!Buffer.readGCOVVersion(GCDAVersion)) return false;
54 if (Version != GCDAVersion) {
55 errs() << "GCOV versions do not match.\n";
59 uint32_t GCDAChecksum;
60 if (!Buffer.readInt(GCDAChecksum)) return false;
61 if (Checksum != GCDAChecksum) {
62 errs() << "File checksums do not match: " << Checksum << " != "
63 << GCDAChecksum << ".\n";
66 for (size_t i = 0, e = Functions.size(); i < e; ++i) {
67 if (!Buffer.readFunctionTag()) {
68 errs() << "Unexpected number of functions.\n";
71 if (!Functions[i]->readGCDA(Buffer, Version))
74 if (Buffer.readObjectTag()) {
77 if (!Buffer.readInt(Length)) return false;
78 if (!Buffer.readInt(Dummy)) return false; // checksum
79 if (!Buffer.readInt(Dummy)) return false; // num
80 if (!Buffer.readInt(RunCount)) return false;
81 Buffer.advanceCursor(Length-3);
83 while (Buffer.readProgramTag()) {
85 if (!Buffer.readInt(Length)) return false;
86 Buffer.advanceCursor(Length);
93 /// dump - Dump GCOVFile content to dbgs() for debugging purposes.
94 void GCOVFile::dump() const {
95 for (const auto &FPtr : Functions)
99 /// collectLineCounts - Collect line counts. This must be used after
100 /// reading .gcno and .gcda files.
101 void GCOVFile::collectLineCounts(FileInfo &FI) {
102 for (const auto &FPtr : Functions)
103 FPtr->collectLineCounts(FI);
104 FI.setRunCount(RunCount);
105 FI.setProgramCount(ProgramCount);
108 //===----------------------------------------------------------------------===//
109 // GCOVFunction implementation.
111 /// readGCNO - Read a function from the GCNO buffer. Return false if an error
113 bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
115 if (!Buff.readInt(Dummy)) return false; // Function header length
116 if (!Buff.readInt(Ident)) return false;
117 if (!Buff.readInt(Checksum)) return false;
118 if (Version != GCOV::V402) {
119 uint32_t CfgChecksum;
120 if (!Buff.readInt(CfgChecksum)) return false;
121 if (Parent.getChecksum() != CfgChecksum) {
122 errs() << "File checksums do not match: " << Parent.getChecksum()
123 << " != " << CfgChecksum << " in (" << Name << ").\n";
127 if (!Buff.readString(Name)) return false;
128 if (!Buff.readString(Filename)) return false;
129 if (!Buff.readInt(LineNumber)) return false;
132 if (!Buff.readBlockTag()) {
133 errs() << "Block tag not found.\n";
137 if (!Buff.readInt(BlockCount)) return false;
138 for (uint32_t i = 0, e = BlockCount; i != e; ++i) {
139 if (!Buff.readInt(Dummy)) return false; // Block flags;
140 Blocks.push_back(make_unique<GCOVBlock>(*this, i));
144 while (Buff.readEdgeTag()) {
146 if (!Buff.readInt(EdgeCount)) return false;
147 EdgeCount = (EdgeCount - 1) / 2;
149 if (!Buff.readInt(BlockNo)) return false;
150 if (BlockNo >= BlockCount) {
151 errs() << "Unexpected block number: " << BlockNo << " (in " << Name
155 for (uint32_t i = 0, e = EdgeCount; i != e; ++i) {
157 if (!Buff.readInt(Dst)) return false;
158 Edges.push_back(make_unique<GCOVEdge>(*Blocks[BlockNo], *Blocks[Dst]));
159 GCOVEdge *Edge = Edges.back().get();
160 Blocks[BlockNo]->addDstEdge(Edge);
161 Blocks[Dst]->addSrcEdge(Edge);
162 if (!Buff.readInt(Dummy)) return false; // Edge flag
167 while (Buff.readLineTag()) {
168 uint32_t LineTableLength;
169 // Read the length of this line table.
170 if (!Buff.readInt(LineTableLength)) return false;
171 uint32_t EndPos = Buff.getCursor() + LineTableLength*4;
173 // Read the block number this table is associated with.
174 if (!Buff.readInt(BlockNo)) return false;
175 if (BlockNo >= BlockCount) {
176 errs() << "Unexpected block number: " << BlockNo << " (in " << Name
180 GCOVBlock &Block = *Blocks[BlockNo];
181 // Read the word that pads the beginning of the line table. This may be a
182 // flag of some sort, but seems to always be zero.
183 if (!Buff.readInt(Dummy)) return false;
185 // Line information starts here and continues up until the last word.
186 if (Buff.getCursor() != (EndPos - sizeof(uint32_t))) {
188 // Read the source file name.
189 if (!Buff.readString(F)) return false;
191 errs() << "Multiple sources for a single basic block: " << Filename
192 << " != " << F << " (in " << Name << ").\n";
195 // Read lines up to, but not including, the null terminator.
196 while (Buff.getCursor() < (EndPos - 2 * sizeof(uint32_t))) {
198 if (!Buff.readInt(Line)) return false;
199 // Line 0 means this instruction was injected by the compiler. Skip it.
203 // Read the null terminator.
204 if (!Buff.readInt(Dummy)) return false;
206 // The last word is either a flag or padding, it isn't clear which. Skip
208 if (!Buff.readInt(Dummy)) return false;
213 /// readGCDA - Read a function from the GCDA buffer. Return false if an error
215 bool GCOVFunction::readGCDA(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
217 if (!Buff.readInt(Dummy)) return false; // Function header length
220 if (!Buff.readInt(GCDAIdent)) return false;
221 if (Ident != GCDAIdent) {
222 errs() << "Function identifiers do not match: " << Ident << " != "
223 << GCDAIdent << " (in " << Name << ").\n";
227 uint32_t GCDAChecksum;
228 if (!Buff.readInt(GCDAChecksum)) return false;
229 if (Checksum != GCDAChecksum) {
230 errs() << "Function checksums do not match: " << Checksum << " != "
231 << GCDAChecksum << " (in " << Name << ").\n";
235 uint32_t CfgChecksum;
236 if (Version != GCOV::V402) {
237 if (!Buff.readInt(CfgChecksum)) return false;
238 if (Parent.getChecksum() != CfgChecksum) {
239 errs() << "File checksums do not match: " << Parent.getChecksum()
240 << " != " << CfgChecksum << " (in " << Name << ").\n";
246 if (!Buff.readString(GCDAName)) return false;
247 if (Name != GCDAName) {
248 errs() << "Function names do not match: " << Name << " != " << GCDAName
253 if (!Buff.readArcTag()) {
254 errs() << "Arc tag not found (in " << Name << ").\n";
259 if (!Buff.readInt(Count)) return false;
262 // This for loop adds the counts for each block. A second nested loop is
263 // required to combine the edge counts that are contained in the GCDA file.
264 for (uint32_t BlockNo = 0; Count > 0; ++BlockNo) {
265 // The last block is always reserved for exit block
266 if (BlockNo >= Blocks.size()-1) {
267 errs() << "Unexpected number of edges (in " << Name << ").\n";
270 GCOVBlock &Block = *Blocks[BlockNo];
271 for (size_t EdgeNo = 0, End = Block.getNumDstEdges(); EdgeNo < End;
274 errs() << "Unexpected number of edges (in " << Name << ").\n";
278 if (!Buff.readInt64(ArcCount)) return false;
279 Block.addCount(EdgeNo, ArcCount);
282 Block.sortDstEdges();
287 /// getEntryCount - Get the number of times the function was called by
288 /// retrieving the entry block's count.
289 uint64_t GCOVFunction::getEntryCount() const {
290 return Blocks.front()->getCount();
293 /// getExitCount - Get the number of times the function returned by retrieving
294 /// the exit block's count.
295 uint64_t GCOVFunction::getExitCount() const {
296 return Blocks.back()->getCount();
299 /// dump - Dump GCOVFunction content to dbgs() for debugging purposes.
300 void GCOVFunction::dump() const {
301 dbgs() << "===== " << Name << " @ " << Filename << ":" << LineNumber << "\n";
302 for (const auto &Block : Blocks)
306 /// collectLineCounts - Collect line counts. This must be used after
307 /// reading .gcno and .gcda files.
308 void GCOVFunction::collectLineCounts(FileInfo &FI) {
309 // If the line number is zero, this is a function that doesn't actually appear
310 // in the source file, so there isn't anything we can do with it.
314 for (const auto &Block : Blocks)
315 Block->collectLineCounts(FI);
316 FI.addFunctionLine(Filename, LineNumber, this);
319 //===----------------------------------------------------------------------===//
320 // GCOVBlock implementation.
322 /// ~GCOVBlock - Delete GCOVBlock and its content.
323 GCOVBlock::~GCOVBlock() {
329 /// addCount - Add to block counter while storing the edge count. If the
330 /// destination has no outgoing edges, also update that block's count too.
331 void GCOVBlock::addCount(size_t DstEdgeNo, uint64_t N) {
332 assert(DstEdgeNo < DstEdges.size()); // up to caller to ensure EdgeNo is valid
333 DstEdges[DstEdgeNo]->Count = N;
335 if (!DstEdges[DstEdgeNo]->Dst.getNumDstEdges())
336 DstEdges[DstEdgeNo]->Dst.Counter += N;
339 /// sortDstEdges - Sort destination edges by block number, nop if already
340 /// sorted. This is required for printing branch info in the correct order.
341 void GCOVBlock::sortDstEdges() {
342 if (!DstEdgesAreSorted) {
343 SortDstEdgesFunctor SortEdges;
344 std::stable_sort(DstEdges.begin(), DstEdges.end(), SortEdges);
348 /// collectLineCounts - Collect line counts. This must be used after
349 /// reading .gcno and .gcda files.
350 void GCOVBlock::collectLineCounts(FileInfo &FI) {
351 for (SmallVectorImpl<uint32_t>::iterator I = Lines.begin(),
352 E = Lines.end(); I != E; ++I)
353 FI.addBlockLine(Parent.getFilename(), *I, this);
356 /// dump - Dump GCOVBlock content to dbgs() for debugging purposes.
357 void GCOVBlock::dump() const {
358 dbgs() << "Block : " << Number << " Counter : " << Counter << "\n";
359 if (!SrcEdges.empty()) {
360 dbgs() << "\tSource Edges : ";
361 for (EdgeIterator I = SrcEdges.begin(), E = SrcEdges.end(); I != E; ++I) {
362 const GCOVEdge *Edge = *I;
363 dbgs() << Edge->Src.Number << " (" << Edge->Count << "), ";
367 if (!DstEdges.empty()) {
368 dbgs() << "\tDestination Edges : ";
369 for (EdgeIterator I = DstEdges.begin(), E = DstEdges.end(); I != E; ++I) {
370 const GCOVEdge *Edge = *I;
371 dbgs() << Edge->Dst.Number << " (" << Edge->Count << "), ";
375 if (!Lines.empty()) {
376 dbgs() << "\tLines : ";
377 for (SmallVectorImpl<uint32_t>::const_iterator I = Lines.begin(),
378 E = Lines.end(); I != E; ++I)
379 dbgs() << (*I) << ",";
384 //===----------------------------------------------------------------------===//
385 // FileInfo implementation.
387 // Safe integer division, returns 0 if numerator is 0.
388 static uint32_t safeDiv(uint64_t Numerator, uint64_t Divisor) {
391 return Numerator/Divisor;
394 // This custom division function mimics gcov's branch ouputs:
395 // - Round to closest whole number
396 // - Only output 0% or 100% if it's exactly that value
397 static uint32_t branchDiv(uint64_t Numerator, uint64_t Divisor) {
400 if (Numerator == Divisor)
403 uint8_t Res = (Numerator*100+Divisor/2) / Divisor;
411 struct formatBranchInfo {
412 formatBranchInfo(const GCOVOptions &Options, uint64_t Count,
414 Options(Options), Count(Count), Total(Total) {}
416 void print(raw_ostream &OS) const {
418 OS << "never executed";
419 else if (Options.BranchCount)
420 OS << "taken " << Count;
422 OS << "taken " << branchDiv(Count, Total) << "%";
425 const GCOVOptions &Options;
430 static raw_ostream &operator<<(raw_ostream &OS, const formatBranchInfo &FBI) {
437 std::unique_ptr<MemoryBuffer> Buffer;
440 LineConsumer(StringRef Filename) {
441 if (error_code EC = MemoryBuffer::getFileOrSTDIN(Filename, Buffer)) {
442 errs() << Filename << ": " << EC.message() << "\n";
445 Remaining = Buffer->getBuffer();
447 bool empty() { return Remaining.empty(); }
448 void printNext(raw_ostream &OS, uint32_t LineNum) {
453 std::tie(Line, Remaining) = Remaining.split("\n");
454 OS << format("%5u:", LineNum) << Line << "\n";
459 /// Convert a path to a gcov filename. If PreservePaths is true, this
460 /// translates "/" to "#", ".." to "^", and drops ".", to match gcov.
461 static std::string mangleCoveragePath(StringRef Filename, bool PreservePaths) {
463 return sys::path::filename(Filename).str();
465 // This behaviour is defined by gcov in terms of text replacements, so it's
466 // not likely to do anything useful on filesystems with different textual
468 llvm::SmallString<256> Result("");
469 StringRef::iterator I, S, E;
470 for (I = S = Filename.begin(), E = Filename.end(); I != E; ++I) {
474 if (I - S == 1 && *S == '.') {
475 // ".", the current directory, is skipped.
476 } else if (I - S == 2 && *S == '.' && *(S + 1) == '.') {
477 // "..", the parent directory, is replaced with "^".
481 // Leave other components intact,
483 // And separate with "#".
484 Result.push_back('#');
494 std::string FileInfo::getCoveragePath(StringRef Filename,
495 StringRef MainFilename) {
496 if (Options.NoOutput)
497 // This is probably a bug in gcov, but when -n is specified, paths aren't
498 // mangled at all, and the -l and -p options are ignored. Here, we do the
502 std::string CoveragePath;
503 if (Options.LongFileNames && !Filename.equals(MainFilename))
505 mangleCoveragePath(MainFilename, Options.PreservePaths) + "##";
507 mangleCoveragePath(Filename, Options.PreservePaths) + ".gcov";
511 std::unique_ptr<raw_ostream>
512 FileInfo::openCoveragePath(StringRef CoveragePath) {
513 if (Options.NoOutput)
514 return llvm::make_unique<raw_null_ostream>();
516 std::string ErrorInfo;
517 auto OS = llvm::make_unique<raw_fd_ostream>(CoveragePath.str().c_str(),
518 ErrorInfo, sys::fs::F_Text);
519 if (!ErrorInfo.empty()) {
520 errs() << ErrorInfo << "\n";
521 return llvm::make_unique<raw_null_ostream>();
523 return std::move(OS);
526 /// print - Print source files with collected line count information.
527 void FileInfo::print(StringRef MainFilename, StringRef GCNOFile,
528 StringRef GCDAFile) {
529 for (StringMap<LineData>::const_iterator I = LineInfo.begin(),
530 E = LineInfo.end(); I != E; ++I) {
531 StringRef Filename = I->first();
532 auto AllLines = LineConsumer(Filename);
534 std::string CoveragePath = getCoveragePath(Filename, MainFilename);
535 std::unique_ptr<raw_ostream> S = openCoveragePath(CoveragePath);
536 raw_ostream &OS = *S;
538 OS << " -: 0:Source:" << Filename << "\n";
539 OS << " -: 0:Graph:" << GCNOFile << "\n";
540 OS << " -: 0:Data:" << GCDAFile << "\n";
541 OS << " -: 0:Runs:" << RunCount << "\n";
542 OS << " -: 0:Programs:" << ProgramCount << "\n";
544 const LineData &Line = I->second;
545 GCOVCoverage FileCoverage(Filename);
546 for (uint32_t LineIndex = 0;
547 LineIndex < Line.LastLine || !AllLines.empty(); ++LineIndex) {
548 if (Options.BranchInfo) {
549 FunctionLines::const_iterator FuncsIt = Line.Functions.find(LineIndex);
550 if (FuncsIt != Line.Functions.end())
551 printFunctionSummary(OS, FuncsIt->second);
554 BlockLines::const_iterator BlocksIt = Line.Blocks.find(LineIndex);
555 if (BlocksIt == Line.Blocks.end()) {
556 // No basic blocks are on this line. Not an executable line of code.
558 AllLines.printNext(OS, LineIndex + 1);
560 const BlockVector &Blocks = BlocksIt->second;
562 // Add up the block counts to form line counts.
563 DenseMap<const GCOVFunction *, bool> LineExecs;
564 uint64_t LineCount = 0;
565 for (BlockVector::const_iterator I = Blocks.begin(), E = Blocks.end();
567 const GCOVBlock *Block = *I;
568 if (Options.AllBlocks) {
569 // Only take the highest block count for that line.
570 uint64_t BlockCount = Block->getCount();
571 LineCount = LineCount > BlockCount ? LineCount : BlockCount;
573 // Sum up all of the block counts.
574 LineCount += Block->getCount();
577 if (Options.FuncCoverage) {
578 // This is a slightly convoluted way to most accurately gather line
579 // statistics for functions. Basically what is happening is that we
580 // don't want to count a single line with multiple blocks more than
581 // once. However, we also don't simply want to give the total line
582 // count to every function that starts on the line. Thus, what is
583 // happening here are two things:
584 // 1) Ensure that the number of logical lines is only incremented
585 // once per function.
586 // 2) If there are multiple blocks on the same line, ensure that the
587 // number of lines executed is incremented as long as at least
588 // one of the blocks are executed.
589 const GCOVFunction *Function = &Block->getParent();
590 if (FuncCoverages.find(Function) == FuncCoverages.end()) {
591 std::pair<const GCOVFunction *, GCOVCoverage>
592 KeyValue(Function, GCOVCoverage(Function->getName()));
593 FuncCoverages.insert(KeyValue);
595 GCOVCoverage &FuncCoverage = FuncCoverages.find(Function)->second;
597 if (LineExecs.find(Function) == LineExecs.end()) {
598 if (Block->getCount()) {
599 ++FuncCoverage.LinesExec;
600 LineExecs[Function] = true;
602 LineExecs[Function] = false;
604 ++FuncCoverage.LogicalLines;
605 } else if (!LineExecs[Function] && Block->getCount()) {
606 ++FuncCoverage.LinesExec;
607 LineExecs[Function] = true;
615 OS << format("%9" PRIu64 ":", LineCount);
616 ++FileCoverage.LinesExec;
618 ++FileCoverage.LogicalLines;
620 AllLines.printNext(OS, LineIndex + 1);
622 uint32_t BlockNo = 0;
624 for (BlockVector::const_iterator I = Blocks.begin(), E = Blocks.end();
626 const GCOVBlock *Block = *I;
628 // Only print block and branch information at the end of the block.
629 if (Block->getLastLine() != LineIndex+1)
631 if (Options.AllBlocks)
632 printBlockInfo(OS, *Block, LineIndex, BlockNo);
633 if (Options.BranchInfo) {
634 size_t NumEdges = Block->getNumDstEdges();
636 printBranchInfo(OS, *Block, FileCoverage, EdgeNo);
637 else if (Options.UncondBranch && NumEdges == 1)
638 printUncondBranchInfo(OS, EdgeNo, (*Block->dst_begin())->Count);
643 FileCoverages.push_back(std::make_pair(CoveragePath, FileCoverage));
646 // FIXME: There is no way to detect calls given current instrumentation.
647 if (Options.FuncCoverage)
653 /// printFunctionSummary - Print function and block summary.
654 void FileInfo::printFunctionSummary(raw_ostream &OS,
655 const FunctionVector &Funcs) const {
656 for (FunctionVector::const_iterator I = Funcs.begin(), E = Funcs.end();
658 const GCOVFunction *Func = *I;
659 uint64_t EntryCount = Func->getEntryCount();
660 uint32_t BlocksExec = 0;
661 for (GCOVFunction::BlockIterator I = Func->block_begin(),
662 E = Func->block_end(); I != E; ++I) {
663 const GCOVBlock &Block = **I;
664 if (Block.getNumDstEdges() && Block.getCount())
668 OS << "function " << Func->getName() << " called " << EntryCount
669 << " returned " << safeDiv(Func->getExitCount()*100, EntryCount)
670 << "% blocks executed "
671 << safeDiv(BlocksExec*100, Func->getNumBlocks()-1) << "%\n";
675 /// printBlockInfo - Output counts for each block.
676 void FileInfo::printBlockInfo(raw_ostream &OS, const GCOVBlock &Block,
677 uint32_t LineIndex, uint32_t &BlockNo) const {
678 if (Block.getCount() == 0)
681 OS << format("%9" PRIu64 ":", Block.getCount());
682 OS << format("%5u-block %2u\n", LineIndex+1, BlockNo++);
685 /// printBranchInfo - Print conditional branch probabilities.
686 void FileInfo::printBranchInfo(raw_ostream &OS, const GCOVBlock &Block,
687 GCOVCoverage &Coverage, uint32_t &EdgeNo) {
688 SmallVector<uint64_t, 16> BranchCounts;
689 uint64_t TotalCounts = 0;
690 for (GCOVBlock::EdgeIterator I = Block.dst_begin(), E = Block.dst_end();
692 const GCOVEdge *Edge = *I;
693 BranchCounts.push_back(Edge->Count);
694 TotalCounts += Edge->Count;
695 if (Block.getCount()) ++Coverage.BranchesExec;
696 if (Edge->Count) ++Coverage.BranchesTaken;
699 if (Options.FuncCoverage) {
700 const GCOVFunction *Function = &Block.getParent();
701 GCOVCoverage &FuncCoverage = FuncCoverages.find(Function)->second;
702 if (Block.getCount()) ++FuncCoverage.BranchesExec;
703 if (Edge->Count) ++FuncCoverage.BranchesTaken;
704 ++FuncCoverage.Branches;
708 for (SmallVectorImpl<uint64_t>::const_iterator I = BranchCounts.begin(),
709 E = BranchCounts.end(); I != E; ++I) {
710 OS << format("branch %2u ", EdgeNo++)
711 << formatBranchInfo(Options, *I, TotalCounts) << "\n";
715 /// printUncondBranchInfo - Print unconditional branch probabilities.
716 void FileInfo::printUncondBranchInfo(raw_ostream &OS, uint32_t &EdgeNo,
717 uint64_t Count) const {
718 OS << format("unconditional %2u ", EdgeNo++)
719 << formatBranchInfo(Options, Count, Count) << "\n";
722 // printCoverage - Print generic coverage info used by both printFuncCoverage
723 // and printFileCoverage.
724 void FileInfo::printCoverage(const GCOVCoverage &Coverage) const {
725 outs() << format("Lines executed:%.2f%% of %u\n",
726 double(Coverage.LinesExec)*100/Coverage.LogicalLines,
727 Coverage.LogicalLines);
728 if (Options.BranchInfo) {
729 if (Coverage.Branches) {
730 outs() << format("Branches executed:%.2f%% of %u\n",
731 double(Coverage.BranchesExec)*100/Coverage.Branches,
733 outs() << format("Taken at least once:%.2f%% of %u\n",
734 double(Coverage.BranchesTaken)*100/Coverage.Branches,
737 outs() << "No branches\n";
739 outs() << "No calls\n"; // to be consistent with gcov
743 // printFuncCoverage - Print per-function coverage info.
744 void FileInfo::printFuncCoverage() const {
745 for (FuncCoverageMap::const_iterator I = FuncCoverages.begin(),
746 E = FuncCoverages.end(); I != E; ++I) {
747 const GCOVCoverage &Coverage = I->second;
748 outs() << "Function '" << Coverage.Name << "'\n";
749 printCoverage(Coverage);
754 // printFileCoverage - Print per-file coverage info.
755 void FileInfo::printFileCoverage() const {
756 for (FileCoverageList::const_iterator I = FileCoverages.begin(),
757 E = FileCoverages.end(); I != E; ++I) {
758 const std::string &Filename = I->first;
759 const GCOVCoverage &Coverage = I->second;
760 outs() << "File '" << Coverage.Name << "'\n";
761 printCoverage(Coverage);
762 if (!Options.NoOutput)
763 outs() << Coverage.Name << ":creating '" << Filename << "'\n";