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: allow user to specify perf and objdump via command line #653

Merged
merged 2 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ int main(int argc, char** argv)
QStringLiteral("path"));
parser.addOption(exportTo);

const auto perfBinary =
QCommandLineOption(QStringLiteral("perf-binary"),
QCoreApplication::translate("main", "Path to the perf binary."), QStringLiteral("path"));
parser.addOption(perfBinary);

const auto objdumpBinary =
QCommandLineOption(QStringLiteral("objdump-binary"),
QCoreApplication::translate("main", "Path to the objdump binary."), QStringLiteral("path"));
parser.addOption(objdumpBinary);

parser.addPositionalArgument(
QStringLiteral("files"),
QCoreApplication::translate("main", "Optional input files to open on startup, i.e. perf.data files."),
Expand Down Expand Up @@ -183,6 +193,8 @@ int main(int argc, char** argv)
applyArg(appPath, &Settings::setAppPath);
applyArg(arch, &Settings::setArch);
applyArg(sourcePath, &Settings::setSourceCodePaths);
applyArg(perfBinary, &Settings::setPerfPath);
applyArg(objdumpBinary, &Settings::setObjdump);
};

auto* settings = Settings::instance();
Expand Down
1 change: 0 additions & 1 deletion src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ MainWindow::MainWindow(QWidget* parent)

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
8 changes: 7 additions & 1 deletion src/models/disassemblyoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,13 @@ DisassemblyOutput DisassemblyOutput::disassemble(const QString& objdump, const Q
return disassemblyOutput;
}

const auto processPath = QStandardPaths::findExecutable(objdump);
auto findObjdump = [](const QString& objdump) {
if (!objdump.isEmpty() && QFile::exists(objdump))
return objdump;
return QStandardPaths::findExecutable(objdump);
};

