Skip to content

Commit df687d1

Browse files
committed
glue diffing on perfparser
1 parent 4f7a309 commit df687d1

12 files changed

Lines changed: 306 additions & 143 deletions

File tree

src/diffviewwidget.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,20 @@ DiffViewWidget::DiffViewWidget(QWidget* parent)
5555
, m_filterAndZoomStackA(new FilterAndZoomStack(this))
5656
, m_filterAndZoomStackB(new FilterAndZoomStack(this))
5757
, m_filterMenu(new QMenu(this))
58-
, m_model(new DiffViewModel(this))
58+
//, m_model(new DiffViewModel(this))
5959
, m_contents(createDockingArea(QStringLiteral("diffview"), this))
6060
, m_timelineA(new TimeLineWidget(m_parserA, m_filterMenu, m_filterAndZoomStackA, this))
6161
, m_timelineB(new TimeLineWidget(m_parserB, m_filterMenu, m_filterAndZoomStackB, this))
6262
{
6363
ui->setupUi(this);
64-
auto diffProxy = new DiffViewProxy(this);
64+
/*auto diffProxy = new DiffViewProxy(this);
6565
diffProxy->setSourceModel(m_model);
6666
6767
ResultsUtil::setupTreeView(ui->diffTreeView, ui->diffSearch, diffProxy, DiffViewModel::InitialSortColumn,
6868
DiffViewModel::SortRole);
6969
ui->diffTreeView->sortByColumn(DiffViewModel::InitialSortColumn, Qt::DescendingOrder);
7070
ResultsUtil::setupCostDelegate<DiffViewModel>(m_model, ui->diffTreeView);
71-
71+
*/
7272
auto dockify = [](QWidget* widget, const QString& id, const QString& title, const QString& shortcut) {
7373
auto* dock = new KDDockWidgets::DockWidget(id);
7474
dock->setWidget(widget);
@@ -90,9 +90,9 @@ DiffViewWidget::DiffViewWidget(QWidget* parent)
9090
costThreshold->setSuffix(QStringLiteral("%"));
9191
costThreshold->setValue(0.01);
9292
costThreshold->setSingleStep(0.01);
93-
connect(costThreshold, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this,
93+
/*connect(costThreshold, static_cast<void (QDoubleSpinBox::*)(double)>(&QDoubleSpinBox::valueChanged), this,
9494
[diffProxy](double threshold) { diffProxy->setThreshold(threshold); });
95-
95+
*/
9696
ui->bottomUpVerticalLayout->addWidget(costThreshold);
9797
ui->bottomUpVerticalLayout->addWidget(m_contents);
9898

@@ -127,7 +127,7 @@ DiffViewWidget::DiffViewWidget(QWidget* parent)
127127
}
128128
});
129129

130-
connect(m_parserA, &PerfParser::topDownDataAvailable, this, [this](const Data::TopDownResults& results) {
130+
/*connect(m_parserA, &PerfParser::topDownDataAvailable, this, [this](const Data::TopDownResults& results) {
131131
m_resultsA = results;
132132
133133
const auto data = Data::DiffViewResults::fromTopDown(m_resultsA, m_resultsB);
@@ -145,7 +145,7 @@ DiffViewWidget::DiffViewWidget(QWidget* parent)
145145
if (data.costsA.numTypes() > 0 && data.costsB.numTypes() > 0) {
146146
m_model->setData(data);
147147
}
148-
});
148+
});*/
149149

150150
connect(m_filterAndZoomStackA, &FilterAndZoomStack::filterChanged, this, [this](const Data::FilterAction& action) {
151151
m_bFinished = true;
@@ -176,9 +176,6 @@ DiffViewWidget::~DiffViewWidget() = default;
176176

177177
void DiffViewWidget::open(const QString& a, const QString& b)
178178
{
179-
auto settings = Settings::instance();
180-
m_parserA->startParseFile(a, settings->sysroot(), settings->kallsyms(), settings->debugPaths(),
181-
settings->extraLibPaths(), settings->appPath(), settings->arch());
182-
m_parserB->startParseFile(b, settings->sysroot(), settings->kallsyms(), settings->debugPaths(),
183-
settings->extraLibPaths(), settings->appPath(), settings->arch());
179+
m_parserA->startParseFile(a);
180+
m_parserB->startParseFile(b);
184181
}

src/mainwindow.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ void MainWindow::onDiffButtonClicked()
345345
tr("Data Files (perf*.data perf.data.*);;All Files (*)"));
346346
const auto file2 = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath(),
347347
tr("Data Files (perf*.data perf.data.*);;All Files (*)"));
348-
m_pageStack->setCurrentWidget(m_diffView);
349-
m_diffView->open(file1, file2);
348+
349+
openFile(file1, false, file2);
350350
}
351351

352352
void MainWindow::onRecordButtonClicked()
@@ -377,7 +377,7 @@ void MainWindow::clear()
377377
clear(false);
378378
}
379379

