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

don't include non-working context-menu entries #558

Merged
merged 6 commits into from
Dec 3, 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
19 changes: 10 additions & 9 deletions src/models/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,26 +258,27 @@ QString prettifySymbol(QStringView str)
return result;
}

void buildPerLibrary(const TopDown* node, PerLibraryResults& results, QHash<QString, int>& binaryToResultIndex,
void buildPerLibrary(const TopDown* node, PerLibraryResults& results, QHash<QString, int>& pathToResultIndex,
const Costs& costs)
{
for (const auto& child : node->children) {
const auto binary = child.symbol.binary;
const auto path = child.symbol.path;

auto resultIndexIt = binaryToResultIndex.find(binary);
if (resultIndexIt == binaryToResultIndex.end()) {
resultIndexIt = binaryToResultIndex.insert(binary, binaryToResultIndex.size());
auto resultIndexIt = pathToResultIndex.find(path);
if (resultIndexIt == pathToResultIndex.end()) {
resultIndexIt = pathToResultIndex.insert(path, pathToResultIndex.size());

PerLibrary library;
library.id = *resultIndexIt;
library.symbol = Symbol(binary);
library.symbol = Symbol({}, 0, 0, child.symbol.binary, child.symbol.path, child.symbol.actualPath,
child.symbol.isKernel);
results.root.children.push_back(library);
}

const auto cost = costs.itemCost(child.id);
results.costs.add(*resultIndexIt, cost);

buildPerLibrary(&child, results, binaryToResultIndex, costs);
buildPerLibrary(&child, results, pathToResultIndex, costs);
}
}
}
Expand Down Expand Up @@ -318,10 +319,10 @@ TopDownResults TopDownResults::fromBottomUp(const BottomUpResults& bottomUpData,
PerLibraryResults PerLibraryResults::fromTopDown(const TopDownResults& topDownData)
{
PerLibraryResults results;
QHash<QString, int> binaryToResultIndex;
QHash<QString, int> pathToResultIndex;
results.costs.initializeCostsFrom(topDownData.selfCosts);

buildPerLibrary(&topDownData.root, results, binaryToResultIndex, topDownData.selfCosts);
buildPerLibrary(&topDownData.root, results, pathToResultIndex, topDownData.selfCosts);

PerLibrary::initializeParents(&results.root);

Expand Down
1 change: 0 additions & 1 deletion src/models/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "../util.h"

#include <functional>
#include <limits>
#include <tuple>
#include <valarray>
Expand Down
4 changes: 3 additions & 1 deletion src/models/treemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ QVariant PerLibraryModel::rowData(const Data::PerLibrary* row, int column, int r
if (role == Qt::DisplayRole || role == SortRole) {
switch (column) {
case Binary:
return Util::formatSymbol(row->symbol);
return Util::formatString(row->symbol.binary);
}

column -= NUM_BASE_COLUMNS;
Expand All @@ -254,6 +254,8 @@ QVariant PerLibraryModel::rowData(const Data::PerLibrary* row, int column, int r

column -= m_results.costs.numTypes();
return m_results.costs.totalCost(column);
} else if (role == Qt::ToolTipRole) {
return Util::formatBinaryTooltip(row->id, row->symbol, m_results.costs);
} else {
return {};
}
Expand Down
2 changes: 1 addition & 1 deletion src/resultssummarypage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ResultsSummaryPage::ResultsSummaryPage(FilterAndZoomStack* filterStack, PerfPars
ui->topLibraryTreeView->setModel(topLibraryProxy);
ResultsUtil::setupCostDelegate<PerLibraryModel>(perLibraryModel, ui->topLibraryTreeView);
ResultsUtil::setupHeaderView(ui->topLibraryTreeView, contextMenu);
ResultsUtil::setupContextMenu(ui->topLibraryTreeView, contextMenu, perLibraryModel, filterStack, this);
ResultsUtil::setupContextMenu(ui->topLibraryTreeView, contextMenu, perLibraryModel, filterStack, this, {});

connect(ui->eventSourceComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this,
[topHotspotsProxy, this]() {
Expand Down
41 changes: 28 additions & 13 deletions src/resultsutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,30 @@ void addFilterActions(QMenu* menu, const Data::Symbol& symbol, FilterAndZoomStac
{
if (symbol.isValid()) {
auto filterActions = filterStack->actions();
filterActions.filterInBySymbol->setData(QVariant::fromValue(symbol));
filterActions.filterOutBySymbol->setData(filterActions.filterInBySymbol->data());

menu->addAction(filterActions.filterInBySymbol);
menu->addAction(filterActions.filterOutBySymbol);
menu->addSeparator();
// don't include symbol-related entries for binary-only symbols (like in Top Hotspots Per File)
if (!symbol.symbol.isEmpty()) {
auto symbolFilter = QVariant::fromValue(symbol);

filterActions.filterInByBinary->setData(QVariant::fromValue(symbol.binary));
filterActions.filterOutByBinary->setData(filterActions.filterInByBinary->data());
filterActions.filterInBySymbol->setData(symbolFilter);
filterActions.filterOutBySymbol->setData(symbolFilter);

menu->addAction(filterActions.filterInByBinary);
menu->addAction(filterActions.filterOutByBinary);
menu->addSeparator();
menu->addAction(filterActions.filterInBySymbol);
menu->addAction(filterActions.filterOutBySymbol);
menu->addSeparator();
}

// don't include binary-related entries when we don't have this information
if (!symbol.binary.isEmpty()) {
auto binaryFilter = QVariant::fromValue(symbol.binary);

filterActions.filterInByBinary->setData(binaryFilter);
filterActions.filterOutByBinary->setData(binaryFilter);

menu->addAction(filterActions.filterInByBinary);
menu->addAction(filterActions.filterOutByBinary);
menu->addSeparator();
}
}

menu->addAction(filterStack->actions().filterOut);
Expand All @@ -103,11 +114,13 @@ void setupContextMenu(QTreeView* view, CostContextMenu* costContextMenu, int sym
contextMenu.addAction(QCoreApplication::translate("Util", "View Caller/Callee"));
QObject::connect(viewCallerCallee, &QAction::triggered, &contextMenu,
[symbol, callback]() { callback(CallbackAction::ViewCallerCallee, symbol); });
viewCallerCallee->setEnabled(symbol.canDisassemble());
}
if (actions.testFlag(CallbackAction::OpenEditor)) {
auto* openEditorAction = contextMenu.addAction(QCoreApplication::translate("Util", "Open in Editor"));
QObject::connect(openEditorAction, &QAction::triggered, &contextMenu,
[symbol, callback]() { callback(CallbackAction::OpenEditor, symbol); });
openEditorAction->setEnabled(symbol.canDisassemble());
}
if (actions.testFlag(CallbackAction::ViewDisassembly)) {
auto* viewDisassembly = contextMenu.addAction(QCoreApplication::translate("Util", "Disassembly"));
Expand All @@ -116,10 +129,12 @@ void setupContextMenu(QTreeView* view, CostContextMenu* costContextMenu, int sym
viewDisassembly->setEnabled(symbol.canDisassemble());
}
contextMenu.addSeparator();
costContextMenu->addToMenu(view->header(),
contextMenu.addMenu(QCoreApplication::translate("Util", "Visible Columns")));
contextMenu.addSeparator();
}

costContextMenu->addToMenu(view->header(),
contextMenu.addMenu(QCoreApplication::translate("Util", "Visible Columns")));
contextMenu.addSeparator();

addFilterActions(&contextMenu, symbol, filterStack);

if (!contextMenu.actions().isEmpty()) {
Expand Down
5 changes: 5 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ QString Util::formatFrequency(quint64 occurrences, quint64 nanoseconds)
return QString::number(hz, 'G', 4) + QLatin1String(*unit);
}

QString Util::formatBinaryTooltip(int id, const Data::Symbol& symbol, const Data::Costs& costs)
{
return formatTooltipImpl(id, Util::formatString(symbol.binary), nullptr, &costs);
}

QString Util::formatTooltip(int id, const Data::Symbol& symbol, const Data::Costs& costs)
{
return formatTooltipImpl(id, formatForTooltip(symbol), nullptr, &costs);
Expand Down
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ QString formatCost(quint64 cost);
QString formatCostRelative(quint64 selfCost, quint64 totalCost, bool addPercentSign = false);
QString formatTimeString(quint64 nanoseconds, bool shortForm = false);
QString formatFrequency(quint64 occurrences, quint64 nanoseconds);
QString formatBinaryTooltip(int id, const Data::Symbol& symbol, const Data::Costs& costs);
QString formatTooltip(int id, const Data::Symbol& symbol, const Data::Costs& costs);
QString formatTooltip(int id, const Data::Symbol& symbol, const Data::Costs& selfCosts,
const Data::Costs& inclusiveCosts);
Expand Down