const auto processPath = findObjdump(objdump);
if (processPath.isEmpty()) {
disassemblyOutput.errorMessage =
QApplication::translate("DisassemblyOutput",
Expand Down
18 changes: 7 additions & 11 deletions src/resultsdisassemblypage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,9 +567,9 @@ void ResultsDisassemblyPage::showDisassembly()
}

// TODO: add the ability to configure the arch <-> objdump mapping somehow in the settings
const auto objdump = [this]() {
if (!m_objdump.isEmpty())
return m_objdump;
const auto objdump = [this](const QString& objdump) {
if (!objdump.isEmpty())
return objdump;

if (m_arch.startsWith(QLatin1String("armv8")) || m_arch.startsWith(QLatin1String("aarch64"))) {
return QStringLiteral("aarch64-linux-gnu-objdump");
Expand All @@ -583,9 +583,10 @@ void ResultsDisassemblyPage::showDisassembly()
auto settings = Settings::instance();
const auto colon = QLatin1Char(':');

showDisassembly(DisassemblyOutput::disassemble(
objdump(), m_arch, settings->debugPaths().split(colon), settings->extraLibPaths().split(colon),
settings->sourceCodePaths().split(colon), settings->sysroot(), curSymbol));
showDisassembly(
DisassemblyOutput::disassemble(objdump(settings->objdump()), m_arch, settings->debugPaths().split(colon),
settings->extraLibPaths().split(colon), settings->sourceCodePaths().split(colon),
settings->sysroot(), curSymbol));
}

void ResultsDisassemblyPage::showDisassembly(const DisassemblyOutput& disassemblyOutput)
Expand Down Expand Up @@ -653,11 +654,6 @@ void ResultsDisassemblyPage::setCostsMap(const Data::CallerCalleeResults& caller
m_callerCalleeResults = callerCalleeResults;
}

void ResultsDisassemblyPage::setObjdump(const QString& objdump)
{
m_objdump = objdump;
}

void ResultsDisassemblyPage::setArch(const QString& arch)
{
m_arch = arch.trimmed().toLower();
Expand Down
3 changes: 0 additions & 3 deletions src/resultsdisassemblypage.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class ResultsDisassemblyPage : public QWidget
void clear();
void setSymbol(const Data::Symbol& data);
void setCostsMap(const Data::CallerCalleeResults& callerCalleeResults);
void setObjdump(const QString& objdump);
void setArch(const QString& arch);

void jumpToSourceLine(const Data::FileLine& line);
Expand Down Expand Up @@ -78,8 +77,6 @@ class ResultsDisassemblyPage : public QWidget
QModelIndex m_currentDisasmSearchIndex;
// Architecture
QString m_arch;
// Objdump binary name
QString m_objdump;
// Map of symbols and its locations with costs
Data::CallerCalleeResults m_callerCalleeResults;
// Cost delegate
Expand Down
5 changes: 0 additions & 5 deletions src/resultspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,6 @@ void ResultsPage::onJumpToSourceCode(const Data::Symbol& symbol, const Data::Fil
}
}

void ResultsPage::setObjdump(const QString& objdump)
{
m_resultsDisassemblyPage->setObjdump(objdump);
}

void ResultsPage::onOpenEditor(const Data::Symbol& symbol)
{
m_resultsCallerCalleePage->openEditor(symbol);
Expand Down
1 change: 0 additions & 1 deletion src/resultspage.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class ResultsPage : public QWidget
public slots:
void setSysroot(const QString& path);
void setAppPath(const QString& path);
void setObjdump(const QString& objdump);

void onJumpToCallerCallee(const Data::Symbol& symbol);
void onOpenEditor(const Data::Symbol& symbol);
Expand Down
69 changes: 40 additions & 29 deletions src/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,32 +89,6 @@ void SettingsDialog::initSettings()
}
}

void SettingsDialog::initSettings(const QString& sysroot, const QString& appPath, const QString& extraLibPaths,
const QString& debugPaths, const QString& kallsyms, const QString& arch,
const QString& objdump)
{
auto fromPathString = [](KEditListWidget* listWidget, const QString& string) {
listWidget->setItems(string.split(QLatin1Char(':'), Qt::SkipEmptyParts));
};
fromPathString(unwindPage->extraLibraryPaths, extraLibPaths);
fromPathString(unwindPage->debugPaths, debugPaths);

unwindPage->lineEditSysroot->setText(sysroot);
unwindPage->lineEditApplicationPath->setText(appPath);
unwindPage->lineEditKallsyms->setText(kallsyms);
unwindPage->lineEditObjdump->setText(objdump);

int itemIndex = 0;
if (!arch.isEmpty()) {
itemIndex = unwindPage->comboBoxArchitecture->findText(arch);
if (itemIndex == -1) {
itemIndex = unwindPage->comboBoxArchitecture->count();
unwindPage->comboBoxArchitecture->addItem(arch);
}
}
unwindPage->comboBoxArchitecture->setCurrentIndex(itemIndex);
}

QString SettingsDialog::sysroot() const
{
return unwindPage->lineEditSysroot->text();
Expand Down Expand Up @@ -188,6 +162,33 @@ void SettingsDialog::addPathSettingsPage()
auto* label = new QLabel(this);
label->setText(tr("Config:"));

auto loadFromSettings = [this]() {
auto settings = Settings::instance();
auto fromPathString = [](KEditListWidget* listWidget, const QString& string) {
listWidget->setItems(string.split(QLatin1Char(':'), Qt::SkipEmptyParts));
};
fromPathString(unwindPage->extraLibraryPaths, settings->extraLibPaths());
fromPathString(unwindPage->debugPaths, settings->debugPaths());

unwindPage->lineEditSysroot->setText(settings->sysroot());
unwindPage->lineEditApplicationPath->setText(settings->appPath());
unwindPage->lineEditKallsyms->setText(settings->kallsyms());
unwindPage->lineEditObjdump->setText(settings->objdump());

const auto arch = settings->arch();
int itemIndex = 0;
if (!arch.isEmpty()) {
itemIndex = unwindPage->comboBoxArchitecture->findText(arch);
if (itemIndex == -1) {
itemIndex = unwindPage->comboBoxArchitecture->count();
unwindPage->comboBoxArchitecture->addItem(arch);
}
}
unwindPage->comboBoxArchitecture->setCurrentIndex(itemIndex);
};

loadFromSettings();

auto saveFunction = [this](KConfigGroup group) {
group.writeEntry("sysroot", sysroot());
group.writeEntry("appPath", appPath());
Expand All @@ -198,16 +199,26 @@ void SettingsDialog::addPathSettingsPage()
group.writeEntry("objdump", objdump());
};

auto restoreFunction = [this](const KConfigGroup& group) {
auto restoreFunction = [this, loadFromSettings](const KConfigGroup& group) {
::config().writeEntry("lastUsed", m_configs->currentConfig());
auto settings = Settings::instance();

const auto sysroot = group.readEntry("sysroot");
settings->setSysroot(sysroot);
const auto appPath = group.readEntry("appPath");
settings->setAppPath(appPath);
const auto extraLibPaths = group.readEntry("extraLibPaths");
settings->setExtraLibPaths(extraLibPaths);
const auto debugPaths = group.readEntry("debugPaths");
settings->setDebugPaths(debugPaths);
const auto kallsyms = group.readEntry("kallsyms");
settings->setKallsyms(kallsyms);
const auto arch = group.readEntry("arch");
settings->setArch(arch);
const auto objdump = group.readEntry("objdump");
initSettings(sysroot, appPath, extraLibPaths, debugPaths, kallsyms, arch, objdump);
::config().writeEntry("lastUsed", m_configs->currentConfig());
settings->setObjdump(objdump);

loadFromSettings();
};

m_configs = new MultiConfigWidget(this);
Expand Down
2 changes: 0 additions & 2 deletions src/settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class SettingsDialog : public KPageDialog
explicit SettingsDialog(QWidget* parent = nullptr);
~SettingsDialog();
void initSettings();
void initSettings(const QString& sysroot, const QString& appPath, const QString& extraLibPaths,
const QString& debugPaths, const QString& kallsyms, const QString& arch, const QString& objdump);
QString sysroot() const;
QString appPath() const;
QString extraLibPaths() const;
Expand Down