380-
void MainWindow::openFile(const QString& path, bool isReload)
380+
void MainWindow::openFile(const QString& path, bool isReload, const QString& diffFile)
381381
{
382382
clear(isReload);
383383

@@ -388,9 +388,7 @@ void MainWindow::openFile(const QString& path, bool isReload)
388388
m_pageStack->setCurrentWidget(m_startPage);
389389

390390
// TODO: support input files of different types via plugins
391-
auto settings = Settings::instance();
392-
m_parser->startParseFile(path, settings->sysroot(), settings->kallsyms(), settings->debugPaths(),
393-
settings->extraLibPaths(), settings->appPath(), settings->arch());
391+
m_parser->startParseFile(path, diffFile);
394392
m_reloadAction->setData(path);
395393
m_exportAction->setData(QUrl::fromLocalFile(file.absoluteFilePath() + QLatin1String(".perfparser")));
396394

src/mainwindow.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public slots:
8080

8181
private:
8282
void clear(bool isReload);
83-
void openFile(const QString& path, bool isReload);
83+
void openFile(const QString& path, bool isReload, const QString& diffFile = QStringLiteral(""));
8484
void closeEvent(QCloseEvent* event) override;
8585
void setupCodeNavigationMenu();
8686

src/models/data.cpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -354,21 +354,40 @@ const Data::ThreadEvents* Data::EventResults::findThread(qint32 pid, qint32 tid)
354354
return const_cast<Data::EventResults*>(this)->findThread(pid, tid);
355355
}
356356

