| Devang Patel | 58c6200 | 2011-10-04 17:24:48 +0000 | [diff] [blame] | 1 | //===- GCOVr.cpp - LLVM coverage tool -------------------------------------===// |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| Devang Patel | 58c6200 | 2011-10-04 17:24:48 +0000 | [diff] [blame] | 10 | // GCOV implements the interface to read and write coverage files that use |
| 11 | // 'gcov' format. |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 12 | // |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| Yuchen Wu | 81e3828 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 15 | #include "llvm/Support/Debug.h" |
| Devang Patel | 58c6200 | 2011-10-04 17:24:48 +0000 | [diff] [blame] | 16 | #include "llvm/Support/GCOV.h" |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/OwningPtr.h" |
| Devang Patel | 7a50202 | 2011-09-29 16:46:47 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/STLExtras.h" |
| Bob Wilson | e877eeb | 2013-10-22 05:09:41 +0000 | [diff] [blame] | 19 | #include "llvm/Support/Format.h" |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 20 | #include "llvm/Support/MemoryObject.h" |
| 21 | #include "llvm/Support/system_error.h" |
| 22 | using namespace llvm; |
| 23 | |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | // GCOVFile implementation. |
| 26 | |
| 27 | /// ~GCOVFile - Delete GCOVFile and its content. |
| 28 | GCOVFile::~GCOVFile() { |
| 29 | DeleteContainerPointers(Functions); |
| 30 | } |
| 31 | |
| Devang Patel | 0066f92 | 2011-09-29 17:06:40 +0000 | [diff] [blame] | 32 | /// isGCDAFile - Return true if Format identifies a .gcda file. |
| Bill Wendling | e4fb6ea | 2012-08-31 17:31:28 +0000 | [diff] [blame] | 33 | static bool isGCDAFile(GCOV::GCOVFormat Format) { |
| 34 | return Format == GCOV::GCDA_402 || Format == GCOV::GCDA_404; |
| Devang Patel | 0066f92 | 2011-09-29 17:06:40 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | /// isGCNOFile - Return true if Format identifies a .gcno file. |
| Bill Wendling | e4fb6ea | 2012-08-31 17:31:28 +0000 | [diff] [blame] | 38 | static bool isGCNOFile(GCOV::GCOVFormat Format) { |
| 39 | return Format == GCOV::GCNO_402 || Format == GCOV::GCNO_404; |
| Devang Patel | 0066f92 | 2011-09-29 17:06:40 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 42 | /// read - Read GCOV buffer. |
| 43 | bool GCOVFile::read(GCOVBuffer &Buffer) { |
| Bill Wendling | e4fb6ea | 2012-08-31 17:31:28 +0000 | [diff] [blame] | 44 | GCOV::GCOVFormat Format = Buffer.readGCOVFormat(); |
| 45 | if (Format == GCOV::InvalidGCOV) |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 46 | return false; |
| 47 | |
| Yuchen Wu | 76fa4d6 | 2013-10-25 02:22:21 +0000 | [diff] [blame] | 48 | if (isGCNOFile(Format)) { |
| 49 | while (true) { |
| 50 | GCOVFunction *GFun = new GCOVFunction(); |
| 51 | if (!GFun->read(Buffer, Format)) |
| 52 | break; |
| Devang Patel | 0066f92 | 2011-09-29 17:06:40 +0000 | [diff] [blame] | 53 | Functions.push_back(GFun); |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 54 | } |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 55 | } |
| Yuchen Wu | 76fa4d6 | 2013-10-25 02:22:21 +0000 | [diff] [blame] | 56 | else if (isGCDAFile(Format)) { |
| 57 | for (size_t i = 0, e = Functions.size(); i < e; ++i) { |
| 58 | bool ReadGCDA = Functions[i]->read(Buffer, Format); |
| 59 | (void)ReadGCDA; |
| 60 | assert(ReadGCDA && ".gcda data does not match .gcno data"); |
| 61 | } |
| Yuchen Wu | e85959c | 2013-11-05 01:11:58 +0000 | [diff] [blame] | 62 | if (Buffer.readObjectTag()) { |
| 63 | uint32_t Length = Buffer.readInt(); |
| 64 | Buffer.readInt(); // checksum |
| 65 | Buffer.readInt(); // num |
| 66 | RunCount = Buffer.readInt(); |
| 67 | Buffer.advanceCursor(Length-3); |
| 68 | } |
| 69 | while (Buffer.readProgramTag()) { |
| 70 | uint32_t Length = Buffer.readInt(); |
| 71 | Buffer.advanceCursor(Length); |
| Yuchen Wu | 76fa4d6 | 2013-10-25 02:22:21 +0000 | [diff] [blame] | 72 | ++ProgramCount; |
| Yuchen Wu | e85959c | 2013-11-05 01:11:58 +0000 | [diff] [blame] | 73 | } |
| Yuchen Wu | 76fa4d6 | 2013-10-25 02:22:21 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 76 | return true; |
| 77 | } |
| 78 | |
| Yuchen Wu | 81e3828 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 79 | /// dump - Dump GCOVFile content to dbgs() for debugging purposes. |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 80 | void GCOVFile::dump() { |
| Craig Topper | 6227d5c | 2013-07-04 01:31:24 +0000 | [diff] [blame] | 81 | for (SmallVectorImpl<GCOVFunction *>::iterator I = Functions.begin(), |
| Bill Wendling | 56cb229 | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 82 | E = Functions.end(); I != E; ++I) |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 83 | (*I)->dump(); |
| 84 | } |
| 85 | |
| 86 | /// collectLineCounts - Collect line counts. This must be used after |
| 87 | /// reading .gcno and .gcda files. |
| 88 | void GCOVFile::collectLineCounts(FileInfo &FI) { |
| Craig Topper | 6227d5c | 2013-07-04 01:31:24 +0000 | [diff] [blame] | 89 | for (SmallVectorImpl<GCOVFunction *>::iterator I = Functions.begin(), |
| Bill Wendling | 56cb229 | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 90 | E = Functions.end(); I != E; ++I) |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 91 | (*I)->collectLineCounts(FI); |
| Yuchen Wu | e85959c | 2013-11-05 01:11:58 +0000 | [diff] [blame] | 92 | FI.setRunCount(RunCount); |
| Yuchen Wu | 76fa4d6 | 2013-10-25 02:22:21 +0000 | [diff] [blame] | 93 | FI.setProgramCount(ProgramCount); |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | //===----------------------------------------------------------------------===// |
| 97 | // GCOVFunction implementation. |
| 98 | |
| 99 | /// ~GCOVFunction - Delete GCOVFunction and its content. |
| 100 | GCOVFunction::~GCOVFunction() { |
| 101 | DeleteContainerPointers(Blocks); |
| 102 | } |
| 103 | |
| Bob Wilson | 0a2463c | 2013-10-22 19:54:32 +0000 | [diff] [blame] | 104 | /// read - Read a function from the buffer. Return false if buffer cursor |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 105 | /// does not point to a function tag. |
| Bill Wendling | e4fb6ea | 2012-08-31 17:31:28 +0000 | [diff] [blame] | 106 | bool GCOVFunction::read(GCOVBuffer &Buff, GCOV::GCOVFormat Format) { |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 107 | if (!Buff.readFunctionTag()) |
| 108 | return false; |
| 109 | |
| 110 | Buff.readInt(); // Function header length |
| 111 | Ident = Buff.readInt(); |
| 112 | Buff.readInt(); // Checksum #1 |
| Bill Wendling | a37d96a | 2013-06-25 18:13:52 +0000 | [diff] [blame] | 113 | if (Format != GCOV::GCNO_402 && Format != GCOV::GCDA_402) |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 114 | Buff.readInt(); // Checksum #2 |
| 115 | |
| 116 | Name = Buff.readString(); |
| Bill Wendling | e4fb6ea | 2012-08-31 17:31:28 +0000 | [diff] [blame] | 117 | if (Format == GCOV::GCNO_402 || Format == GCOV::GCNO_404) |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 118 | Filename = Buff.readString(); |
| 119 | |
| Bill Wendling | e4fb6ea | 2012-08-31 17:31:28 +0000 | [diff] [blame] | 120 | if (Format == GCOV::GCDA_402 || Format == GCOV::GCDA_404) { |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 121 | Buff.readArcTag(); |
| Yuchen Wu | cbbd208 | 2013-10-24 01:51:04 +0000 | [diff] [blame] | 122 | uint32_t i = 0; |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 123 | uint32_t Count = Buff.readInt() / 2; |
| Yuchen Wu | cbbd208 | 2013-10-24 01:51:04 +0000 | [diff] [blame] | 124 | |
| 125 | // This for loop adds the counts for each block. A second nested loop is |
| 126 | // required to combine the edge counts that are contained in the GCDA file. |
| 127 | for (uint32_t Line = 0; i < Count; ++Line) { |
| 128 | GCOVBlock &Block = *Blocks[Line]; |
| 129 | for (size_t Edge = 0, End = Block.getNumEdges(); Edge < End; ++Edge) { |
| 130 | assert(i < Count && "Unexpected number of Edges!"); |
| 131 | Block.addCount(Buff.readInt64()); |
| 132 | ++i; |
| 133 | } |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 134 | } |
| Chad Rosier | 90f2004 | 2012-02-22 17:25:00 +0000 | [diff] [blame] | 135 | return true; |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | LineNumber = Buff.readInt(); |
| 139 | |
| 140 | // read blocks. |
| Nick Lewycky | 85aa4f6 | 2012-09-23 03:58:21 +0000 | [diff] [blame] | 141 | bool BlockTagFound = Buff.readBlockTag(); |
| 142 | (void)BlockTagFound; |
| 143 | assert(BlockTagFound && "Block Tag not found!"); |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 144 | uint32_t BlockCount = Buff.readInt(); |
| Bob Wilson | 67fa539 | 2013-10-22 20:02:36 +0000 | [diff] [blame] | 145 | for (uint32_t i = 0, e = BlockCount; i != e; ++i) { |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 146 | Buff.readInt(); // Block flags; |
| 147 | Blocks.push_back(new GCOVBlock(i)); |
| 148 | } |
| 149 | |
| 150 | // read edges. |
| 151 | while (Buff.readEdgeTag()) { |
| 152 | uint32_t EdgeCount = (Buff.readInt() - 1) / 2; |
| 153 | uint32_t BlockNo = Buff.readInt(); |
| Nick Lewycky | 85aa4f6 | 2012-09-23 03:58:21 +0000 | [diff] [blame] | 154 | assert(BlockNo < BlockCount && "Unexpected Block number!"); |
| Bob Wilson | 67fa539 | 2013-10-22 20:02:36 +0000 | [diff] [blame] | 155 | for (uint32_t i = 0, e = EdgeCount; i != e; ++i) { |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 156 | Blocks[BlockNo]->addEdge(Buff.readInt()); |
| 157 | Buff.readInt(); // Edge flag |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | // read line table. |
| 162 | while (Buff.readLineTag()) { |
| 163 | uint32_t LineTableLength = Buff.readInt(); |
| Bob Wilson | 0a2463c | 2013-10-22 19:54:32 +0000 | [diff] [blame] | 164 | uint32_t EndPos = Buff.getCursor() + LineTableLength*4; |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 165 | uint32_t BlockNo = Buff.readInt(); |
| Nick Lewycky | 85aa4f6 | 2012-09-23 03:58:21 +0000 | [diff] [blame] | 166 | assert(BlockNo < BlockCount && "Unexpected Block number!"); |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 167 | GCOVBlock *Block = Blocks[BlockNo]; |
| 168 | Buff.readInt(); // flag |
| Bob Wilson | 0a2463c | 2013-10-22 19:54:32 +0000 | [diff] [blame] | 169 | while (Buff.getCursor() != (EndPos - 4)) { |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 170 | StringRef Filename = Buff.readString(); |
| Bob Wilson | 0a2463c | 2013-10-22 19:54:32 +0000 | [diff] [blame] | 171 | if (Buff.getCursor() == (EndPos - 4)) break; |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 172 | while (uint32_t L = Buff.readInt()) |
| Bill Wendling | 56cb229 | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 173 | Block->addLine(Filename, L); |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 174 | } |
| 175 | Buff.readInt(); // flag |
| 176 | } |
| 177 | return true; |
| 178 | } |
| 179 | |
| Yuchen Wu | 81e3828 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 180 | /// dump - Dump GCOVFunction content to dbgs() for debugging purposes. |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 181 | void GCOVFunction::dump() { |
| Yuchen Wu | 81e3828 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 182 | dbgs() << "===== " << Name << " @ " << Filename << ":" << LineNumber << "\n"; |
| Craig Topper | 6227d5c | 2013-07-04 01:31:24 +0000 | [diff] [blame] | 183 | for (SmallVectorImpl<GCOVBlock *>::iterator I = Blocks.begin(), |
| Bill Wendling | 56cb229 | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 184 | E = Blocks.end(); I != E; ++I) |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 185 | (*I)->dump(); |
| 186 | } |
| 187 | |
| 188 | /// collectLineCounts - Collect line counts. This must be used after |
| 189 | /// reading .gcno and .gcda files. |
| 190 | void GCOVFunction::collectLineCounts(FileInfo &FI) { |
| Craig Topper | 6227d5c | 2013-07-04 01:31:24 +0000 | [diff] [blame] | 191 | for (SmallVectorImpl<GCOVBlock *>::iterator I = Blocks.begin(), |
| Bill Wendling | 56cb229 | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 192 | E = Blocks.end(); I != E; ++I) |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 193 | (*I)->collectLineCounts(FI); |
| 194 | } |
| 195 | |
| 196 | //===----------------------------------------------------------------------===// |
| 197 | // GCOVBlock implementation. |
| 198 | |
| 199 | /// ~GCOVBlock - Delete GCOVBlock and its content. |
| 200 | GCOVBlock::~GCOVBlock() { |
| 201 | Edges.clear(); |
| 202 | DeleteContainerSeconds(Lines); |
| 203 | } |
| 204 | |
| 205 | void GCOVBlock::addLine(StringRef Filename, uint32_t LineNo) { |
| 206 | GCOVLines *&LinesForFile = Lines[Filename]; |
| 207 | if (!LinesForFile) |
| 208 | LinesForFile = new GCOVLines(); |
| 209 | LinesForFile->add(LineNo); |
| 210 | } |
| 211 | |
| 212 | /// collectLineCounts - Collect line counts. This must be used after |
| 213 | /// reading .gcno and .gcda files. |
| 214 | void GCOVBlock::collectLineCounts(FileInfo &FI) { |
| 215 | for (StringMap<GCOVLines *>::iterator I = Lines.begin(), |
| Bill Wendling | 56cb229 | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 216 | E = Lines.end(); I != E; ++I) |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 217 | I->second->collectLineCounts(FI, I->first(), Counter); |
| 218 | } |
| 219 | |
| Yuchen Wu | 81e3828 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 220 | /// dump - Dump GCOVBlock content to dbgs() for debugging purposes. |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 221 | void GCOVBlock::dump() { |
| Yuchen Wu | 81e3828 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 222 | dbgs() << "Block : " << Number << " Counter : " << Counter << "\n"; |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 223 | if (!Edges.empty()) { |
| Yuchen Wu | 81e3828 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 224 | dbgs() << "\tEdges : "; |
| Craig Topper | 6227d5c | 2013-07-04 01:31:24 +0000 | [diff] [blame] | 225 | for (SmallVectorImpl<uint32_t>::iterator I = Edges.begin(), E = Edges.end(); |
| Bill Wendling | 56cb229 | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 226 | I != E; ++I) |
| Yuchen Wu | 81e3828 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 227 | dbgs() << (*I) << ","; |
| 228 | dbgs() << "\n"; |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 229 | } |
| 230 | if (!Lines.empty()) { |
| Yuchen Wu | 81e3828 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 231 | dbgs() << "\tLines : "; |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 232 | for (StringMap<GCOVLines *>::iterator LI = Lines.begin(), |
| Bill Wendling | 56cb229 | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 233 | LE = Lines.end(); LI != LE; ++LI) { |
| Yuchen Wu | 81e3828 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 234 | dbgs() << LI->first() << " -> "; |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 235 | LI->second->dump(); |
| Yuchen Wu | 81e3828 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 236 | dbgs() << "\n"; |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | //===----------------------------------------------------------------------===// |
| 242 | // GCOVLines implementation. |
| 243 | |
| 244 | /// collectLineCounts - Collect line counts. This must be used after |
| 245 | /// reading .gcno and .gcda files. |
| 246 | void GCOVLines::collectLineCounts(FileInfo &FI, StringRef Filename, |
| Bob Wilson | 51ec77d | 2013-10-22 17:43:47 +0000 | [diff] [blame] | 247 | uint64_t Count) { |
| Craig Topper | 6227d5c | 2013-07-04 01:31:24 +0000 | [diff] [blame] | 248 | for (SmallVectorImpl<uint32_t>::iterator I = Lines.begin(), |
| Bill Wendling | 56cb229 | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 249 | E = Lines.end(); I != E; ++I) |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 250 | FI.addLineCount(Filename, *I, Count); |
| 251 | } |
| 252 | |
| Yuchen Wu | 81e3828 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 253 | /// dump - Dump GCOVLines content to dbgs() for debugging purposes. |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 254 | void GCOVLines::dump() { |
| Craig Topper | 6227d5c | 2013-07-04 01:31:24 +0000 | [diff] [blame] | 255 | for (SmallVectorImpl<uint32_t>::iterator I = Lines.begin(), |
| Bill Wendling | 56cb229 | 2012-07-19 00:11:40 +0000 | [diff] [blame] | 256 | E = Lines.end(); I != E; ++I) |
| Yuchen Wu | 81e3828 | 2013-10-25 02:22:24 +0000 | [diff] [blame] | 257 | dbgs() << (*I) << ","; |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | //===----------------------------------------------------------------------===// |
| 261 | // FileInfo implementation. |
| 262 | |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 263 | /// print - Print source files with collected line count information. |
| Yuchen Wu | daaa8b7 | 2013-11-02 00:09:17 +0000 | [diff] [blame] | 264 | void FileInfo::print(raw_fd_ostream &OS, StringRef gcnoFile, |
| 265 | StringRef gcdaFile) { |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 266 | for (StringMap<LineCounts>::iterator I = LineInfo.begin(), E = LineInfo.end(); |
| 267 | I != E; ++I) { |
| 268 | StringRef Filename = I->first(); |
| Yuchen Wu | f44533c | 2013-11-05 01:56:29 +0000 | [diff] [blame^] | 269 | OS << " -: 0:Source:" << Filename << "\n"; |
| 270 | OS << " -: 0:Graph:" << gcnoFile << "\n"; |
| 271 | OS << " -: 0:Data:" << gcdaFile << "\n"; |
| 272 | OS << " -: 0:Runs:" << RunCount << "\n"; |
| 273 | OS << " -: 0:Programs:" << ProgramCount << "\n"; |
| 274 | LineCounts &L = LineInfo[Filename]; |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 275 | OwningPtr<MemoryBuffer> Buff; |
| 276 | if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) { |
| 277 | errs() << Filename << ": " << ec.message() << "\n"; |
| 278 | return; |
| 279 | } |
| 280 | StringRef AllLines = Buff.take()->getBuffer(); |
| Yuchen Wu | 9db9663 | 2013-10-23 19:45:03 +0000 | [diff] [blame] | 281 | uint32_t i = 0; |
| 282 | while (!AllLines.empty()) { |
| 283 | if (L.find(i) != L.end()) { |
| 284 | if (L[i] == 0) |
| Yuchen Wu | daaa8b7 | 2013-11-02 00:09:17 +0000 | [diff] [blame] | 285 | OS << " #####:"; |
| Yuchen Wu | 9db9663 | 2013-10-23 19:45:03 +0000 | [diff] [blame] | 286 | else |
| Yuchen Wu | daaa8b7 | 2013-11-02 00:09:17 +0000 | [diff] [blame] | 287 | OS << format("%9lu:", L[i]); |
| Yuchen Wu | 9db9663 | 2013-10-23 19:45:03 +0000 | [diff] [blame] | 288 | } else { |
| Yuchen Wu | daaa8b7 | 2013-11-02 00:09:17 +0000 | [diff] [blame] | 289 | OS << " -:"; |
| Yuchen Wu | 9db9663 | 2013-10-23 19:45:03 +0000 | [diff] [blame] | 290 | } |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 291 | std::pair<StringRef, StringRef> P = AllLines.split('\n'); |
| 292 | if (AllLines != P.first) |
| Yuchen Wu | daaa8b7 | 2013-11-02 00:09:17 +0000 | [diff] [blame] | 293 | OS << format("%5u:", i+1) << P.first; |
| 294 | OS << "\n"; |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 295 | AllLines = P.second; |
| Yuchen Wu | 9db9663 | 2013-10-23 19:45:03 +0000 | [diff] [blame] | 296 | ++i; |
| Devang Patel | d02c42b | 2011-09-28 18:50:00 +0000 | [diff] [blame] | 297 | } |
| 298 | } |
| 299 | } |
| 300 | |