From 4bcf805e84857187af43ba7502bb1c9cbdc7cfc1 Mon Sep 17 00:00:00 2001 From: Lieven Hey Date: Tue, 17 Sep 2024 13:22:51 +0200 Subject: [PATCH] feat: open more perf files Currently `hotspot dir` only opens perf.data files. This patch extends this to perf.data, perf.data.old and perf.data.perfparser files. --- src/main.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 58e46ca8..a278b474 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -236,7 +236,15 @@ 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 + for (const auto& perfDataFile : {QStringLiteral("/perf.data"), QStringLiteral("/perf.data.old"), + QStringLiteral("/perf.data.perfparser")}) { + if (QFileInfo::exists(file + perfDataFile)) { + file.append(perfDataFile); + break; + } + } } if (parser.isSet(exportTo)) { @@ -267,9 +275,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); + for (const auto& perfDataFile : + {QStringLiteral("perf.data"), QStringLiteral("perf.data.old"), QStringLiteral("perf.data.perfparser")}) { + if (QFileInfo::exists(perfDataFile) && window) { + window->openFile(perfDataFile); + break; + } } } if (window)