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

feat: detect more perf data file types in directory #677

Merged
merged 1 commit into from
Oct 7, 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
30 changes: 26 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ void Q_DECL_UNUSED initRCCIconTheme()
}
#endif

namespace {
QStringList findPerfDataFiles(const QDir& directory = QDir::current())
{
QStringList files;

for (const auto& filename : {QStringLiteral("perf.data"), QStringLiteral("perf.data.perfparser")}) {
if (directory.exists(filename)) {
files.push_back(directory.absoluteFilePath(filename));
}
}
return files;
}
}

std::unique_ptr<QCoreApplication> createApplication(int& argc, char* argv[])
{
const std::initializer_list<std::string_view> nonGUIOptions = {"--version", "-v", "--exportTo",
Expand Down Expand Up @@ -236,7 +250,12 @@ int main(int argc, char** argv)
if (!files.isEmpty()) {
auto file = files.constFirst();
if (QFileInfo(file).isDir()) {
file.append(QLatin1String("/perf.data"));
// search for common perf data files in dir and open the first one found
// if none is found, hotspot will complain, that `file` is not a file
const auto perfDataFiles = findPerfDataFiles(QDir(file));
if (!perfDataFiles.isEmpty()) {
file = perfDataFiles.first();
}
}

if (parser.isSet(exportTo)) {
Expand Down Expand Up @@ -267,9 +286,12 @@ int main(int argc, char** argv)
} else {
// open perf.data in current CWD, if it exists
// this brings hotspot closer to the behavior of "perf report"
const auto perfDataFile = QStringLiteral("perf.data");
if (QFile::exists(perfDataFile) && window) {
window->openFile(perfDataFile);
const auto perfDataFiles = findPerfDataFiles();
for (const auto& perfDataFile : perfDataFiles) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perf report opens only a single file and I have lots of perf files in my directories...
I suggest to add either an optional integer limit or boolean newestFileOnly attribute to that function and use it here and above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the loop breaks after the first opened file, so this is fine as-is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory this means that the caller may collect lots of file entries, just to drop all of those later.
That's not of a big issue currently as findPerfDataFiles() does not match our file open window (which I think it should, I'm creating a new issue to track it).

if (window) {
window->openFile(perfDataFile);
break;
}
}
}
if (window)
Expand Down