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

Disable branches #518

Merged
merged 7 commits into from
Oct 21, 2023
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
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ set(HOTSPOT_SRCS
callgraphwidget.ui
callgraphsettingspage.ui
frequencypage.ui
sourcepathsettings.ui
disassemblysettingspage.ui
perfsettingspage.ui
# resources:
resources.qrc
Expand Down
22 changes: 18 additions & 4 deletions src/sourcepathsettings.ui → src/disassemblysettingspage.ui
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SourcePathSettingsPage</class>
<widget class="QWidget" name="SourcePathSettingsPage">
<class>DisassemblySettingsPage</class>
<widget class="QWidget" name="DisassemblySettingsPage">
<property name="geometry">
<rect>
<x>0</x>
Expand Down Expand Up @@ -32,20 +32,34 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Source Code Search Paths:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="1">
<widget class="KEditListWidget" name="sourcePaths">
<property name="buttons">
<set>KEditListWidget::All</set>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Show branches:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="showBranches">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
Expand Down
5 changes: 4 additions & 1 deletion src/models/disassemblymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <QTextDocument>

#include "disassemblymodel.h"
#include "hotspot-config.h"

#include "highlighter.hpp"
#include "search.h"
Expand Down Expand Up @@ -81,6 +80,8 @@ QVariant DisassemblyModel::headerData(int section, Qt::Orientation orientation,

if (section == AddrColumn)
return tr("Address");
else if (section == BranchColumn)
return tr("Branches");
else if (section == DisassemblyColumn)
return tr("Assembly / Disassembly");

Expand Down Expand Up @@ -117,6 +118,8 @@ QVariant DisassemblyModel::data(const QModelIndex& index, int role) const
if (!data.addr)
return {};
return QString::number(data.addr, 16);
} else if (index.column() == BranchColumn) {
return data.branchVisualisation;
} else if (index.column() == DisassemblyColumn) {
const auto block = m_document->findBlockByLineNumber(index.row());
if (role == SyntaxHighlightRole)
Expand Down
1 change: 1 addition & 0 deletions src/models/disassemblymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class DisassemblyModel : public QAbstractTableModel
enum Columns
{
AddrColumn,
BranchColumn,
DisassemblyColumn,
COLUMN_COUNT
};
Expand Down
20 changes: 18 additions & 2 deletions src/models/disassemblyoutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ QString findBinaryForSymbol(const QStringList& debugPaths, const QStringList& ex
return {};
}

bool isHexCharacter(QChar c)
{
return (c >= QLatin1Char('0') && c <= QLatin1Char('9')) || (c >= QLatin1Char('a') && c <= QLatin1Char('f'));
milianw marked this conversation as resolved.
Show resolved Hide resolved
}

ObjectdumpOutput objdumpParse(const QByteArray& output)
{
QVector<DisassemblyOutput::DisassemblyLine> disassemblyLines;
Expand Down Expand Up @@ -199,8 +204,19 @@ ObjectdumpOutput objdumpParse(const QByteArray& output)
assembly = asmLine;
}

disassemblyLines.push_back(
{addr, assembly, extractLinkedFunction(asmLine), {currentSourceFileName, sourceCodeLine}});
// format is the following:
// /- a5 54 12 ...
// | 64 a3 ....
// \-> 65 23 ....
// so we can simply skip all characters until we meet a letter or a number
const auto branchVisualisationRange =
std::distance(assembly.cbegin(), std::find_if(assembly.cbegin(), assembly.cend(), isHexCharacter));

disassemblyLines.push_back({addr,
assembly.mid(branchVisualisationRange),
branchVisualisationRange ? assembly.left(branchVisualisationRange) : QString {},
extractLinkedFunction(asmLine),
{currentSourceFileName, sourceCodeLine}});
}
return {disassemblyLines, sourceFileName};
}
Expand Down
1 change: 1 addition & 0 deletions src/models/disassemblyoutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct DisassemblyOutput
{
quint64 addr = 0;
QString disassembly;
QString branchVisualisation;
LinkedFunction linkedFunction;
Data::FileLine fileLine;
};
Expand Down
3 changes: 2 additions & 1 deletion src/models/timelinedelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ Data::Events::const_iterator findEvent(const Data::Events::const_iterator& begin
auto it = std::lower_bound(begin, end, time, byTime);
// it points to the first item for which our predicate returns false, we want to find the item before that
// so decrement it if possible or return begin otherwise
return (it == begin || it->time == time) ? it : (it - 1);
// if only one event is recorded, it will point to end it->time which will cause asan to complain
return (it == begin || (it != end && it->time == time)) ? it : (it - 1);
}
}

