llvm.org GIT mirror llvm / 730ddb6
InstrProf: Strip filename prefixes from the names we display for coverage For consumers of coverage data, any filename prefixes we store in the profile data are just noise. Strip this prefix if it exists. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236558 91177308-0d34-0410-b5e6-96231b3b80d8 Justin Bogner 4 years ago
2 changed file(s) with 29 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
1919 #include "llvm/ProfileData/InstrProfReader.h"
2020 #include "llvm/Support/Debug.h"
2121 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/Path.h"
2223 #include "llvm/Support/raw_ostream.h"
2324
2425 using namespace llvm;
177178 *this = FunctionRecordIterator();
178179 }
179180
181 /// Get the function name from the record, removing the filename prefix if
182 /// necessary.
183 static StringRef getFuncNameWithoutPrefix(const CoverageMappingRecord &Record) {
184 StringRef FunctionName = Record.FunctionName;
185 if (Record.Filenames.empty())
186 return FunctionName;
187 StringRef Filename = sys::path::filename(Record.Filenames[0]);
188 if (FunctionName.startswith(Filename))
189 FunctionName = FunctionName.drop_front(Filename.size() + 1);
190 return FunctionName;
191 }
192
180193 ErrorOr>
181194 CoverageMapping::load(CoverageMappingReader &CoverageReader,
182195 IndexedInstrProfReader &ProfileReader) {
198211 Ctx.setCounts(Counts);
199212
200213 assert(!Record.MappingRegions.empty() && "Function has no regions");
201 FunctionRecord Function(Record.FunctionName, Record.Filenames);
214
215 FunctionRecord Function(getFuncNameWithoutPrefix(Record), Record.Filenames);
202216 for (const auto &Region : Record.MappingRegions) {
203217 ErrorOr ExecutionCount = Ctx.evaluate(Region.Count);
204218 if (!ExecutionCount)
258258 ASSERT_EQ(CoverageSegment(9, 9, false), Segments[3]);
259259 }
260260
261 TEST_F(CoverageMappingTest, strip_filename_prefix) {
262 ProfileWriter.addFunctionCounts("file1:func", 0x1234, {10});
263 readProfCounts();
264
265 addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
266 loadCoverageMapping("file1:func", 0x1234);
267
268 std::vector Names;
269 for (const auto &Func : LoadedCoverage->getCoveredFunctions())
270 Names.push_back(Func.Name);
271 ASSERT_EQ(1U, Names.size());
272 ASSERT_EQ("func", Names[0]);
273 }
274
261275 } // end anonymous namespace