Skip to content

Commit c0c01a5

Browse files
committed
diff view for top down and bottom up
1 parent 08a29b6 commit c0c01a5

File tree

5 files changed

+45
-31
lines changed

5 files changed

+45
-31
lines changed

src/models/costdelegate.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ void CostDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option,
3131
}
3232

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

3637
auto rect = option.rect;
3738
rect.setWidth(rect.width() * fraction);

src/models/data.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ QString Data::prettifySymbol(const QString& name)
312312
return result == name ? name : result;
313313
}
314314

315-
TopDownResults TopDownResults::fromBottomUp(const BottomUpResults& bottomUpData, bool skipFirstLevel)
315+
TopDownResults Data::TopDownResults::fromBottomUp(const BottomUpResults& bottomUpData, bool skipFirstLevel)
316316
{
317317
TopDownResults results;
318318
results.selfCosts.initializeCostsFrom(bottomUpData.costs);

src/models/data.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,9 @@ struct TopDownResults
526526
TopDown root;
527527
Costs selfCosts;
528528
Costs inclusiveCosts;
529-
static TopDownResults fromBottomUp(const Data::BottomUpResults& bottomUpData, bool skipFirstLevel);
529+
static TopDownResults fromBottomUp(const Data::BottomUpResults& bottomUpData, bool skipFirestLevel);
530+
531+
static TopDownResults diffTopDownResults(const Data::TopDownResults& a, const Data::TopDownResults& b);
530532
};
531533

532534
struct PerLibrary : SymbolTree<PerLibrary>

src/resultstopdownpage.cpp

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "resultstopdownpage.h"
1010
#include "ui_resultstopdownpage.h"
1111

12+
#include "data.h"
1213
#include "parsers/perf/perfparser.h"
1314
#include "resultsutil.h"
1415

@@ -18,38 +19,17 @@
1819
ResultsTopDownPage::ResultsTopDownPage(FilterAndZoomStack* filterStack, PerfParser* parser,
1920
CostContextMenu* contextMenu, QWidget* parent)
2021
: QWidget(parent)
22+
, m_model(new TopDownModel(this))
2123
, ui(new Ui::ResultsTopDownPage)
2224
{
2325
ui->setupUi(this);
2426

25-
auto topDownCostModel = new TopDownModel(this);
26-
ResultsUtil::setupTreeView(ui->topDownTreeView, contextMenu, ui->topDownSearch, topDownCostModel);
27-
ResultsUtil::setupCostDelegate(topDownCostModel, ui->topDownTreeView);
28-
ResultsUtil::setupContextMenu(ui->topDownTreeView, contextMenu, topDownCostModel, filterStack, this);
29-
30-
connect(parser, &PerfParser::topDownDataAvailable, this,
31-
[this, topDownCostModel](const Data::TopDownResults& data) {
32-
topDownCostModel->setData(data);
33-
ResultsUtil::hideEmptyColumns(data.inclusiveCosts, ui->topDownTreeView, TopDownModel::NUM_BASE_COLUMNS);
34-
35-
ResultsUtil::hideEmptyColumns(data.selfCosts, ui->topDownTreeView,
36-
TopDownModel::NUM_BASE_COLUMNS + data.inclusiveCosts.numTypes());
37-
ResultsUtil::hideTracepointColumns(data.selfCosts, ui->topDownTreeView,
38-
TopDownModel::NUM_BASE_COLUMNS + data.inclusiveCosts.numTypes());
39-
40-
// hide self cost columns for sched:sched_switch and off-CPU
41-
// quasi all rows will have a cost of 0%, and only the leaves will show
42-
// a non-zero value that is equal to the inclusive cost then
43-
const auto costs = data.inclusiveCosts.numTypes();
44-
const auto schedSwitchName = QLatin1String("sched:sched_switch");
45-
const auto offCpuName = PerfParser::tr("off-CPU Time");
46-
for (int i = 0; i < costs; ++i) {
47-
const auto typeName = data.inclusiveCosts.typeName(i);
48-
if (typeName == schedSwitchName || typeName == offCpuName) {
49-
ui->topDownTreeView->hideColumn(topDownCostModel->selfCostColumn(i));
50-
}
51-
}
52-
});
27+
ResultsUtil::setupTreeViewDiff(ui->topDownTreeView, contextMenu, ui->topDownSearch, m_model);
28+
ResultsUtil::setupCostDelegate(m_model, ui->topDownTreeView);
29+
ResultsUtil::setupContextMenu(ui->topDownTreeView, contextMenu, m_model, filterStack, this);
30+
31+
if (parser)
32+
connect(parser, &PerfParser::topDownDataAvailable, this, &ResultsTopDownPage::setTopDownResults);
5333

5434
ResultsUtil::setupResultsAggregation(ui->costAggregationComboBox);
5535
}
@@ -60,3 +40,28 @@ void ResultsTopDownPage::clear()
6040
{
6141
ui->topDownSearch->setText({});
6242
}
43+
44+
void ResultsTopDownPage::setTopDownResults(const Data::TopDownResults& data)
45+
{
46+
m_model->setData(data);
47+
ResultsUtil::hideEmptyColumns(data.inclusiveCosts, ui->topDownTreeView, TopDownModel::NUM_BASE_COLUMNS);
48+
49+
ResultsUtil::hideEmptyColumns(data.selfCosts, ui->topDownTreeView,
50+
TopDownModel::NUM_BASE_COLUMNS + data.inclusiveCosts.numTypes());
51+
ResultsUtil::hideTracepointColumns(data.selfCosts, ui->topDownTreeView,
52+
TopDownModel::NUM_BASE_COLUMNS + data.inclusiveCosts.numTypes());
53+
54+
// hide self cost columns for sched:sched_switch and off-CPU
55+
// quasi all rows will have a cost of 0%, and only the leaves will show
56+
// a non-zero value that is equal to the inclusive cost then
57+
const auto costs = data.inclusiveCosts.numTypes();
58+
const auto schedSwitchName = QLatin1String("sched:sched_switch");
59+
const auto offCpuName = PerfParser::tr("off-CPU Time");
60+
for (int i = 0; i < costs; ++i) {
61+
const auto typeName = data.inclusiveCosts.typeName(i);
62+
// use contains to also work in diff view
63+
if (typeName.contains(schedSwitchName) || typeName.contains(offCpuName)) {
64+
ui->topDownTreeView->hideColumn(m_model->selfCostColumn(i));
65+
}
66+
}
67+
}

src/resultstopdownpage.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ class ResultsTopDownPage;
1616

1717
namespace Data {
1818
struct Symbol;
19+
struct TopDownResults;
1920
}
2021

2122
class QTreeView;
2223

2324
class PerfParser;
2425
class FilterAndZoomStack;
2526
class CostContextMenu;
27+
class TopDownModel;
2628

2729
class ResultsTopDownPage : public QWidget
2830
{
@@ -34,12 +36,16 @@ class ResultsTopDownPage : public QWidget
3436

3537
void clear();
3638

39+
public slots:
40+
void setTopDownResults(const Data::TopDownResults& data);
41+
3742
signals:
3843
void jumpToCallerCallee(const Data::Symbol& symbol);
3944
void openEditor(const Data::Symbol& symbol);
4045
void selectSymbol(const Data::Symbol& symbol);
4146
void jumpToDisassembly(const Data::Symbol& symbol);
4247

4348
private:
49+
TopDownModel* m_model = nullptr;
4450
QScopedPointer<Ui::ResultsTopDownPage> ui;
4551
};

0 commit comments

Comments
 (0)