Expand Down
1 change: 0 additions & 1 deletion src/resultscallercalleepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ ResultsCallerCalleePage::ResultsCallerCalleePage(FilterAndZoomStack* filterStack
CallerCalleeModel::NUM_BASE_COLUMNS + data.inclusiveCosts.numTypes());
ResultsUtil::hideTracepointColumns(data.selfCosts, ui->callerCalleeTableView, BottomUpModel::NUM_BASE_COLUMNS);
auto view = ui->callerCalleeTableView;
view->sortByColumn(CallerCalleeModel::InitialSortColumn, view->header()->sortIndicatorOrder());
view->setCurrentIndex(view->model()->index(0, 0, {}));
ResultsUtil::hideEmptyColumns(data.inclusiveCosts, ui->callersView, CallerModel::NUM_BASE_COLUMNS);
ResultsUtil::hideEmptyColumns(data.inclusiveCosts, ui->calleesView, CalleeModel::NUM_BASE_COLUMNS);
Expand Down
13 changes: 8 additions & 5 deletions src/resultsdisassemblypage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <KColorScheme>
#include <KStandardAction>

#include "parsers/perf/perfparser.h"
#include "resultsutil.h"

#if KFSyntaxHighlighting_FOUND
Expand All @@ -43,11 +42,8 @@
#include "models/codedelegate.h"
#include "models/costdelegate.h"
#include "models/disassemblymodel.h"
#include "models/hashmodel.h"
#include "models/search.h"
#include "models/sourcecodemodel.h"
#include "models/topproxy.h"
#include "models/treemodel.h"
#include "settings.h"

