Daniel Carvalho has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/45413 )
Change subject: base-stats: Create base struct for print structs
......................................................................
base-stats: Create base struct for print structs
Reduce code duplication.
Change-Id: I4d31b80ef946d9c1d964910e861088cdd2472f7c
Signed-off-by: Daniel R. Carvalho <[email protected]>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/45413
Maintainer: Jason Lowe-Power <[email protected]>
Tested-by: kokoro <[email protected]>
Reviewed-by: Hoa Nguyen <[email protected]>
---
M src/base/stats/text.cc
1 file changed, 65 insertions(+), 94 deletions(-)
Approvals:
Hoa Nguyen: Looks good to me, approved
Jason Lowe-Power: Looks good to me, approved
kokoro: Regressions pass
diff --git a/src/base/stats/text.cc b/src/base/stats/text.cc
index 17d1e3b..8c0ff5f 100644
--- a/src/base/stats/text.cc
+++ b/src/base/stats/text.cc
@@ -194,17 +194,47 @@
return val.str();
}
-struct ScalarPrint
+struct BasePrint
+{
+ std::string name;
+ Flags flags;
+ int precision;
+ bool descriptions;
+ std::string desc;
+ bool units;
+ std::string unitStr;
+ bool spaces;
+
+ BasePrint(bool _spaces=false) : spaces(_spaces) {}
+
+ void
+ setup(std::string _name, Flags _flags, int _precision,
+ bool enable_descriptions, std::string _desc,
+ bool enable_units, std::string unit_str,
+ bool enable_spaces)
+ {
+ name = _name;
+ flags = _flags;
+ precision = _precision;
+ descriptions = enable_descriptions;
+ desc = _desc;
+ units = enable_units;
+ unitStr = unit_str;
+ spaces = enable_spaces;
+ }
+
+ void
+ printUnits(std::ostream &stream) const
+ {
+ if (units && !unitStr.empty()) {
+ ccprintf(stream, " (%s)", unitStr);
+ }
+ }
+};
+
+struct ScalarPrint : public BasePrint
{
Result value;
- std::string name;
- std::string desc;
- std::string unitStr;
- Flags flags;
- bool descriptions;
- bool spaces;
- bool units;
- int precision;
Result pdf;
Result cdf;
int nameSpaces;
@@ -212,7 +242,9 @@
int pdfstrSpaces;
int cdfstrSpaces;
- ScalarPrint(bool spaces) : spaces(spaces) {
+ ScalarPrint(bool spaces)
+ : BasePrint(spaces)
+ {
if (spaces) {
nameSpaces = 40;
valueSpaces = 12;
@@ -269,33 +301,25 @@
if (!desc.empty())
ccprintf(stream, " # %s", desc);
}
- if (units && !unitStr.empty()) {
- ccprintf(stream, " (%s)", unitStr);
- }
+ printUnits(stream);
stream << std::endl;
}
}
-struct VectorPrint
+struct VectorPrint : public BasePrint
{
- std::string name;
std::string separatorString;
- std::string desc;
- std::string unitStr;
std::vector<std::string> subnames;
std::vector<std::string> subdescs;
- Flags flags;
- bool units;
- bool descriptions;
- bool spaces;
- int precision;
VResult vec;
Result total;
bool forceSubnames;
int nameSpaces;
VectorPrint() = delete;
- VectorPrint(bool spaces) : spaces(spaces) {
+ VectorPrint(bool spaces)
+ : BasePrint(spaces)
+ {
if (spaces) {
nameSpaces = 40;
} else {
@@ -320,13 +344,8 @@
std::string base = name + separatorString;
ScalarPrint print(spaces);
- print.name = name;
- print.desc = desc;
- print.unitStr = unitStr;
- print.precision = precision;
- print.descriptions = descriptions;
- print.units = units;
- print.flags = flags;
+ print.setup(name, flags, precision, descriptions, desc, units, unitStr,
+ spaces);
print.pdf = _total ? 0.0 : Nan;
print.cdf = _total ? 0.0 : Nan;
@@ -366,9 +385,7 @@
if (!desc.empty())
ccprintf(stream, " # %s", desc);
}
- if (units && !unitStr.empty()) {
- ccprintf(stream, " (%s)", unitStr);
- }
+ printUnits(stream);
stream << std::endl;
}
}
@@ -384,17 +401,9 @@
}
}
-struct DistPrint
+struct DistPrint : public BasePrint
{
- std::string name;
std::string separatorString;
- std::string desc;
- std::string unitStr;
- Flags flags;
- bool units;
- bool descriptions;
- bool spaces;
- int precision;
int nameSpaces;
const DistData &data;
@@ -429,15 +438,10 @@
void
DistPrint::init(const Text *text, const Info &info)
{
- name = text->statName(info.name);
+ setup(text->statName(info.name), info.flags, info.precision,
+ text->descriptions, info.desc, text->units,
info.unit->getUnitString(),
+ text->spaces);
separatorString = info.separatorString;
- desc = info.desc;
- unitStr = info.unit->getUnitString();
- flags = info.flags;
- precision = info.precision;
- descriptions = text->descriptions;
- units = text->units;
- spaces = text->spaces;
if (spaces) {
nameSpaces = 40;
} else {
@@ -544,9 +548,7 @@
if (!desc.empty())
ccprintf(stream, " # %s", desc);
}
- if (units && !unitStr.empty()) {
- ccprintf(stream, " (%s)", unitStr);
- }
+ printUnits(stream);
stream << std::endl;
}
@@ -583,14 +585,9 @@
return;
ScalarPrint print(spaces);
+ print.setup(statName(info.name), info.flags, info.precision,
descriptions,
+ info.desc, units, info.unit->getUnitString(), spaces);
print.value = info.result();
- print.name = statName(info.name);
- print.desc = info.desc;
- print.unitStr = info.unit->getUnitString();
- print.flags = info.flags;
- print.descriptions = descriptions;
- print.units = units;
- print.precision = info.precision;
print.pdf = Nan;
print.cdf = Nan;
@@ -605,15 +602,9 @@
size_type size = info.size();
VectorPrint print(spaces);
-
- print.name = statName(info.name);
+ print.setup(statName(info.name), info.flags, info.precision,
descriptions,
+ info.desc, units, info.unit->getUnitString(), spaces);
print.separatorString = info.separatorString;
- print.desc = info.desc;
- print.unitStr = info.unit->getUnitString();
- print.flags = info.flags;
- print.descriptions = descriptions;
- print.units = units;
- print.precision = info.precision;
print.vec = info.result();
print.total = info.total();
print.forceSubnames = false;
@@ -647,7 +638,6 @@
bool havesub = false;
VectorPrint print(spaces);
-
if (!info.y_subnames.empty()) {
for (off_type i = 0; i < info.y; ++i) {
if (!info.y_subnames[i].empty()) {
@@ -741,17 +731,9 @@
This struct implements the output methods for the sparse
histogram stat
*/
-struct SparseHistPrint
+struct SparseHistPrint : public BasePrint
{
- std::string name;
std::string separatorString;
- std::string desc;
- std::string unitStr;
- Flags flags;
- bool descriptions;
- bool units;
- bool spaces;
- int precision;
const SparseHistData &data;
@@ -771,15 +753,10 @@
void
SparseHistPrint::init(const Text *text, const Info &info)
{
- name = text->statName(info.name);
+ setup(text->statName(info.name), info.flags, info.precision,
+ text->descriptions, info.desc, text->units,
+ info.unit->getUnitString(), text->spaces);
separatorString = info.separatorString;
- desc = info.desc;
- unitStr = info.unit->getUnitString();
- flags = info.flags;
- precision = info.precision;
- descriptions = text->descriptions;
- units = text->units;
- spaces = text->spaces;
}
/* Grab data from map and write to output stream */
@@ -789,16 +766,10 @@
std::string base = name + separatorString;
ScalarPrint print(spaces);
- print.precision = precision;
- print.flags = flags;
- print.descriptions = descriptions;
- print.units = units;
- print.desc = desc;
- print.unitStr = unitStr;
+ print.setup(base + "samples", flags, precision, descriptions, desc,
units,
+ unitStr, spaces);
print.pdf = Nan;
print.cdf = Nan;
-
- print.name = base + "samples";
print.value = data.samples;
print(stream);
5 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the
submitted one.
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/45413
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I4d31b80ef946d9c1d964910e861088cdd2472f7c
Gerrit-Change-Number: 45413
Gerrit-PatchSet: 8
Gerrit-Owner: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Hoa Nguyen <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s