base-stats: Make Rate's compilation smarter

A Rate should be supplied units of different types.
Rates between units of the same type are Ratios,
and should be declared as such.

An exception is applied to Count and Unspecified,
since those units represent unknown underlying units.

Change-Id: I36ab7c73b239ccc86d866c5b38e14fd765bbbd0f
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/43008
Tested-by: kokoro <noreply+kokoro@google.com>
Maintainer: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-by: Hoa Nguyen <hoanguyen@ucdavis.edu>
This commit is contained in:
Daniel R. Carvalho
2021-03-13 19:06:27 -03:00
committed by Daniel Carvalho
parent aa07dbfba9
commit 219003c575

View File

@@ -272,38 +272,6 @@ class Count : public Base
std::string getUnitString() const override { return Count::toString(); }
};
template <typename T1, typename T2>
class Rate : public Base
{
static_assert(std::is_base_of<Base, T1>::value,
"Rate(T1,T2) must have T1 and T2 derived from"
"Stats::Units::Base");
static_assert(std::is_base_of<Base, T2>::value,
"Rate(T1,T2) must have T1 and T2 derived from"
"Stats::Units::Base");
private:
Rate<T1,T2>() {}
public:
Rate<T1,T2>(Rate<T1,T2> const&) = delete;
void operator=(Rate<T1,T2> const&) = delete;
static Rate<T1,T2>*
get()
{
static Rate<T1,T2> instance;
return &instance;
}
static std::string
toString()
{
return csprintf("(%s/%s)", T1::toString(), T2::toString());
}
std::string
getUnitString() const override
{
return Rate<T1,T2>::toString();
}
};
class Ratio : public Base
{
private:
@@ -342,6 +310,41 @@ class Unspecified : public Base
}
};
template <typename T1, typename T2>
class Rate : public Base
{
static_assert(std::is_base_of<Base, T1>::value,
"Rate(T1,T2) must have T1 and T2 derived from Stats::Units::Base");
static_assert(std::is_base_of<Base, T2>::value,
"Rate(T1,T2) must have T1 and T2 derived from Stats::Units::Base");
static_assert(!std::is_same<T1, T2>::value ||
std::is_same<T1, Count>::value || std::is_same<T1, Unspecified>::value,
"Rate(T1,T2) must have T1 and T2 of different types; "
"otherwise, it would be a Ratio");
private:
Rate<T1,T2>() {}
public:
Rate<T1,T2>(Rate<T1,T2> const&) = delete;
void operator=(Rate<T1,T2> const&) = delete;
static Rate<T1,T2>*
get()
{
static Rate<T1,T2> instance;
return &instance;
}
static std::string
toString()
{
return csprintf("(%s/%s)", T1::toString(), T2::toString());
}
std::string
getUnitString() const override
{
return Rate<T1,T2>::toString();
}
};
} // namespace Units
} // namespace Stats