stdlib: Add SparseHist to PyStats

This is inclusive of tests to ensure they have implemented correctly.

Change-Id: I5c84d5ffdb7b914936cfd86ca012a7b141eeaf42
This commit is contained in:
Bobby R. Bruce
2024-03-27 10:06:16 -07:00
parent b5e8804cd4
commit 178679cbfd
9 changed files with 251 additions and 0 deletions

View File

@@ -32,5 +32,6 @@ if env['CONF']['USE_TEST_OBJECTS']:
'ScalarStatTester',
'VectorStatTester',
'Vector2dStatTester',
'SparseHistStatTester',
])
Source('stat_tester.cc')

View File

@@ -87,3 +87,14 @@ class Vector2dStatTester(StatTester):
[],
"The vector stat's y subdescriptions. If empty, the subdescriptions ",
)
class SparseHistStatTester(StatTester):
type = "SparseHistStatTester"
cxx_header = "test_objects/stat_tester.hh"
cxx_class = "gem5::SparseHistStatTester"
samples = VectorParam.Float(
"The sparse histogram's sampled values, to be inserted into the "
"histogram."
)

View File

@@ -28,6 +28,8 @@
#include "test_objects/stat_tester.hh"
#include <set>
#include "base/stats/group.hh"
namespace gem5
@@ -133,4 +135,28 @@ Vector2dStatTester::Vector2dStatTesterStats::Vector2dStatTesterStats(
}
void
SparseHistStatTester::setStats()
{
for (auto sample : params.samples) {
stats.sparse_histogram.sample(sample);
}
}
SparseHistStatTester::SparseHistStatTesterStats::SparseHistStatTesterStats(
statistics::Group *parent,
const SparseHistStatTesterParams &params
) : statistics::Group(parent),
sparse_histogram(
this,
params.name.c_str(),
statistics::units::Count::get(),
params.description.c_str()
)
{
sparse_histogram.init(
(std::set(params.samples.begin(), params.samples.end())).size()
);
}
} // namespace gem5

View File

@@ -31,6 +31,7 @@
#include "base/statistics.hh"
#include "params/ScalarStatTester.hh"
#include "params/SparseHistStatTester.hh"
#include "params/StatTester.hh"
#include "params/Vector2dStatTester.hh"
#include "params/VectorStatTester.hh"
@@ -158,6 +159,27 @@ class Vector2dStatTester : public StatTester
} stats;
};
class SparseHistStatTester : public StatTester
{
private:
SparseHistStatTesterParams params;
public:
SparseHistStatTester(const SparseHistStatTesterParams &p) :
StatTester(p), params(p), stats(this, p) {}
protected:
void setStats() override;
struct SparseHistStatTesterStats : public statistics::Group
{
SparseHistStatTesterStats(
statistics::Group *parent,
const SparseHistStatTesterParams &params
);
statistics::SparseHistogram sparse_histogram;
} stats;
};
} // namespace gem5