summaryrefslogtreecommitdiff
path: root/src/base/statistics.hh
diff options
context:
space:
mode:
authorStephan Diestelhorst <stephan.diestelhorst@arm.com>2014-05-09 18:58:46 -0400
committerStephan Diestelhorst <stephan.diestelhorst@arm.com>2014-05-09 18:58:46 -0400
commitb9e6c260a01bab2b59d6eef4f45a642f57484275 (patch)
tree4a5e51b1c8898e4e00a8b444848b9f7186458d1d /src/base/statistics.hh
parent2b1a01ee6ccda9f046b1ceb13c90ee0635473959 (diff)
downloadgem5-b9e6c260a01bab2b59d6eef4f45a642f57484275.tar.xz
stats: Method stats source
This source for stats binds an object and a method / function from the object to a stats object. This allows pulling out stats from object methods without needing to go through a global, or static shim. Syntax is somewhat unpleasant, but the templates and method pointer type specification were quite tricky. Interface is very clean though; and similar to .functor
Diffstat (limited to 'src/base/statistics.hh')
-rw-r--r--src/base/statistics.hh35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/base/statistics.hh b/src/base/statistics.hh
index 048c1be86..fbf8ee769 100644
--- a/src/base/statistics.hh
+++ b/src/base/statistics.hh
@@ -777,6 +777,25 @@ class FunctorProxy : public ProxyInfo
Result total() const { return (*functor)(); }
};
+/**
+ * A proxy similar to the FunctorProxy, but allows calling a method of a bound
+ * object, instead of a global free-standing function.
+ */
+template <class T, class V>
+class MethodProxy : public ProxyInfo
+{
+ private:
+ T *object;
+ typedef V (T::*MethodPointer) () const;
+ MethodPointer method;
+
+ public:
+ MethodProxy(T *obj, MethodPointer meth) : object(obj), method(meth) {}
+ Counter value() const { return (object->*method)(); }
+ Result result() const { return (object->*method)(); }
+ Result total() const { return (object->*method)(); }
+};
+
template <class Derived>
class ValueBase : public DataWrap<Derived, ScalarInfoProxy>
{
@@ -805,6 +824,22 @@ class ValueBase : public DataWrap<Derived, ScalarInfoProxy>
return this->self();
}
+ /**
+ * Extended functor that calls the specified method of the provided object.
+ *
+ * @param obj Pointer to the object whose method should be called.
+ * @param method Pointer of the function / method of the object.
+ * @return Updated stats item.
+ */
+ template <class T, class V>
+ Derived &
+ method(T *obj, V (T::*method)() const)
+ {
+ proxy = new MethodProxy<T,V>(obj, method);
+ this->setInit();
+ return this->self();
+ }
+
Counter value() { return proxy->value(); }
Result result() const { return proxy->result(); }
Result total() const { return proxy->total(); };