[PATCH] D97061: [llvm-cov] Compare path only to find the same file
Choongwoo Han via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 19 09:15:33 PST 2021
tunz created this revision.
tunz added reviewers: vsk, phosek, zequanwu.
tunz requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Currently, getSourceFile accesses file system to
check if two paths are the same file with a thread
lock, which is a huge performance bottleneck in some
cases.
Thus, if -ignore-symlinks option is given, let it
check only path strings after path normalization
so that we can avoid file system accesses.
When I tested it with two binaries and 16 cpu cores,
it saved over 70% of time.
Binary 1: 56 secs -> 3 secs
Binary 2: 17 hours -> 4 hours
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D97061
Files:
llvm/tools/llvm-cov/CodeCoverage.cpp
Index: llvm/tools/llvm-cov/CodeCoverage.cpp
===================================================================
--- llvm/tools/llvm-cov/CodeCoverage.cpp
+++ llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -135,6 +135,7 @@
CoverageViewOptions ViewOpts;
CoverageFiltersMatchAll Filters;
CoverageFilters IgnoreFilenameFilters;
+ bool ComparePathStringOnly = false;
/// True if InputSourceFiles are provided.
bool HadSourceFiles = false;
@@ -248,9 +249,22 @@
if (Loc != RemappedFilenames.end())
SourceFile = Loc->second;
}
- for (const auto &Files : LoadedSourceFiles)
- if (sys::fs::equivalent(SourceFile, Files.first))
- return *Files.second;
+
+ SmallString<256> NormalizedPath;
+ sys::path::native(SourceFile, NormalizedPath);
+ sys::path::remove_dots(NormalizedPath, true);
+ SourceFile = NormalizedPath;
+
+ if (ComparePathStringOnly) {
+ for (const auto &Files : LoadedSourceFiles)
+ if (SourceFile == Files.first)
+ return *Files.second;
+ } else {
+ for (const auto &Files : LoadedSourceFiles)
+ if (sys::fs::equivalent(SourceFile, Files.first))
+ return *Files.second;
+ }
+
auto Buffer = MemoryBuffer::getFile(SourceFile);
if (auto EC = Buffer.getError()) {
error(EC.message(), SourceFile);
@@ -654,6 +668,12 @@
"regular expression"),
cl::ZeroOrMore, cl::cat(FilteringCategory));
+ cl::opt<bool> IgnoreSymlinks(
+ "ignore-symlinks", cl::Optional,
+ cl::desc("Do not follow symlinks to check file equivalence. "
+ "Use only normalized path strings to find the same file."),
+ cl::init(false));
+
cl::opt<double> RegionCoverageLtFilter(
"region-coverage-lt", cl::Optional,
cl::desc("Show code coverage only for functions with region coverage "
@@ -838,6 +858,7 @@
::exit(0);
}
+ ComparePathStringOnly = IgnoreSymlinks;
ViewOpts.ShowBranchSummary = BranchSummary;
ViewOpts.ShowRegionSummary = RegionSummary;
ViewOpts.ShowInstantiationSummary = InstantiationSummary;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97061.325009.patch
Type: text/x-patch
Size: 2056 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210219/5d094bcf/attachment.bin>
More information about the llvm-commits
mailing list