namespace {
Expand Down Expand Up @@ -105,7 +101,6 @@ ResultsDisassemblyPage::ResultsDisassemblyPage(CostContextMenu* costContextMenu,
connect(settings, &Settings::sourceCodePathsChanged, this, [this](const QString&) { showDisassembly(); });

connect(ui->assemblyView, &QTreeView::entered, this, updateFromDisassembly);

connect(ui->sourceCodeView, &QTreeView::entered, this, updateFromSource);

ui->sourceCodeView->setContextMenuPolicy(Qt::CustomContextMenu);
Expand Down Expand Up @@ -257,6 +252,12 @@ ResultsDisassemblyPage::ResultsDisassemblyPage(CostContextMenu* costContextMenu,
ui->disasmSearchWidget, ui->disasmSearchEdit, ui->assemblyView, ui->disasmEndReachedWidget,
m_disassemblyModel, &m_currentDisasmSearchIndex, 0);

ui->assemblyView->setColumnHidden(DisassemblyModel::BranchColumn, !settings->showBranches());

connect(settings, &Settings::showBranchesChanged, this, [this](bool showBranches) {
ui->assemblyView->setColumnHidden(DisassemblyModel::BranchColumn, !showBranches);
});
lievenhey marked this conversation as resolved.
Show resolved Hide resolved

#if KFSyntaxHighlighting_FOUND
QStringList schemes;

Expand Down Expand Up @@ -312,7 +313,9 @@ void ResultsDisassemblyPage::setupAsmViewModel()

ui->assemblyView->header()->setStretchLastSection(false);
ui->assemblyView->header()->setSectionResizeMode(DisassemblyModel::AddrColumn, QHeaderView::ResizeToContents);
ui->assemblyView->header()->setSectionResizeMode(DisassemblyModel::BranchColumn, QHeaderView::ResizeToContents);
ui->assemblyView->header()->setSectionResizeMode(DisassemblyModel::DisassemblyColumn, QHeaderView::Stretch);
ui->assemblyView->setItemDelegateForColumn(DisassemblyModel::BranchColumn, m_disassemblyDelegate);
ui->assemblyView->setItemDelegateForColumn(DisassemblyModel::DisassemblyColumn, m_disassemblyDelegate);

for (int col = DisassemblyModel::COLUMN_COUNT; col < m_disassemblyModel->columnCount(); col++) {
Expand Down
2 changes: 1 addition & 1 deletion src/resultsdisassemblypage.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class ResultsDisassemblyPage : public QWidget

void clear();
void setupAsmViewModel();
void showDisassembly();
void setSymbol(const Data::Symbol& data);
void setCostsMap(const Data::CallerCalleeResults& callerCalleeResults);
void setObjdump(const QString& objdump);
Expand All @@ -65,6 +64,7 @@ class ResultsDisassemblyPage : public QWidget

private:
void showDisassembly(const DisassemblyOutput& disassemblyOutput);
void showDisassembly();

std::unique_ptr<Ui::ResultsDisassemblyPage> ui;
#if KFSyntaxHighlighting_FOUND
Expand Down
1 change: 0 additions & 1 deletion src/resultspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ void ResultsPage::onJumpToDisassembly(const Data::Symbol& symbol)
{
m_disassemblyDock->toggleAction()->setEnabled(true);
m_resultsDisassemblyPage->setSymbol(symbol);
m_resultsDisassemblyPage->showDisassembly();
showDock(m_disassemblyDock);
}

Expand Down
22 changes: 18 additions & 4 deletions src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@ void Settings::loadFromFile()
sharedConfig->group("PathSettings").writeEntry("userPaths", this->userPaths());
sharedConfig->group("PathSettings").writeEntry("systemPaths", this->systemPaths());
});
setSourceCodePaths(sharedConfig->group("PathSettings").readEntry("sourceCodePaths", QString()));
connect(this, &Settings::sourceCodePathsChanged, this, [sharedConfig](const QString& paths) {
sharedConfig->group("PathSettings").writeEntry("sourceCodePaths", paths);
});

// fix build error in app image build
const auto colorScheme = KColorScheme(QPalette::Normal, KColorScheme::View, sharedConfig);
Expand Down Expand Up @@ -237,6 +233,16 @@ void Settings::loadFromFile()
connect(this, &Settings::lastUsedEnvironmentChanged, this, [sharedConfig](const QString& envName) {
sharedConfig->group("PerfPaths").writeEntry("lastUsed", envName);
});

setSourceCodePaths(sharedConfig->group("Disassembly").readEntry("sourceCodePaths", QString()));
connect(this, &Settings::sourceCodePathsChanged, this, [sharedConfig](const QString& paths) {
sharedConfig->group("Disassembly").writeEntry("sourceCodePaths", paths);
});

setShowBranches(sharedConfig->group("Disassembly").readEntry("showBranches", true));
connect(this, &Settings::showBranchesChanged, [sharedConfig](bool showBranches) {
sharedConfig->group("Disassembly").writeEntry("showBranches", showBranches);
});
}

void Settings::setSourceCodePaths(const QString& paths)
Expand All @@ -254,3 +260,11 @@ void Settings::setPerfPath(const QString& path)
emit perfPathChanged(m_perfPath);
}
}

void Settings::setShowBranches(bool showBranches)
{
if (m_showBranches != showBranches) {
m_showBranches = showBranches;
emit showBranchesChanged(m_showBranches);
}
}
8 changes: 8 additions & 0 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ class Settings : public QObject
return m_perfPath;
}

bool showBranches() const
{
return m_showBranches;
}

void loadFromFile();

signals:
Expand All @@ -176,6 +181,7 @@ class Settings : public QObject
void lastUsedEnvironmentChanged(const QString& envName);
void sourceCodePathsChanged(const QString& paths);
void perfPathChanged(const QString& perfPath);
void showBranchesChanged(bool showBranches);

public slots:
void setPrettifySymbols(bool prettifySymbols);
Expand All @@ -199,6 +205,7 @@ public slots:
void setLastUsedEnvironment(const QString& envName);
void setSourceCodePaths(const QString& paths);
void setPerfPath(const QString& path);
void setShowBranches(bool showBranches);

private:
Settings() = default;
Expand All @@ -222,6 +229,7 @@ public slots:
QString m_objdump;
QString m_sourceCodePaths;
QString m_perfMapPath;
bool m_showBranches = true;

QString m_lastUsedEnvironment;

Expand Down
25 changes: 15 additions & 10 deletions src/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