357-
DiffViewResults DiffViewResults::fromTopDown(const Data::TopDownResults& a, const Data::TopDownResults& b)
357+
BottomUpResults BottomUpResults::mergeBottomUpResults(const BottomUpResults &a, const BottomUpResults &b)
358358
{
359-
DiffViewResults results;
360-
results.costsA = a.selfCosts;
361-
results.costsB = b.selfCosts;
362-
363-
std::function<void(const TopDown&, DiffView& parent)> iterateModels = [&iterateModels, b](const TopDown& node, DiffView& parent) {
364-
DiffView diffView;
365-
diffView.costIdA = node.id;
366-
diffView.symbol = node.symbol;
359+
if (a.costs.numTypes() != b.costs.numTypes()) {
360+
return {};
361+
}
362+
363+
BottomUpResults results;
364+
365+
for (int i = 0; i < a.costs.numTypes(); i++) {
366+
results.costs.addType(i * 2, a.costs.typeName(i) + QStringLiteral(" - file A"), a.costs.unit(i));
367+
results.costs.addTotalCost(i * 2, a.costs.totalCost(i));
368+
}
369+
370+
for (int i = 0; i < b.costs.numTypes(); i++) {
371+
results.costs.addType(i * 2 + 1, b.costs.typeName(i) + QStringLiteral(" - file B"), b.costs.unit(i));
372+
results.costs.addTotalCost(i * 2 + 1, b.costs.totalCost(i));
373+
}
374+
375+
std::function<void(const BottomUp&, BottomUp& parent)> iterateModels = [&iterateModels, a, b, &results](const BottomUp& node, BottomUp& parent) {
376+
BottomUp bottomUp;
377+
bottomUp.id = node.id;
378+
bottomUp.symbol = node.symbol;
379+
380+
for (int i = 0; i < a.costs.numTypes(); i++) {
381+
results.costs.add(i * 2, bottomUp.id, a.costs.cost(i, bottomUp.id));
382+
}
383+
367384
const auto sibling = b.root.entryForSymbol(node.symbol);
368385
if (sibling) {
369-
diffView.costIdB = sibling->id;
386+
for (int i = 0; i < b.costs.numTypes(); i++) {
387+
results.costs.add(i * 2 + 1, bottomUp.id, b.costs.cost(i, sibling->id));
388+
}
370389
}
371-
parent.children.push_back(diffView);
390+
parent.children.push_back(bottomUp);
372391

373392
for (const auto& child : node.children) {
374393
iterateModels(child, parent.children.back());
@@ -379,7 +398,7 @@ DiffViewResults DiffViewResults::fromTopDown(const Data::TopDownResults& a, cons
379398
iterateModels(entry, results.root);
380399
}
381400

382-
Data::DiffView::initializeParents(&results.root);
401+
Data::BottomUp::initializeParents(&results.root);
383402

384403
return results;
385404
}

src/models/data.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ struct BottomUpResults
422422
return parent;
423423
}
424424

425+
static BottomUpResults mergeBottomUpResults(const Data::BottomUpResults& a, const Data::BottomUpResults& b);
426+
425427
private:
426428
quint32 maxBottomUpId = 0;
427429

@@ -468,21 +470,6 @@ struct TopDownResults
468470
static TopDownResults fromBottomUp(const Data::BottomUpResults& bottomUpData);
469471
};
470472

471-
struct DiffView : SymbolTree<DiffView>
472-
{
473-
quint32 costIdA = UINT32_MAX;
474-
quint32 costIdB = UINT32_MAX;
475-
};
476-
477-
struct DiffViewResults
478-
{
479-
DiffView root;
480-
Costs costsA;
481-
Costs costsB;
482-
483-
static DiffViewResults fromTopDown(const Data::TopDownResults& a, const Data::TopDownResults& b);
484-
};
485-
486473
using SymbolCostMap = QHash<Symbol, ItemCost>;
487474
using CalleeMap = SymbolCostMap;
488475
using CallerMap = SymbolCostMap;

src/models/diffviewproxy.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ bool DiffViewProxy::filterAcceptsRow(int source_row, const QModelIndex& parent)
4646
{
4747
Q_UNUSED(parent);
4848

49-
const auto model = qobject_cast<DiffViewModel*>(sourceModel());
49+
/*const auto model = qobject_cast<DiffViewModel*>(sourceModel());
5050
5151
const auto cost =
5252
model->data(model->index(source_row, DiffViewModel::NUM_BASE_COLUMNS), DiffViewModel::SortRole).toLongLong();
5353
const auto total = model->data(model->index(source_row, DiffViewModel::NUM_BASE_COLUMNS), DiffViewModel::TotalCostRole).toLongLong();
5454
55-
return cost * 100 / static_cast<double>(total) > m_threshold;
55+
return cost * 100 / static_cast<double>(total) > m_threshold;*/
56+
return false;
5657
}

src/models/treemodel.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ int TopDownModel::selfCostColumn(int cost) const
225225
return NUM_BASE_COLUMNS + m_results.inclusiveCosts.numTypes() + cost;
226226
}
227227

228-
DiffViewModel::DiffViewModel(QObject* parent)
228+
/*DiffViewModel::DiffViewModel(QObject* parent)
229229
: CostTreeModel(parent)
230230
{
231231
auto prettifySymbolsHelper = [this]() {
@@ -321,4 +321,4 @@ QVariant DiffViewModel::rowData(const Data::DiffView* row, int column, int role)
321321
int DiffViewModel::numColumns() const
322322
{
323323
return NUM_BASE_COLUMNS + m_results.costsA.numTypes() + m_results.costsB.numTypes();
324-
}
324+
}*/

src/models/treemodel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class TopDownModel : public CostTreeModel<Data::TopDownResults, TopDownModel>
323323
int selfCostColumn(int cost) const;
324324
};
325325

326-
class DiffViewModel : public CostTreeModel<Data::DiffViewResults, DiffViewModel>
326+
/*class DiffViewModel : public CostTreeModel<Data::DiffViewResults, DiffViewModel>
327327
{
328328
Q_OBJECT
329329
public:
@@ -344,4 +344,4 @@ class DiffViewModel : public CostTreeModel<Data::DiffViewResults, DiffViewModel>
344344
QVariant headerColumnData(int column, int role) const final override;
345345
QVariant rowData(const Data::DiffView* row, int column, int role) const final override;
346346
int numColumns() const final override;
347-
};
347+
};*/

0 commit comments

Comments
 (0)