Skip to content

Commit

Permalink
glue diffing on perfparser
Browse files Browse the repository at this point in the history
  • Loading branch information
lievenhey committed Nov 16, 2021
1 parent f952582 commit cd7a4fa
Show file tree
Hide file tree
Showing 9 changed files with 316 additions and 76 deletions.
19 changes: 17 additions & 2 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ MainWindow::MainWindow(QWidget* parent)
connect(m_startPage, &StartPage::recordButtonClicked, this, &MainWindow::onRecordButtonClicked);
connect(m_startPage, &StartPage::stopParseButtonClicked, this,
static_cast<void (MainWindow::*)()>(&MainWindow::clear));
connect(m_startPage, &StartPage::diffButtonClicked, this, [this] {
const auto fileNameA = QFileDialog::getOpenFileName(this, tr("Open File A"), QDir::currentPath(),
tr("Data Files (perf*.data perf.data.*);;All Files (*)"));
if (fileNameA.isEmpty()) {
return;
}

const auto fileNameB = QFileDialog::getOpenFileName(this, tr("Open File B"), QDir::currentPath(),
tr("Data Files (perf*.data perf.data.*);;All Files (*)"));
if (fileNameB.isEmpty()) {
return;
}

openFile(fileNameA, false, fileNameB);
});
connect(m_parser, &PerfParser::progress, m_startPage, &StartPage::onParseFileProgress);
connect(this, &MainWindow::openFileError, m_startPage, &StartPage::onOpenFileError);
connect(m_recordPage, &RecordPage::homeButtonClicked, this, &MainWindow::onHomeButtonClicked);
Expand Down Expand Up @@ -363,7 +378,7 @@ void MainWindow::clear()
clear(false);
}

void MainWindow::openFile(const QString& path, bool isReload)
void MainWindow::openFile(const QString& path, bool isReload, const QString& diffFile)
{
clear(isReload);

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

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

Expand Down
2 changes: 1 addition & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public slots:

private:
void clear(bool isReload);
void openFile(const QString& path, bool isReload);
void openFile(const QString& path, bool isReload, const QString& diffFile = QStringLiteral(""));
void closeEvent(QCloseEvent* event) override;
void setupCodeNavigationMenu();

Expand Down
50 changes: 50 additions & 0 deletions src/models/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,53 @@ const Data::ThreadEvents* Data::EventResults::findThread(qint32 pid, qint32 tid)
{
return const_cast<Data::EventResults*>(this)->findThread(pid, tid);
}

BottomUpResults BottomUpResults::mergeBottomUpResults(const BottomUpResults& a, const BottomUpResults& b)
{
if (a.costs.numTypes() != b.costs.numTypes()) {
return {};
}

BottomUpResults results;

for (int i = 0; i < a.costs.numTypes(); i++) {
results.costs.addType(i * 2, a.costs.typeName(i) + QStringLiteral(" - file A"), a.costs.unit(i));
results.costs.addTotalCost(i * 2, a.costs.totalCost(i));
}

for (int i = 0; i < b.costs.numTypes(); i++) {
results.costs.addType(i * 2 + 1, b.costs.typeName(i) + QStringLiteral(" - file B"), b.costs.unit(i));
results.costs.addTotalCost(i * 2 + 1, b.costs.totalCost(i));
}

std::function<void(const BottomUp&, BottomUp& parent)> iterateModels =
[&iterateModels, a, b, &results](const BottomUp& node, BottomUp& parent) {
BottomUp bottomUp;
bottomUp.id = node.id;
bottomUp.symbol = node.symbol;

for (int i = 0; i < a.costs.numTypes(); i++) {
results.costs.add(i * 2, bottomUp.id, a.costs.cost(i, bottomUp.id));
}

const auto sibling = b.root.entryForSymbol(node.symbol);
if (sibling) {
for (int i = 0; i < b.costs.numTypes(); i++) {
results.costs.add(i * 2 + 1, bottomUp.id, b.costs.cost(i, sibling->id));
}
}
parent.children.push_back(bottomUp);

for (const auto& child : node.children) {
iterateModels(child, parent.children.back());
}
};

for (const auto& entry : a.root.children) {
iterateModels(entry, results.root);
}

Data::BottomUp::initializeParents(&results.root);

return results;
}
2 changes: 2 additions & 0 deletions src/models/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ struct BottomUpResults
return parent;
}

static BottomUpResults mergeBottomUpResults(const Data::BottomUpResults& a, const Data::BottomUpResults& b);

private:
quint32 maxBottomUpId = 0;

Expand Down
Loading

0 comments on commit cd7a4fa

Please sign in to comment.