#include "ui_callgraphsettingspage.h"
#include "ui_debuginfodpage.h"
#include "ui_disassemblysettingspage.h"
#include "ui_flamegraphsettingspage.h"
#include "ui_perfsettingspage.h"
#include "ui_sourcepathsettings.h"
#include "ui_unwindsettingspage.h"

#include "multiconfigwidget.h"
Expand Down Expand Up @@ -64,7 +64,7 @@ SettingsDialog::SettingsDialog(QWidget* parent)
, unwindPage(new Ui::UnwindSettingsPage)
, flamegraphPage(new Ui::FlamegraphSettingsPage)
, debuginfodPage(new Ui::DebuginfodPage)
, sourcePathPage(new Ui::SourcePathSettingsPage)
, disassemblyPage(new Ui::DisassemblySettingsPage)
#if KGraphViewerPart_FOUND
, callgraphPage(new Ui::CallgraphSettingsPage)
#endif
Expand Down Expand Up @@ -321,19 +321,24 @@ void SettingsDialog::addCallgraphPage()
void SettingsDialog::addSourcePathPage()
{
auto page = new QWidget(this);
auto item = addPage(page, tr("Source Path"));
item->setHeader(tr("Source Path Settings"));
auto item = addPage(page, tr("Disassembly"));
item->setHeader(tr("Disassembly Settings"));
item->setIcon(QIcon::fromTheme(QStringLiteral("preferences-system-windows-behavior")));

sourcePathPage->setupUi(page);
disassemblyPage->setupUi(page);

auto settings = Settings::instance();

const auto colon = QLatin1Char(':');
connect(Settings::instance(), &Settings::sourceCodePathsChanged, this,
[this, colon](const QString& paths) { sourcePathPage->sourcePaths->setItems(paths.split(colon)); });
connect(settings, &Settings::sourceCodePathsChanged, this,
[this, colon](const QString& paths) { disassemblyPage->sourcePaths->setItems(paths.split(colon)); });

setupMultiPath(disassemblyPage->sourcePaths, disassemblyPage->label, buttonBox()->button(QDialogButtonBox::Ok));

setupMultiPath(sourcePathPage->sourcePaths, sourcePathPage->label, buttonBox()->button(QDialogButtonBox::Ok));
disassemblyPage->showBranches->setChecked(settings->showBranches());

connect(buttonBox(), &QDialogButtonBox::accepted, this, [this, colon] {
Settings::instance()->setSourceCodePaths(sourcePathPage->sourcePaths->items().join(colon));
connect(buttonBox(), &QDialogButtonBox::accepted, this, [this, colon, settings] {
settings->setSourceCodePaths(disassemblyPage->sourcePaths->items().join(colon));
settings->setShowBranches(disassemblyPage->showBranches->isChecked());
});
}
4 changes: 2 additions & 2 deletions src/settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class UnwindSettingsPage;
class FlamegraphSettingsPage;
class DebuginfodPage;
class CallgraphSettingsPage;
class SourcePathSettingsPage;
class DisassemblySettingsPage;
class PerfSettingsPage;
}

Expand Down Expand Up @@ -56,7 +56,7 @@ class SettingsDialog : public KPageDialog
std::unique_ptr<Ui::UnwindSettingsPage> unwindPage;
std::unique_ptr<Ui::FlamegraphSettingsPage> flamegraphPage;
std::unique_ptr<Ui::DebuginfodPage> debuginfodPage;
std::unique_ptr<Ui::SourcePathSettingsPage> sourcePathPage;
std::unique_ptr<Ui::DisassemblySettingsPage> disassemblyPage;
std::unique_ptr<Ui::CallgraphSettingsPage> callgraphPage;
MultiConfigWidget* m_configs;
};
2 changes: 1 addition & 1 deletion tests/integrationtests/tst_perfparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct ComparableSymbol

bool operator==(const ComparableSymbol& rhs) const
{
Q_ASSERT(isPattern != rhs.isPattern);
VERIFY_OR_THROW(isPattern != rhs.isPattern);
auto cmp = [](const Data::Symbol& symbol, const QVector<QPair<QString, QString>>& pattern) {
return std::any_of(pattern.begin(), pattern.end(), [&symbol](const QPair<QString, QString>& pattern) {
return symbol.symbol.contains(pattern.first) && symbol.binary.contains(pattern.second);
Expand Down
Loading