Skip to content

Commit

Permalink
feat: allow user to specify perf and objdump via command line
Browse files Browse the repository at this point in the history
closes: #556
  • Loading branch information
lievenhey committed May 29, 2024
1 parent e4ac31e commit f0c03d0
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 22 deletions.
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

0 comments on commit f0c03d0

Please sign in to comment.