diff --git a/src/models/data.cpp b/src/models/data.cpp index d86094fc..62efaba9 100644 --- a/src/models/data.cpp +++ b/src/models/data.cpp @@ -12,6 +12,79 @@ using namespace Data; +ItemCost::ItemCost(std::size_t size) + : m_cost(size) +{ +} + +ItemCost::ItemCost(qint64 value, std::size_t count) + : m_cost(value, count) +{ +} + +ItemCost::ItemCost(std::valarray&& cost) + : m_cost(cost) +{ +} +ItemCost::~ItemCost() = default; + +void ItemCost::resize(std::size_t newSize, qint64 value) +{ + m_cost.resize(newSize, value); +} + +std::size_t ItemCost::size() const +{ + return m_cost.size(); +} + +ItemCost ItemCost::operator+(const ItemCost& rhs) const +{ + return static_cast>(m_cost + rhs.m_cost); +} + +ItemCost ItemCost::operator-(const ItemCost& rhs) const +{ + return static_cast>(m_cost - rhs.m_cost); +} + +ItemCost& ItemCost::operator+=(const ItemCost& rhs) +{ + m_cost += rhs.m_cost; + return *this; +} + +qint64& ItemCost::operator[](int index) +{ + if (static_cast(index) < m_cost.size()) { + resize(index + 1); + } + return m_cost[index]; +} + +qint64 ItemCost::operator[](int index) const +{ + if (static_cast(index) < m_cost.size()) { + return m_cost[index]; + } + return 0; +} + +qint64 ItemCost::sum() const +{ + return m_cost.sum(); +} + +auto ItemCost::begin() const +{ + return std::begin(m_cost); +} + +auto ItemCost::end() const +{ + return std::end(m_cost); +} + namespace { ItemCost buildTopDownResult(const BottomUp& bottomUpData, const Costs& bottomUpCosts, TopDown* topDownData, @@ -338,28 +411,21 @@ void Data::callerCalleesFromBottomUpData(const BottomUpResults& bottomUpData, Ca QDebug Data::operator<<(QDebug stream, const Symbol& symbol) { - stream.noquote().nospace() << "Symbol{" - << "symbol=" << symbol.symbol << ", " - << "relAddr=" << symbol.relAddr << ", " - << "size=" << symbol.size << ", " - << "binary=" << symbol.binary << "}"; + stream.noquote().nospace() << "Symbol{" << "symbol=" << symbol.symbol << ", " << "relAddr=" << symbol.relAddr + << ", " << "size=" << symbol.size << ", " << "binary=" << symbol.binary << "}"; return stream.resetFormat().space(); } QDebug Data::operator<<(QDebug stream, const FileLine& fileLine) { - stream.noquote().nospace() << "FileLine{" - << "file=" << fileLine.file << ", " - << "line=" << fileLine.line << "}"; + stream.noquote().nospace() << "FileLine{" << "file=" << fileLine.file << ", " << "line=" << fileLine.line << "}"; return stream.resetFormat().space(); } QDebug Data::operator<<(QDebug stream, const Location& location) { - stream.noquote().nospace() << "Location{" - << "address=" << location.address << ", " - << "relAddr=" << location.relAddr << ", " - << "fileLine=" << location.fileLine << "}"; + stream.noquote().nospace() << "Location{" << "address=" << location.address << ", " + << "relAddr=" << location.relAddr << ", " << "fileLine=" << location.fileLine << "}"; return stream.resetFormat().space(); } @@ -375,10 +441,9 @@ QDebug Data::operator<<(QDebug stream, const ItemCost& cost) QDebug Data::operator<<(QDebug stream, const CostSummary& cost) { - stream.noquote().nospace() << "CostSummary{" - << "label = " << cost.label << ", " - << "sampleCount = " << cost.sampleCount << ", " - << "totalPeriod = " << cost.totalPeriod << "}"; + stream.noquote().nospace() << "CostSummary{" << "label = " << cost.label << ", " + << "sampleCount = " << cost.sampleCount << ", " << "totalPeriod = " << cost.totalPeriod + << "}"; return stream.resetFormat().space(); } diff --git a/src/models/data.h b/src/models/data.h index 6a2c0cff..a71674d1 100644 --- a/src/models/data.h +++ b/src/models/data.h @@ -203,7 +203,32 @@ struct FrameLocation Data::Location location; }; -using ItemCost = std::valarray; +class ItemCost +{ +public: + ItemCost(std::size_t size = 0); + ItemCost(qint64 value, std::size_t count); + ItemCost(std::valarray&& cost); + ~ItemCost(); + + void resize(std::size_t newSize, qint64 value = 0); + std::size_t size() const; + + ItemCost operator+(const ItemCost& rhs) const; + ItemCost operator-(const ItemCost& rhs) const; + ItemCost& operator+=(const ItemCost& rhs); + + qint64& operator[](int index); + qint64 operator[](int index) const; + + qint64 sum() const; + + auto begin() const; + auto end() const; + +private: + std::valarray m_cost; +}; QDebug operator<<(QDebug stream, const ItemCost& cost); diff --git a/src/recordpage.cpp b/src/recordpage.cpp index f29b12b0..d58325f1 100644 --- a/src/recordpage.cpp +++ b/src/recordpage.cpp @@ -40,6 +40,8 @@ #include #include +#include + #include "multiconfigwidget.h" #include "perfoutputwidgetkonsole.h" #include "perfoutputwidgettext.h" diff --git a/src/util.h b/src/util.h index cd72922d..c1ba483b 100644 --- a/src/util.h +++ b/src/util.h @@ -7,7 +7,6 @@ #pragma once -#include #include #include @@ -20,7 +19,7 @@ struct Symbol; struct FileLine; struct LocationCost; class Costs; -using ItemCost = std::valarray; +class ItemCost; } namespace KParts {