Skip to content

Commit

Permalink
move unwind settings from mainwindow to settings
Browse files Browse the repository at this point in the history
this makes it possible for other perfparser instances to parse files
  • Loading branch information
lievenhey committed Nov 5, 2021
1 parent 7c69604 commit 9a136cc
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 92 deletions.
20 changes: 11 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "hotspot-config.h"
#include "mainwindow.h"
#include "models/data.h"
#include "settings.h"
#include "util.h"

#include <ThreadWeaver/ThreadWeaver>
Expand Down Expand Up @@ -157,38 +158,39 @@ int main(int argc, char** argv)

ThreadWeaver::Queue::instance()->setMaximumNumberOfThreads(QThread::idealThreadCount());

auto applyCliArgs = [&](MainWindow* window) {
auto applyCliArgs = [&](Settings* settings) {
if (parser.isSet(sysroot)) {
window->setSysroot(parser.value(sysroot));
settings->setSysroot(parser.value(sysroot));
}
if (parser.isSet(kallsyms)) {
window->setKallsyms(parser.value(kallsyms));
settings->setKallsyms(parser.value(kallsyms));
}
if (parser.isSet(debugPaths)) {
window->setDebugPaths(parser.value(debugPaths));
settings->setDebugPaths(parser.value(debugPaths));
}
if (parser.isSet(extraLibPaths)) {
window->setExtraLibPaths(parser.value(extraLibPaths));
settings->setExtraLibPaths(parser.value(extraLibPaths));
}
if (parser.isSet(appPath)) {
window->setAppPath(parser.value(appPath));
settings->setAppPath(parser.value(appPath));
}
if (parser.isSet(arch)) {
window->setArch(parser.value(arch));
settings->setArch(parser.value(arch));
}
};

const auto settings = Settings::instance();
for (const auto& file : parser.positionalArguments()) {
auto window = new MainWindow;
applyCliArgs(window);
applyCliArgs(settings);
window->openFile(file);
window->show();
}

// show at least one mainwindow
if (parser.positionalArguments().isEmpty()) {
auto window = new MainWindow;
applyCliArgs(window);
applyCliArgs(Settings::instance());

// open perf.data in current CWD, if it exists
// this brings hotspot closer to the behavior of "perf report"
Expand Down
84 changes: 23 additions & 61 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,21 @@ MainWindow::MainWindow(QWidget* parent)
layout->addWidget(m_pageStack);
centralWidget()->setLayout(layout);

connect(m_settingsDialog, &QDialog::accepted, this, [this]() {
setSysroot(m_settingsDialog->sysroot());
setAppPath(m_settingsDialog->appPath());
setExtraLibPaths(m_settingsDialog->extraLibPaths());
setDebugPaths(m_settingsDialog->debugPaths());
setKallsyms(m_settingsDialog->kallsyms());
setArch(m_settingsDialog->arch());
setObjdump(m_settingsDialog->objdump());
auto settings = Settings::instance();

connect(m_settingsDialog, &QDialog::accepted, this, [this, settings]() {
settings->setSysroot(m_settingsDialog->sysroot());
settings->setAppPath(m_settingsDialog->appPath());
settings->setExtraLibPaths(m_settingsDialog->extraLibPaths());
settings->setDebugPaths(m_settingsDialog->debugPaths());
settings->setKallsyms(m_settingsDialog->kallsyms());
settings->setArch(m_settingsDialog->arch());
settings->setObjdump(m_settingsDialog->objdump());
});

connect(this, &MainWindow::sysrootChanged, m_resultsPage, &ResultsPage::setSysroot);
connect(this, &MainWindow::appPathChanged, m_resultsPage, &ResultsPage::setAppPath);
connect(this, &MainWindow::objdumpChanged, m_resultsPage, &ResultsPage::setObjdump);
connect(settings, &Settings::sysrootChanged, m_resultsPage, &ResultsPage::setSysroot);
connect(settings, &Settings::appPathChanged, m_resultsPage, &ResultsPage::setAppPath);
connect(settings, &Settings::objdumpChanged, m_resultsPage, &ResultsPage::setObjdump);
connect(m_startPage, &StartPage::pathSettingsButtonClicked, this, &MainWindow::openSettingsDialog);

connect(m_startPage, &StartPage::openFileButtonClicked, this, &MainWindow::onOpenFileButtonClicked);
Expand Down Expand Up @@ -292,13 +294,13 @@ MainWindow::MainWindow(QWidget* parent)
m_lastUsedSettings = m_config->group("PerfPaths").readEntry("lastUsed");
if (!m_lastUsedSettings.isEmpty()) {
auto currentConfig = m_config->group("PerfPaths").group(m_lastUsedSettings);
setSysroot(currentConfig.readEntry("sysroot", ""));
setAppPath(currentConfig.readEntry("appPath", ""));
setExtraLibPaths(currentConfig.readEntry("extraLibPaths", ""));
setDebugPaths(currentConfig.readEntry("debugPaths", ""));
setKallsyms(currentConfig.readEntry("kallsyms", ""));
setArch(currentConfig.readEntry("arch", ""));
setObjdump(currentConfig.readEntry("objdump", ""));
settings->setSysroot(currentConfig.readEntry("sysroot", ""));
settings->setAppPath(currentConfig.readEntry("appPath", ""));
settings->setExtraLibPaths(currentConfig.readEntry("extraLibPaths", ""));
settings->setDebugPaths(currentConfig.readEntry("debugPaths", ""));
settings->setKallsyms(currentConfig.readEntry("kallsyms", ""));
settings->setArch(currentConfig.readEntry("arch", ""));
settings->setObjdump(currentConfig.readEntry("objdump", ""));
}
}

Expand All @@ -316,48 +318,6 @@ void MainWindow::closeEvent(QCloseEvent* event)
QMainWindow::closeEvent(event);
}

void MainWindow::setSysroot(const QString& path)
{
m_sysroot = path.trimmed();
emit sysrootChanged(m_sysroot);
}

void MainWindow::setKallsyms(const QString& path)
{
m_kallsyms = path;
emit kallsymsChanged(m_kallsyms);
}

void MainWindow::setDebugPaths(const QString& paths)
{
m_debugPaths = paths;
emit debugPathsChanged(m_debugPaths);
}

void MainWindow::setExtraLibPaths(const QString& paths)
{
m_extraLibPaths = paths;
emit extraLibPathsChanged(m_extraLibPaths);
}

void MainWindow::setAppPath(const QString& path)
{
m_appPath = path;
emit appPathChanged(m_appPath);
}

void MainWindow::setArch(const QString& arch)
{
m_arch = arch;
emit archChanged(m_arch);
}

void MainWindow::setObjdump(const QString& objdump)
{
m_objdump = objdump;
emit objdumpChanged(m_objdump);
}

void MainWindow::onOpenFileButtonClicked()
{
const auto fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath(),
Expand Down Expand Up @@ -414,7 +374,9 @@ void MainWindow::openFile(const QString& path, bool isReload)
m_pageStack->setCurrentWidget(m_startPage);

// TODO: support input files of different types via plugins
m_parser->startParseFile(path, m_sysroot, m_kallsyms, m_debugPaths, m_extraLibPaths, m_appPath, m_arch);
auto settings = Settings::instance();
m_parser->startParseFile(path, settings->sysroot(), settings->kallsyms(), settings->debugPaths(),
settings->extraLibPaths(), settings->appPath(), settings->arch());
m_reloadAction->setData(path);
m_exportAction->setData(QUrl::fromLocalFile(file.absoluteFilePath() + QLatin1String(".perfparser")));

Expand Down
22 changes: 0 additions & 22 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ class MainWindow : public KParts::MainWindow
~MainWindow();

public slots:
void setSysroot(const QString& path);
void setKallsyms(const QString& path);
void setDebugPaths(const QString& paths);
void setExtraLibPaths(const QString& paths);
void setAppPath(const QString& path);
void setArch(const QString& arch);
void setObjdump(const QString& objdump);

void clear();
void openFile(const QString& path);
void openFile(const QUrl& url);
Expand All @@ -83,13 +75,6 @@ public slots:

signals:
void openFileError(const QString& errorMessage);
void sysrootChanged(const QString& path);
void kallsymsChanged(const QString& path);
void debugPathsChanged(const QString& paths);
void extraLibPathsChanged(const QString& paths);
void appPathChanged(const QString& path);
void archChanged(const QString& arch);
void objdumpChanged(const QString& objdump);

private:
void clear(bool isReload);
Expand All @@ -106,13 +91,6 @@ public slots:
ResultsPage* m_resultsPage;
SettingsDialog* m_settingsDialog;

QString m_sysroot;
QString m_kallsyms;
QString m_debugPaths;
QString m_extraLibPaths;
QString m_appPath;
QString m_arch;
QString m_objdump;
QString m_lastUsedSettings;
KRecentFilesAction* m_recentFilesAction = nullptr;
QAction* m_reloadAction = nullptr;
Expand Down
42 changes: 42 additions & 0 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,45 @@ void Settings::setDebuginfodUrls(const QStringList& urls)
emit debuginfodUrlsChanged();
}
}

void Settings::setSysroot(const QString& path)
{
m_sysroot = path.trimmed();
emit sysrootChanged(m_sysroot);
}

void Settings::setKallsyms(const QString& path)
{
m_kallsyms = path;
emit kallsymsChanged(m_kallsyms);
}

void Settings::setDebugPaths(const QString& paths)
{
m_debugPaths = paths;
emit debugPathsChanged(m_debugPaths);
}

void Settings::setExtraLibPaths(const QString& paths)
{
m_extraLibPaths = paths;
emit extraLibPathsChanged(m_extraLibPaths);
}

void Settings::setAppPath(const QString& path)
{
m_appPath = path;
emit appPathChanged(m_appPath);
}

void Settings::setArch(const QString& arch)
{
m_arch = arch;
emit archChanged(m_arch);
}

void Settings::setObjdump(const QString& objdump)
{
m_objdump = objdump;
emit objdumpChanged(m_objdump);
}
57 changes: 57 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,55 @@ class Settings : public QObject
return m_debuginfodUrls;
}

