Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve file lookup time #34

Merged
merged 1 commit into from
Jan 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions app/perfsymboltable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,23 @@ PerfSymbolTable::~PerfSymbolTable()
dwfl_end(m_dwfl);
}

static bool findInExtraPath(QFileInfo &path, const QString &fileName)
static bool findInExtraPath(QFileInfo &path, const QString &fileName, QSet<QString> &checkedCanonicalPaths)
{
path.setFile(path.absoluteFilePath() + QDir::separator() + fileName);
if (path.isFile())
return true;

QString canonicalPath = path.canonicalFilePath();
if (checkedCanonicalPaths.contains(canonicalPath))
return false;

checkedCanonicalPaths.insert(canonicalPath);
const QDir absDir = path.absoluteDir();

const auto entries = absDir.entryList({}, QDir::Dirs | QDir::NoDotAndDotDot);
for (const QString &entry : entries) {
path.setFile(absDir, entry);
if (findInExtraPath(path, fileName))
if (findInExtraPath(path, fileName, checkedCanonicalPaths))
return true;
}
return false;
Expand Down Expand Up @@ -170,11 +176,19 @@ QFileInfo PerfSymbolTable::findFile(const QString& path, const QString &fileName
return fullPath;
}
}

// we want to ensure to not check a path twice (overlap of appPath and extraPath,
// recursive symlinks like /usr/bin/X11 as seen in Debian/Ubuntu, ...) so we store
// the canonical visited paths for each library during the lookup
QSet<QString> checkedCanonicalPaths;
milianw marked this conversation as resolved.
Show resolved Hide resolved

// reserve an arbitrary small number to remove the first few reallocations and rehashes
checkedCanonicalPaths.reserve(16);

if (!m_unwind->appPath().isEmpty()) {
// try to find the file in the app path
fullPath.setFile(m_unwind->appPath());
if (findInExtraPath(fullPath, fileName) && matchesBuildId(buildId, fullPath)) {
if (findInExtraPath(fullPath, fileName, checkedCanonicalPaths) && matchesBuildId(buildId, fullPath)) {
return fullPath;
}
}
Expand All @@ -183,7 +197,7 @@ QFileInfo PerfSymbolTable::findFile(const QString& path, const QString &fileName
const auto extraPaths = splitPath(m_unwind->extraLibsPath());
for (const QString &extraPath : extraPaths) {
fullPath.setFile(extraPath);
if (findInExtraPath(fullPath, fileName) && matchesBuildId(buildId, fullPath)) {
if (findInExtraPath(fullPath, fileName, checkedCanonicalPaths) && matchesBuildId(buildId, fullPath)) {
return fullPath;
}
}
Expand Down