Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: crash if samples have different amount of costs associated #636

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ repos:
args: [--allow-multiple-documents]
- id: check-json
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v14.0.0
rev: v17.0.6
hooks:
- id: clang-format
files: (\.cpp|\.h|\.c)
Expand Down
82 changes: 81 additions & 1 deletion src/models/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,87 @@ struct FrameLocation
Data::Location location;
};

using ItemCost = std::valarray<qint64>;
class ItemCost
{
public:
ItemCost(std::size_t size = 0)
: m_cost(size)
{
}

ItemCost(qint64 value, std::size_t count)
: m_cost(value, count)
{
}

ItemCost(std::valarray<qint64> cost)
: m_cost(std::move(cost))
{
}

void resize(std::size_t newSize, qint64 value = 0)
{
m_cost.resize(newSize, value);
}
std::size_t size() const
{
return m_cost.size();
}

ItemCost operator+(const ItemCost& rhs) const
{
return {m_cost + rhs.m_cost};
}

ItemCost operator-(const ItemCost& rhs) const
{
return {m_cost - rhs.m_cost};
}

ItemCost& operator+=(const ItemCost& rhs)
{
m_cost += rhs.m_cost;
return *this;
}

ItemCost& operator-=(const ItemCost& rhs)
{
m_cost -= rhs.m_cost;
return *this;
}

qint64& operator[](int index)
{
if (static_cast<std::size_t>(index) >= m_cost.size()) {
resize(index + 1);
}
return m_cost[index];
}
qint64 operator[](int index) const
{
if (static_cast<std::size_t>(index) < m_cost.size()) {
return m_cost[index];
}
return 0;
}

qint64 sum() const
{
return m_cost.sum();
}

auto begin() const
{
return std::begin(m_cost);
}
auto end() const
{
return std::end(m_cost);
}

private:
std::valarray<qint64> m_cost;
};

QDebug operator<<(QDebug stream, const ItemCost& cost);

Expand Down
2 changes: 2 additions & 0 deletions src/recordpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#include <Solid/Device>
#include <Solid/Processor>

#include <cmath>

#include "multiconfigwidget.h"
#include "perfoutputwidgetkonsole.h"
#include "perfoutputwidgettext.h"
Expand Down
3 changes: 1 addition & 2 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#pragma once

#include <valarray>
#include <QHashFunctions>
#include <QtGlobal>

Expand All @@ -20,7 +19,7 @@ struct Symbol;
struct FileLine;
struct LocationCost;
class Costs;
using ItemCost = std::valarray<qint64>;
class ItemCost;
}

namespace KParts {
Expand Down