QString sysroot() const
{
return m_sysroot;
}

QString kallsyms() const
{
return m_kallsyms;
}

QString debugPaths() const
{
return m_debugPaths;
}

QString extraLibPaths() const
{
return m_extraLibPaths;
}

QString appPath() const
{
return m_appPath;
}

QString arch() const
{
return m_arch;
}

QString objdump() const
{
return m_objdump;
}

signals:
void prettifySymbolsChanged(bool);
void collapseTemplatesChanged(bool);
void collapseDepthChanged(int);
void colorSchemeChanged(ColorScheme);
void pathsChanged();
void debuginfodUrlsChanged();
void sysrootChanged(const QString& path);
void kallsymsChanged(const QString& path);
void debugPathsChanged(const QString& paths);
void extraLibPathsChanged(const QString& paths);
void appPathChanged(const QString& path);
void archChanged(const QString& arch);
void objdumpChanged(const QString& objdump);

public slots:
void setPrettifySymbols(bool prettifySymbols);
Expand All @@ -91,6 +133,13 @@ public slots:
void setColorScheme(ColorScheme scheme);
void setPaths(const QStringList& userPaths, const QStringList& systemPaths);
void setDebuginfodUrls(const QStringList& urls);
void setSysroot(const QString& path);
void setKallsyms(const QString& path);
void setDebugPaths(const QString& paths);
void setExtraLibPaths(const QString& paths);
void setAppPath(const QString& path);
void setArch(const QString& arch);
void setObjdump(const QString& objdump);

private:
Settings() = default;
Expand All @@ -103,4 +152,12 @@ public slots:
QStringList m_userPaths;
QStringList m_systemPaths;
QStringList m_debuginfodUrls;

QString m_sysroot;
QString m_kallsyms;
QString m_debugPaths;
QString m_extraLibPaths;
QString m_appPath;
QString m_arch;
QString m_objdump;
};

0 comments on commit 9a136cc

Please sign in to comment.