stdlib: Add tests for PyStats's Vector and fix bugs
The big thing missing from the Vector stats was that each position in the vector could have it's own unique id (a str, float, or int) and each position in the vector can have its own description. Therefore, to add this the Vector is represented as a dictionary mapping the unique ID to a Pystat Scaler (whcih can have it's own unique description. Change-Id: I3a8634f43298f6491300cf5a4f9d25dee8101808
This commit is contained in:
@@ -27,5 +27,9 @@
|
||||
Import ("*")
|
||||
|
||||
if env['CONF']['USE_TEST_OBJECTS']:
|
||||
SimObject('StatTester.py', sim_objects=['StatTester', 'ScalarStatTester'])
|
||||
SimObject('StatTester.py', sim_objects=[
|
||||
'StatTester',
|
||||
'ScalarStatTester',
|
||||
'VectorStatTester',
|
||||
])
|
||||
Source('stat_tester.cc')
|
||||
|
||||
@@ -44,3 +44,21 @@ class ScalarStatTester(StatTester):
|
||||
cxx_class = "gem5::ScalarStatTester"
|
||||
|
||||
value = Param.Float("The scalar stat's value.")
|
||||
|
||||
|
||||
class VectorStatTester(StatTester):
|
||||
type = "VectorStatTester"
|
||||
cxx_header = "test_objects/stat_tester.hh"
|
||||
cxx_class = "gem5::VectorStatTester"
|
||||
|
||||
values = VectorParam.Float("The vector stat's values.")
|
||||
subnames = VectorParam.String(
|
||||
[],
|
||||
"The vector stat's subnames. If position is empty, index int is "
|
||||
"used instead.",
|
||||
)
|
||||
subdescs = VectorParam.String(
|
||||
[],
|
||||
"The vector stat's subdescriptions. If empty, the subdescriptions "
|
||||
"are not used.",
|
||||
)
|
||||
|
||||
@@ -51,4 +51,37 @@ ScalarStatTester::ScalarStatTesterStats::ScalarStatTesterStats(
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
VectorStatTester::setStats()
|
||||
{
|
||||
for (int i = 0; i < params.values.size(); i++)
|
||||
{
|
||||
stats.vector[i] = (params.values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
VectorStatTester::VectorStatTesterStats::VectorStatTesterStats(
|
||||
statistics::Group *parent,
|
||||
const VectorStatTesterParams ¶ms
|
||||
) : statistics::Group(parent),
|
||||
vector(this,
|
||||
params.name.c_str(),
|
||||
statistics::units::Count::get(),
|
||||
params.description.c_str()
|
||||
)
|
||||
{
|
||||
vector.init(params.values.size());
|
||||
for (int i = 0; i < params.values.size(); i++)
|
||||
{
|
||||
if (params.subnames.size() > i) {
|
||||
vector.subname(i, params.subnames[i]);
|
||||
} else {
|
||||
vector.subname(i, std::to_string(i));
|
||||
}
|
||||
if (params.subdescs.size() > i) {
|
||||
vector.subdesc(i, params.subdescs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace gem5
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "base/statistics.hh"
|
||||
#include "params/ScalarStatTester.hh"
|
||||
#include "params/StatTester.hh"
|
||||
#include "params/VectorStatTester.hh"
|
||||
#include "sim/sim_object.hh"
|
||||
|
||||
namespace gem5
|
||||
@@ -114,6 +115,27 @@ class ScalarStatTester : public StatTester
|
||||
} stats;
|
||||
};
|
||||
|
||||
class VectorStatTester : public StatTester
|
||||
{
|
||||
private:
|
||||
VectorStatTesterParams params;
|
||||
|
||||
public:
|
||||
VectorStatTester(const VectorStatTesterParams &p) :
|
||||
StatTester(p), params(p), stats(this, p) {}
|
||||
|
||||
protected:
|
||||
void setStats() override;
|
||||
struct VectorStatTesterStats : public statistics::Group
|
||||
{
|
||||
VectorStatTesterStats(
|
||||
statistics::Group *parent,
|
||||
const VectorStatTesterParams ¶ms
|
||||
);
|
||||
statistics::Vector vector;
|
||||
} stats;
|
||||
};
|
||||
|
||||
} // namespace gem5
|
||||
|
||||
#endif // __STAT_TESTER_HH__
|
||||
|
||||
Reference in New Issue
Block a user