From ea36472dcec4e3227cc2113439c7d7168d2623e5 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 13 Dec 2022 08:11:32 +0100 Subject: [PATCH] Perf: FilePathify PerfDataReader Change-Id: I253cfd3724a15d40ef39dafd4f4497ca331ad596 Reviewed-by: Orgad Shaneh Reviewed-by: --- src/plugins/perfprofiler/perfdatareader.cpp | 70 +++++++++++-------- src/plugins/perfprofiler/perfdatareader.h | 14 ++-- .../perfprofiler/perfprofilerruncontrol.cpp | 9 +-- src/plugins/perfprofiler/perfprofilertool.cpp | 6 +- .../perfprofiler/perfprofilertracemanager.cpp | 15 ++-- .../perfprofiler/perfprofilertracemanager.h | 6 +- 6 files changed, 67 insertions(+), 53 deletions(-) diff --git a/src/plugins/perfprofiler/perfdatareader.cpp b/src/plugins/perfprofiler/perfdatareader.cpp index 1351bc40479..0463127a3b3 100644 --- a/src/plugins/perfprofiler/perfdatareader.cpp +++ b/src/plugins/perfprofiler/perfdatareader.cpp @@ -35,6 +35,7 @@ #include using namespace ProjectExplorer; +using namespace Utils; namespace PerfProfiler { namespace Internal { @@ -125,20 +126,25 @@ PerfDataReader::~PerfDataReader() qDeleteAll(m_buffer); } -void PerfDataReader::loadFromFile(const QString &filePath, const QString &executableDirPath, - ProjectExplorer::Kit *kit) +void PerfDataReader::loadFromFile(const FilePath &filePath, const QString &executableDirPath, + Kit *kit) { - createParser(collectArguments(executableDirPath, kit) << QLatin1String("--input") << filePath); + CommandLine cmd{findPerfParser()}; + collectArguments(&cmd, executableDirPath, kit); + cmd.addArg("--input"); + cmd.addArg(filePath.nativePath()); + createParser(cmd); + m_remoteProcessStart = 0; // Don't try to guess the timestamps m_input.start(QIODevice::ReadOnly); } -void PerfDataReader::createParser(const QStringList &arguments) +void PerfDataReader::createParser(const CommandLine &cmd) { clear(); - QString program = findPerfParser(); + const QString program = cmd.executable().path(); m_input.setProgram(program); - m_input.setArguments(arguments); + m_input.setArguments(cmd.splitArguments()); m_input.setWorkingDirectory(QFileInfo(program).dir().absolutePath()); } @@ -269,35 +275,39 @@ bool PerfDataReader::acceptsSamples() const return m_recording; } -QStringList PerfDataReader::collectArguments(const QString &executableDirPath, const Kit *kit) const +void PerfDataReader::collectArguments(CommandLine *cmd, const QString &exe, const Kit *kit) const { - QStringList arguments; - if (!executableDirPath.isEmpty()) - arguments << "--app" << executableDirPath; + if (!exe.isEmpty()) { + cmd->addArg("--app"); + cmd->addArg(exe); + } if (QtSupport::QtVersion *qt = QtSupport::QtKitAspect::qtVersion(kit)) { - arguments << "--extra" << QString("%1%5%2%5%3%5%4") - .arg(QDir::toNativeSeparators(qt->libraryPath().toString())) - .arg(QDir::toNativeSeparators(qt->pluginPath().toString())) - .arg(QDir::toNativeSeparators(qt->hostBinPath().toString())) - .arg(QDir::toNativeSeparators(qt->qmlPath().toString())) - .arg(QDir::listSeparator()); + cmd->addArg("--extra"); + cmd->addArg(QString("%1%5%2%5%3%5%4") + .arg(qt->libraryPath().nativePath()) + .arg(qt->pluginPath().nativePath()) + .arg(qt->hostBinPath().nativePath()) + .arg(qt->qmlPath().nativePath()) + .arg(cmd->executable().osType() == OsTypeWindows ? u';' : u':')); } if (auto toolChain = ToolChainKitAspect::cxxToolChain(kit)) { Abi::Architecture architecture = toolChain->targetAbi().architecture(); if (architecture == Abi::ArmArchitecture && toolChain->targetAbi().wordWidth() == 64) { - arguments << "--arch" << "aarch64"; + cmd->addArg("--arch"); + cmd->addArg("aarch64"); } else if (architecture != Abi::UnknownArchitecture) { - arguments << "--arch" << Abi::toString(architecture); + cmd->addArg("--arch"); + cmd->addArg(Abi::toString(architecture)); } } - QString sysroot = SysRootKitAspect::sysRoot(kit).toString(); - if (!sysroot.isEmpty()) - arguments << "--sysroot" << sysroot; - - return arguments; + const FilePath sysroot = SysRootKitAspect::sysRoot(kit); + if (!sysroot.isEmpty()) { + cmd->addArg("--sysroot"); + cmd->addArg(sysroot.nativePath()); + } } static bool checkedWrite(QIODevice *device, const QByteArray &input) @@ -372,21 +382,21 @@ bool PerfDataReader::feedParser(const QByteArray &input) return true; } -QStringList PerfDataReader::findTargetArguments(const ProjectExplorer::RunControl *runControl) const +void PerfDataReader::addTargetArguments(CommandLine *cmd, const RunControl *runControl) const { ProjectExplorer::Kit *kit = runControl->kit(); - QTC_ASSERT(kit, return QStringList()); + QTC_ASSERT(kit, return); ProjectExplorer::BuildConfiguration *buildConfig = runControl->target()->activeBuildConfiguration(); QString buildDir = buildConfig ? buildConfig->buildDirectory().toString() : QString(); - return collectArguments(buildDir, kit); + collectArguments(cmd, buildDir, kit); } -QString PerfDataReader::findPerfParser() +FilePath findPerfParser() { - QString filePath = Utils::qtcEnvironmentVariable("PERFPROFILER_PARSER_FILEPATH"); + FilePath filePath = FilePath::fromUserInput(qtcEnvironmentVariable("PERFPROFILER_PARSER_FILEPATH")); if (filePath.isEmpty()) - filePath = Core::ICore::libexecPath("perfparser" QTC_HOST_EXE_SUFFIX).toString(); - return QDir::toNativeSeparators(QDir::cleanPath(filePath)); + filePath = Core::ICore::libexecPath("perfparser" QTC_HOST_EXE_SUFFIX); + return filePath; } } // namespace Internal diff --git a/src/plugins/perfprofiler/perfdatareader.h b/src/plugins/perfprofiler/perfdatareader.h index e135c28b4ab..8dc70cdc22b 100644 --- a/src/plugins/perfprofiler/perfdatareader.h +++ b/src/plugins/perfprofiler/perfdatareader.h @@ -19,6 +19,8 @@ class RunControl; namespace PerfProfiler { namespace Internal { +Utils::FilePath findPerfParser(); + class PerfDataReader : public PerfProfilerTraceFile { Q_OBJECT @@ -26,14 +28,14 @@ public: explicit PerfDataReader(QObject *parent = nullptr); ~PerfDataReader() override; - void loadFromFile(const QString &filePath, const QString &executableDirPath, + void loadFromFile(const Utils::FilePath &filePath, const QString &executableDirPath, ProjectExplorer::Kit *kit); - void createParser(const QStringList &arguments); + void createParser(const Utils::CommandLine &arguments); void startParser(); void stopParser(); - QStringList findTargetArguments(const ProjectExplorer::RunControl *runControl) const; + void addTargetArguments(Utils::CommandLine *cmd, const ProjectExplorer::RunControl *runControl) const; void clear(); bool feedParser(const QByteArray &input); @@ -63,8 +65,9 @@ protected: private: static const int s_maxBufferSize = 1 << 29; - QStringList collectArguments(const QString &executableDirPath, - const ProjectExplorer::Kit *kit) const; + void collectArguments(Utils::CommandLine *cmd, + const QString &executableDirPath, + const ProjectExplorer::Kit *kit) const; void writeChunk(); bool m_recording; @@ -77,7 +80,6 @@ private: qint64 m_remoteProcessStart; qint64 m_lastRemoteTimestamp; - static QString findPerfParser(); qint64 delay(qint64 currentTime); }; diff --git a/src/plugins/perfprofiler/perfprofilerruncontrol.cpp b/src/plugins/perfprofiler/perfprofilerruncontrol.cpp index a5873dcfc50..b558aaa8bad 100644 --- a/src/plugins/perfprofiler/perfprofilerruncontrol.cpp +++ b/src/plugins/perfprofiler/perfprofilerruncontrol.cpp @@ -60,13 +60,14 @@ public: void start() override { - QStringList args = m_reader.findTargetArguments(runControl()); + CommandLine cmd{findPerfParser()}; + m_reader.addTargetArguments(&cmd, runControl()); QUrl url = runControl()->property("PerfConnection").toUrl(); if (url.isValid()) { - args.append(QStringList{"--host", url.host(), "--port", QString::number(url.port())}); + cmd.addArgs({"--host", url.host(), "--port", QString::number(url.port())}); } - appendMessage("PerfParser args: " + args.join(' '), Utils::NormalMessageFormat); - m_reader.createParser(args); + appendMessage("PerfParser args: " + cmd.arguments(), NormalMessageFormat); + m_reader.createParser(cmd); m_reader.startParser(); } diff --git a/src/plugins/perfprofiler/perfprofilertool.cpp b/src/plugins/perfprofiler/perfprofilertool.cpp index 07aee796d73..a869723bfa1 100644 --- a/src/plugins/perfprofiler/perfprofilertool.cpp +++ b/src/plugins/perfprofiler/perfprofilertool.cpp @@ -593,7 +593,7 @@ void PerfProfilerTool::showLoadPerfDialog() m_fileFinder.setAdditionalSearchDirectories(collectQtIncludePaths(kit)); m_fileFinder.setSysroot(sysroot(kit)); m_fileFinder.setProjectFiles(sourceFiles()); - m_traceManager->loadFromPerfData(dlg.traceFilePath(), dlg.executableDirPath(), kit); + m_traceManager->loadFromPerfData(FilePath::fromUserInput(dlg.traceFilePath()), dlg.executableDirPath(), kit); } void PerfProfilerTool::showLoadTraceDialog() @@ -612,7 +612,7 @@ void PerfProfilerTool::showLoadTraceDialog() const Kit *kit = target ? target->kit() : nullptr; populateFileFinder(currentProject, kit); - m_traceManager->loadFromTraceFile(filePath.toString()); + m_traceManager->loadFromTraceFile(filePath); } void PerfProfilerTool::showSaveTraceDialog() @@ -627,7 +627,7 @@ void PerfProfilerTool::showSaveTraceDialog() filePath = filePath.stringAppended(".ptq"); setToolActionsEnabled(false); - m_traceManager->saveToTraceFile(filePath.toString()); + m_traceManager->saveToTraceFile(filePath); } void PerfProfilerTool::setAggregated(bool aggregated) diff --git a/src/plugins/perfprofiler/perfprofilertracemanager.cpp b/src/plugins/perfprofiler/perfprofilertracemanager.cpp index 847ac1c4ec6..d5bc205645b 100644 --- a/src/plugins/perfprofiler/perfprofilertracemanager.cpp +++ b/src/plugins/perfprofiler/perfprofilertracemanager.cpp @@ -12,9 +12,10 @@ #include -#include #include +using namespace Utils; + namespace PerfProfiler { namespace Internal { @@ -575,19 +576,19 @@ qint32 PerfProfilerTraceManager::symbolLocation(qint32 locationId) const return symbol(locationId).name != -1 ? locationId : location(locationId).parentLocationId; } -void PerfProfilerTraceManager::loadFromTraceFile(const QString &filePath) +void PerfProfilerTraceManager::loadFromTraceFile(const FilePath &filePath) { - Core::ProgressManager::addTask(load(filePath), Tr::tr("Loading Trace Data"), + Core::ProgressManager::addTask(load(filePath.toFSPathString()), Tr::tr("Loading Trace Data"), Constants::PerfProfilerTaskLoadTrace); } -void PerfProfilerTraceManager::saveToTraceFile(const QString &filePath) +void PerfProfilerTraceManager::saveToTraceFile(const FilePath &filePath) { - Core::ProgressManager::addTask(save(filePath), Tr::tr("Saving Trace Data"), + Core::ProgressManager::addTask(save(filePath.toFSPathString()), Tr::tr("Saving Trace Data"), Constants::PerfProfilerTaskSaveTrace); } -void PerfProfilerTraceManager::loadFromPerfData(const QString &filePath, +void PerfProfilerTraceManager::loadFromPerfData(const FilePath &filePath, const QString &executableDirPath, ProjectExplorer::Kit *kit) { @@ -604,7 +605,7 @@ void PerfProfilerTraceManager::loadFromPerfData(const QString &filePath, connect(reader, &QObject::destroyed, this, &TimelineTraceManager::loadFinished); const int fileMegabytes = static_cast( - qMin(QFileInfo(filePath).size() >> 20, + qMin(filePath.fileSize() >> 20, static_cast(std::numeric_limits::max()))); Core::FutureProgress *fp = Core::ProgressManager::addTimedTask( reader->future(), Tr::tr("Loading Trace Data"), Constants::PerfProfilerTaskLoadPerf, diff --git a/src/plugins/perfprofiler/perfprofilertracemanager.h b/src/plugins/perfprofiler/perfprofilertracemanager.h index 528c44174bb..303af9f5e5a 100644 --- a/src/plugins/perfprofiler/perfprofilertracemanager.h +++ b/src/plugins/perfprofiler/perfprofilertracemanager.h @@ -139,9 +139,9 @@ public: const QHash &tracePoints() const { return m_tracePoints; } const QHash &threads() const { return m_threads; } - void loadFromTraceFile(const QString &filePath); - void saveToTraceFile(const QString &filePath); - void loadFromPerfData(const QString &filePath, const QString &executableDirPath, + void loadFromTraceFile(const Utils::FilePath &filePath); + void saveToTraceFile(const Utils::FilePath &filePath); + void loadFromPerfData(const Utils::FilePath &filePath, const QString &executableDirPath, ProjectExplorer::Kit *kit); void finalize() override;