Skip to content

Commit cd7a4fa

Browse files
committed
glue diffing on perfparser
1 parent f952582 commit cd7a4fa

9 files changed

Lines changed: 316 additions & 76 deletions

File tree

src/mainwindow.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,21 @@ MainWindow::MainWindow(QWidget* parent)
148148
connect(m_startPage, &StartPage::recordButtonClicked, this, &MainWindow::onRecordButtonClicked);
149149
connect(m_startPage, &StartPage::stopParseButtonClicked, this,
150150
static_cast<void (MainWindow::*)()>(&MainWindow::clear));
151+
connect(m_startPage, &StartPage::diffButtonClicked, this, [this] {
152+
const auto fileNameA = QFileDialog::getOpenFileName(this, tr("Open File A"), QDir::currentPath(),
153+
tr("Data Files (perf*.data perf.data.*);;All Files (*)"));
154+
if (fileNameA.isEmpty()) {
155+
return;
156+
}
157+
158+
const auto fileNameB = QFileDialog::getOpenFileName(this, tr("Open File B"), QDir::currentPath(),
159+
tr("Data Files (perf*.data perf.data.*);;All Files (*)"));
160+
if (fileNameB.isEmpty()) {
161+
return;
162+
}
163+
164+
openFile(fileNameA, false, fileNameB);
165+
});
151166
connect(m_parser, &PerfParser::progress, m_startPage, &StartPage::onParseFileProgress);
152167
connect(this, &MainWindow::openFileError, m_startPage, &StartPage::onOpenFileError);
153168
connect(m_recordPage, &RecordPage::homeButtonClicked, this, &MainWindow::onHomeButtonClicked);
@@ -363,7 +378,7 @@ void MainWindow::clear()
363378
clear(false);
364379
}
365380

366-
void MainWindow::openFile(const QString& path, bool isReload)
381+
void MainWindow::openFile(const QString& path, bool isReload, const QString& diffFile)
367382
{
368383
clear(isReload);
369384

@@ -374,7 +389,7 @@ void MainWindow::openFile(const QString& path, bool isReload)
374389
m_pageStack->setCurrentWidget(m_startPage);
375390

376391
// TODO: support input files of different types via plugins
377-
m_parser->startParseFile(path);
392+
m_parser->startParseFile(path, diffFile);
378393
m_reloadAction->setData(path);
379394
m_exportAction->setData(QUrl::fromLocalFile(file.absoluteFilePath() + QLatin1String(".perfparser")));
380395

src/mainwindow.h

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

7979
private:
8080
void clear(bool isReload);
81-
void openFile(const QString& path, bool isReload);
81+
void openFile(const QString& path, bool isReload, const QString& diffFile = QStringLiteral(""));
8282
void closeEvent(QCloseEvent* event) override;
8383
void setupCodeNavigationMenu();
8484

src/models/data.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,53 @@ const Data::ThreadEvents* Data::EventResults::findThread(qint32 pid, qint32 tid)
353353
{
354354
return const_cast<Data::EventResults*>(this)->findThread(pid, tid);
355355
}
356+
357+
BottomUpResults BottomUpResults::mergeBottomUpResults(const BottomUpResults& a, const BottomUpResults& b)
358+
{
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 =
376+
[&iterateModels, a, b, &results](const BottomUp& node, BottomUp& parent) {
377+
BottomUp bottomUp;
378+
bottomUp.id = node.id;
379+
bottomUp.symbol = node.symbol;
380+
381+
for (int i = 0; i < a.costs.numTypes(); i++) {
382+
results.costs.add(i * 2, bottomUp.id, a.costs.cost(i, bottomUp.id));
383+
}
384+
385+
const auto sibling = b.root.entryForSymbol(node.symbol);
386+
if (sibling) {
387+
for (int i = 0; i < b.costs.numTypes(); i++) {
388+
results.costs.add(i * 2 + 1, bottomUp.id, b.costs.cost(i, sibling->id));
389+
}
390+
}
391+
parent.children.push_back(bottomUp);
392+
393+
for (const auto& child : node.children) {
394+
iterateModels(child, parent.children.back());
395+
}
396+
};
397+
398+
for (const auto& entry : a.root.children) {
399+
iterateModels(entry, results.root);
400+
}
401+
402+
Data::BottomUp::initializeParents(&results.root);
403+
404+
return results;
405+
}

src/models/data.h

Lines changed: 2 additions & 0 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

0 commit comments

Comments
 (0)