Skip to content

Commit

Permalink
diff view for top down and bottom up
Browse files Browse the repository at this point in the history
  • Loading branch information
lievenhey committed Dec 8, 2022
1 parent e207ac4 commit e0b8957
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 31 deletions.
3 changes: 2 additions & 1 deletion src/models/costdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ void CostDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
}

const auto totalCost = index.data(m_totalCostRole).toULongLong();
const auto fraction = std::abs(float(cost) / totalCost);
// TODO C++17: std::clamp
const auto fraction = std::max(0.f, std::min(1.f, std::abs(float(cost) / totalCost)));

auto rect = option.rect;
rect.setWidth(rect.width() * fraction);
Expand Down
2 changes: 1 addition & 1 deletion src/models/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ QString Data::prettifySymbol(const QString& name)
return result == name ? name : result;
}

TopDownResults TopDownResults::fromBottomUp(const BottomUpResults& bottomUpData, bool skipFirstLevel)
TopDownResults Data::TopDownResults::fromBottomUp(const BottomUpResults& bottomUpData, bool skipFirstLevel)
{
TopDownResults results;
results.selfCosts.initializeCostsFrom(bottomUpData.costs);
Expand Down
4 changes: 3 additions & 1 deletion src/models/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,9 @@ struct TopDownResults
TopDown root;
Costs selfCosts;
Costs inclusiveCosts;
static TopDownResults fromBottomUp(const Data::BottomUpResults& bottomUpData, bool skipFirstLevel);
static TopDownResults fromBottomUp(const Data::BottomUpResults& bottomUpData, bool skipFirestLevel);

static TopDownResults diffTopDownResults(const Data::TopDownResults& a, const Data::TopDownResults& b);
};

struct PerLibrary : SymbolTree<PerLibrary>
Expand Down
61 changes: 33 additions & 28 deletions src/resultstopdownpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "resultstopdownpage.h"
#include "ui_resultstopdownpage.h"

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

Expand All @@ -18,38 +19,17 @@
ResultsTopDownPage::ResultsTopDownPage(FilterAndZoomStack* filterStack, PerfParser* parser,
CostContextMenu* contextMenu, QWidget* parent)
: QWidget(parent)
, m_model(new TopDownModel(this))
, ui(new Ui::ResultsTopDownPage)
{
ui->setupUi(this);

auto topDownCostModel = new TopDownModel(this);
ResultsUtil::setupTreeView(ui->topDownTreeView, contextMenu, ui->topDownSearch, topDownCostModel);
ResultsUtil::setupCostDelegate(topDownCostModel, ui->topDownTreeView);
ResultsUtil::setupContextMenu(ui->topDownTreeView, contextMenu, topDownCostModel, filterStack, this);

connect(parser, &PerfParser::topDownDataAvailable, this,
[this, topDownCostModel](const Data::TopDownResults& data) {
topDownCostModel->setData(data);
ResultsUtil::hideEmptyColumns(data.inclusiveCosts, ui->topDownTreeView, TopDownModel::NUM_BASE_COLUMNS);

ResultsUtil::hideEmptyColumns(data.selfCosts, ui->topDownTreeView,
TopDownModel::NUM_BASE_COLUMNS + data.inclusiveCosts.numTypes());
ResultsUtil::hideTracepointColumns(data.selfCosts, ui->topDownTreeView,
TopDownModel::NUM_BASE_COLUMNS + data.inclusiveCosts.numTypes());

// hide self cost columns for sched:sched_switch and off-CPU
// quasi all rows will have a cost of 0%, and only the leaves will show
// a non-zero value that is equal to the inclusive cost then
const auto costs = data.inclusiveCosts.numTypes();
const auto schedSwitchName = QLatin1String("sched:sched_switch");
const auto offCpuName = PerfParser::tr("off-CPU Time");
for (int i = 0; i < costs; ++i) {
const auto typeName = data.inclusiveCosts.typeName(i);
if (typeName == schedSwitchName || typeName == offCpuName) {
ui->topDownTreeView->hideColumn(topDownCostModel->selfCostColumn(i));
}
}
});
ResultsUtil::setupTreeViewDiff(ui->topDownTreeView, contextMenu, ui->topDownSearch, m_model);
ResultsUtil::setupCostDelegate(m_model, ui->topDownTreeView);
ResultsUtil::setupContextMenu(ui->topDownTreeView, contextMenu, m_model, filterStack, this);

if (parser)
connect(parser, &PerfParser::topDownDataAvailable, this, &ResultsTopDownPage::setTopDownResults);

ResultsUtil::setupResultsAggregation(ui->costAggregationComboBox);
}
Expand All @@ -60,3 +40,28 @@ void ResultsTopDownPage::clear()
{
ui->topDownSearch->setText({});
}

void ResultsTopDownPage::setTopDownResults(const Data::TopDownResults& data)
{
m_model->setData(data);
ResultsUtil::hideEmptyColumns(data.inclusiveCosts, ui->topDownTreeView, TopDownModel::NUM_BASE_COLUMNS);

ResultsUtil::hideEmptyColumns(data.selfCosts, ui->topDownTreeView,
TopDownModel::NUM_BASE_COLUMNS + data.inclusiveCosts.numTypes());
ResultsUtil::hideTracepointColumns(data.selfCosts, ui->topDownTreeView,
TopDownModel::NUM_BASE_COLUMNS + data.inclusiveCosts.numTypes());

// hide self cost columns for sched:sched_switch and off-CPU
// quasi all rows will have a cost of 0%, and only the leaves will show
// a non-zero value that is equal to the inclusive cost then
const auto costs = data.inclusiveCosts.numTypes();
const auto schedSwitchName = QLatin1String("sched:sched_switch");
const auto offCpuName = PerfParser::tr("off-CPU Time");
for (int i = 0; i < costs; ++i) {
const auto typeName = data.inclusiveCosts.typeName(i);
// use contains to also work in diff view
if (typeName.contains(schedSwitchName) || typeName.contains(offCpuName)) {
ui->topDownTreeView->hideColumn(m_model->selfCostColumn(i));
}
}
}
6 changes: 6 additions & 0 deletions src/resultstopdownpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ class ResultsTopDownPage;

namespace Data {
struct Symbol;
struct TopDownResults;
}

class QTreeView;

class PerfParser;
class FilterAndZoomStack;
class CostContextMenu;
class TopDownModel;

class ResultsTopDownPage : public QWidget
{
Expand All @@ -34,12 +36,16 @@ class ResultsTopDownPage : public QWidget

void clear();

public slots:
void setTopDownResults(const Data::TopDownResults& data);

signals:
void jumpToCallerCallee(const Data::Symbol& symbol);
void openEditor(const Data::Symbol& symbol);
void selectSymbol(const Data::Symbol& symbol);
void jumpToDisassembly(const Data::Symbol& symbol);

private:
TopDownModel* m_model = nullptr;
QScopedPointer<Ui::ResultsTopDownPage> ui;
};

0 comments on commit e0b8957

Please sign in to comment.