Skip to content

Commit daeeccd

Browse files
committed
change cost type to qint64 to support negative values
1 parent d0b37e5 commit daeeccd

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

src/models/costdelegate.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ CostDelegate::~CostDelegate() = default;
4444
void CostDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
4545
{
4646
// TODO: handle negative values
47-
const auto cost = index.data(m_sortRole).toULongLong();
47+
const auto cost = index.data(m_sortRole).toLongLong();
4848
if (cost == 0) {
4949
QStyledItemDelegate::paint(painter, option, index);
5050
return;
5151
}
5252

53-
const auto totalCost = index.data(m_totalCostRole).toULongLong();
53+
const auto totalCost = index.data(m_totalCostRole).toLongLong();
5454
const auto fraction = std::abs(float(cost) / totalCost);
5555

5656
auto rect = option.rect;

src/models/data.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ class Costs
278278
m_totalCosts = rhs.m_totalCosts;
279279
}
280280

281-
QString formatCost(int type, quint64 cost) const
281+
QString formatCost(int type, qint64 cost) const
282282
{
283283
return formatCost(m_units[type], cost);
284284
}
285285

286-
static QString formatCost(Unit unit, quint64 cost)
286+
static QString formatCost(Unit unit, qint64 cost)
287287
{
288288
switch (unit) {
289289
case Unit::Time:
@@ -408,7 +408,7 @@ struct BottomUpResults
408408

409409
// callback return type is ignored, all frames will be iterated over
410410
template<typename FrameCallback>
411-
const BottomUp* addEvent(int type, quint64 cost, const QVector<qint32>& frames, FrameCallback frameCallback)
411+
const BottomUp* addEvent(int type, qint64 cost, const QVector<qint32>& frames, FrameCallback frameCallback)
412412
{
413413
costs.addTotalCost(type, cost);
414414
auto parent = &root;

src/models/topproxy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ bool TopProxy::filterAcceptsRow(int source_row, const QModelIndex& source_parent
6666
if (source_parent.isValid()) {
6767
return false;
6868
}
69-
if (!sourceModel()->index(source_row, m_costColumn, source_parent).data(sortRole()).value<quint64>()) {
69+
if (!sourceModel()->index(source_row, m_costColumn, source_parent).data(sortRole()).value<qint64>()) {
7070
return false;
7171
}
7272
return true;

src/parsers/perf/perfparser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,7 @@ void PerfParser::startParseFile(const QString& path, const QString& diffFile)
15431543
this->m_callerCalleeResults = {};
15441544

15451545
const auto diffResults =
1546-
Data::BottomUpResults::mergeBottomUpResults(m_bottomUpResults, otherResults);
1546+
Data::BottomUpResults::diffBottomUpResults(m_bottomUpResults, otherResults);
15471547
m_bottomUpResults = diffResults;
15481548
const auto topDown = Data::TopDownResults::fromBottomUp(diffResults);
15491549
Data::CallerCalleeResults callerCalleeResults;
@@ -1558,7 +1558,7 @@ void PerfParser::startParseFile(const QString& path, const QString& diffFile)
15581558
this->m_callerCalleeResults = {};
15591559

15601560
const auto diffResults =
1561-
Data::BottomUpResults::mergeBottomUpResults(results, otherResults);
1561+
Data::BottomUpResults::diffBottomUpResults(results, otherResults);
15621562
const auto topDown = Data::TopDownResults::fromBottomUp(diffResults);
15631563
Data::CallerCalleeResults callerCalleeResults;
15641564
Data::callerCalleesFromBottomUpData(diffResults, &callerCalleeResults);

src/util.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ QString Util::formatSymbol(const Data::Symbol& symbol, bool replaceEmptyString)
136136
return formatString(symbolString, replaceEmptyString);
137137
}
138138

139-
QString Util::formatCost(quint64 cost)
139+
QString Util::formatCost(qint64 cost)
140140
{
141141
// resulting format: 1.234E56
142142
return QString::number(static_cast<double>(cost), 'G', 4);
143143
}
144144

145-
QString Util::formatCostRelative(quint64 selfCost, quint64 totalCost, bool addPercentSign)
145+
QString Util::formatCostRelative(qint64 selfCost, qint64 totalCost, bool addPercentSign)
146146
{
147147
if (!totalCost) {
148148
return QString();

src/util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ struct HashCombine
6767

6868
QString formatString(const QString& input, bool replaceEmptyString = true);
6969
QString formatSymbol(const Data::Symbol& symbol, bool replaceEmptyString = true);
70-
QString formatCost(quint64 cost);
71-
QString formatCostRelative(quint64 selfCost, quint64 totalCost, bool addPercentSign = false);
70+
QString formatCost(qint64 cost);
71+
QString formatCostRelative(qint64 selfCost, qint64 totalCost, bool addPercentSign = false);
7272
QString formatTimeString(quint64 nanoseconds, bool shortForm = false);
7373
QString formatFrequency(quint64 occurrences, quint64 nanoseconds);
7474
QString formatTooltip(int id, const Data::Symbol& symbol, const Data::Costs& costs);

0 commit comments

Comments
 (0)