Skip to content

Commit

Permalink
change cost type to qint64 to support negative values
Browse files Browse the repository at this point in the history
  • Loading branch information
lievenhey committed Dec 3, 2021
1 parent d0b37e5 commit daeeccd
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/models/costdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ CostDelegate::~CostDelegate() = default;
void CostDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
// TODO: handle negative values
const auto cost = index.data(m_sortRole).toULongLong();
const auto cost = index.data(m_sortRole).toLongLong();
if (cost == 0) {
QStyledItemDelegate::paint(painter, option, index);
return;
}

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

auto rect = option.rect;
Expand Down
6 changes: 3 additions & 3 deletions src/models/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ class Costs
m_totalCosts = rhs.m_totalCosts;
}

QString formatCost(int type, quint64 cost) const
QString formatCost(int type, qint64 cost) const
{
return formatCost(m_units[type], cost);
}

static QString formatCost(Unit unit, quint64 cost)
static QString formatCost(Unit unit, qint64 cost)
{
switch (unit) {
case Unit::Time:
Expand Down Expand Up @@ -408,7 +408,7 @@ struct BottomUpResults

// callback return type is ignored, all frames will be iterated over
template<typename FrameCallback>
const BottomUp* addEvent(int type, quint64 cost, const QVector<qint32>& frames, FrameCallback frameCallback)
const BottomUp* addEvent(int type, qint64 cost, const QVector<qint32>& frames, FrameCallback frameCallback)
{
costs.addTotalCost(type, cost);
auto parent = &root;
Expand Down
2 changes: 1 addition & 1 deletion src/models/topproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bool TopProxy::filterAcceptsRow(int source_row, const QModelIndex& source_parent
if (source_parent.isValid()) {
return false;
}
if (!sourceModel()->index(source_row, m_costColumn, source_parent).data(sortRole()).value<quint64>()) {
if (!sourceModel()->index(source_row, m_costColumn, source_parent).data(sortRole()).value<qint64>()) {
return false;
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/parsers/perf/perfparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ void PerfParser::startParseFile(const QString& path, const QString& diffFile)
this->m_callerCalleeResults = {};

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

const auto diffResults =
Data::BottomUpResults::mergeBottomUpResults(results, otherResults);
Data::BottomUpResults::diffBottomUpResults(results, otherResults);
const auto topDown = Data::TopDownResults::fromBottomUp(diffResults);
Data::CallerCalleeResults callerCalleeResults;
Data::callerCalleesFromBottomUpData(diffResults, &callerCalleeResults);
Expand Down
4 changes: 2 additions & 2 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ QString Util::formatSymbol(const Data::Symbol& symbol, bool replaceEmptyString)
return formatString(symbolString, replaceEmptyString);
}

QString Util::formatCost(quint64 cost)
QString Util::formatCost(qint64 cost)
{
// resulting format: 1.234E56
return QString::number(static_cast<double>(cost), 'G', 4);
}

QString Util::formatCostRelative(quint64 selfCost, quint64 totalCost, bool addPercentSign)
QString Util::formatCostRelative(qint64 selfCost, qint64 totalCost, bool addPercentSign)
{
if (!totalCost) {
return QString();
Expand Down
4 changes: 2 additions & 2 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ struct HashCombine

QString formatString(const QString& input, bool replaceEmptyString = true);
QString formatSymbol(const Data::Symbol& symbol, bool replaceEmptyString = true);
QString formatCost(quint64 cost);
QString formatCostRelative(quint64 selfCost, quint64 totalCost, bool addPercentSign = false);
QString formatCost(qint64 cost);
QString formatCostRelative(qint64 selfCost, qint64 totalCost, bool addPercentSign = false);
QString formatTimeString(quint64 nanoseconds, bool shortForm = false);
QString formatFrequency(quint64 occurrences, quint64 nanoseconds);
QString formatTooltip(int id, const Data::Symbol& symbol, const Data::Costs& costs);
Expand Down

0 comments on commit daeeccd

Please sign in to comment.