[llvm] r236558 - InstrProf: Strip filename prefixes from the names we display for coverage
Justin Bogner
mail at justinbogner.com
Tue May 5 16:44:48 PDT 2015
Author: bogner
Date: Tue May 5 18:44:48 2015
New Revision: 236558
URL: http://llvm.org/viewvc/llvm-project?rev=236558&view=rev
Log:
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.
Modified:
llvm/trunk/lib/ProfileData/CoverageMapping.cpp
llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp
Modified: llvm/trunk/lib/ProfileData/CoverageMapping.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/CoverageMapping.cpp?rev=236558&r1=236557&r2=236558&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/CoverageMapping.cpp (original)
+++ llvm/trunk/lib/ProfileData/CoverageMapping.cpp Tue May 5 18:44:48 2015
@@ -20,6 +20,7 @@
#include "llvm/ProfileData/InstrProfReader.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
@@ -178,6 +179,18 @@ void FunctionRecordIterator::skipOtherFi
*this = FunctionRecordIterator();
}
+/// Get the function name from the record, removing the filename prefix if
+/// necessary.
+static StringRef getFuncNameWithoutPrefix(const CoverageMappingRecord &Record) {
+ StringRef FunctionName = Record.FunctionName;
+ if (Record.Filenames.empty())
+ return FunctionName;
+ StringRef Filename = sys::path::filename(Record.Filenames[0]);
+ if (FunctionName.startswith(Filename))
+ FunctionName = FunctionName.drop_front(Filename.size() + 1);
+ return FunctionName;
+}
+
ErrorOr<std::unique_ptr<CoverageMapping>>
CoverageMapping::load(CoverageMappingReader &CoverageReader,
IndexedInstrProfReader &ProfileReader) {
@@ -199,7 +212,8 @@ CoverageMapping::load(CoverageMappingRea
Ctx.setCounts(Counts);
assert(!Record.MappingRegions.empty() && "Function has no regions");
- FunctionRecord Function(Record.FunctionName, Record.Filenames);
+
+ FunctionRecord Function(getFuncNameWithoutPrefix(Record), Record.Filenames);
for (const auto &Region : Record.MappingRegions) {
ErrorOr<int64_t> ExecutionCount = Ctx.evaluate(Region.Count);
if (!ExecutionCount)
Modified: llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp?rev=236558&r1=236557&r2=236558&view=diff
==============================================================================
--- llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp (original)
+++ llvm/trunk/unittests/ProfileData/CoverageMappingTest.cpp Tue May 5 18:44:48 2015
@@ -259,4 +259,18 @@ TEST_F(CoverageMappingTest, dont_combine
ASSERT_EQ(CoverageSegment(9, 9, false), Segments[3]);
}
+TEST_F(CoverageMappingTest, strip_filename_prefix) {
+ ProfileWriter.addFunctionCounts("file1:func", 0x1234, {10});
+ readProfCounts();
+
+ addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
+ loadCoverageMapping("file1:func", 0x1234);
+
+ std::vector<std::string> Names;
+ for (const auto &Func : LoadedCoverage->getCoveredFunctions())
+ Names.push_back(Func.Name);
+ ASSERT_EQ(1U, Names.size());
+ ASSERT_EQ("func", Names[0]);
+}
+
} // end anonymous namespace
More information about the llvm-commits
mailing list