mem-cache: Upgrade BaseDictionaryCompressor's stats
authorDaniel R. Carvalho <odanrc@yahoo.com.br>
Thu, 7 Nov 2019 10:04:14 +0000 (11:04 +0100)
committerDaniel Carvalho <odanrc@yahoo.com.br>
Mon, 31 Aug 2020 17:45:43 +0000 (17:45 +0000)
Upgrade this compressor's stats to match current stats API.

Change-Id: I1cb69230f8deca053bc860cedafc9e6e78446df7
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/33376
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/mem/cache/compressors/base_dictionary_compressor.cc
src/mem/cache/compressors/dictionary_compressor.hh
src/mem/cache/compressors/dictionary_compressor_impl.hh

index d6af8ee775f461929c33714b3aa64d28176f454b..ebbfc1c6f5316ba7fba66b456fc1e17a31795599 100644 (file)
 namespace Compressor {
 
 BaseDictionaryCompressor::BaseDictionaryCompressor(const Params *p)
-    : Base(p), dictionarySize(p->dictionary_size), numEntries(0)
+  : Base(p), dictionarySize(p->dictionary_size),
+    numEntries(0), dictionaryStats(stats, *this)
+{
+}
+
+BaseDictionaryCompressor::DictionaryStats::DictionaryStats(
+    BaseStats& base_group, BaseDictionaryCompressor& _compressor)
+  : Stats::Group(&base_group), compressor(_compressor),
+    patterns(this, "pattern",
+        "Number of data entries that were compressed to this pattern")
 {
 }
 
 void
-BaseDictionaryCompressor::regStats()
+BaseDictionaryCompressor::DictionaryStats::regStats()
 {
-    Base::regStats();
+    Stats::Group::regStats();
 
     // We store the frequency of each pattern
-    patternStats
-        .init(getNumPatterns())
-        .name(name() + ".pattern")
-        .desc("Number of data entries that were compressed to this pattern.")
-        ;
-
-    for (unsigned i = 0; i < getNumPatterns(); ++i) {
-        patternStats.subname(i, getName(i));
-        patternStats.subdesc(i, "Number of data entries that match pattern " +
-                                getName(i));
+    patterns.init(compressor.getNumPatterns());
+    for (unsigned i = 0; i < compressor.getNumPatterns(); ++i) {
+        const std::string name = compressor.getName(i);
+        patterns.subname(i, name);
+        patterns.subdesc(i, "Number of data entries that match pattern " +
+            name);
     }
 }
 
index b9c68a1d65e786a36462786e80788a5e67402458..b5e9e673ebb20897c85eb238cbdedf67e849b5b0 100644 (file)
@@ -51,6 +51,7 @@
 #include <type_traits>
 #include <vector>
 
+#include "base/statistics.hh"
 #include "base/types.hh"
 #include "mem/cache/compressors/base.hh"
 
@@ -67,17 +68,18 @@ class BaseDictionaryCompressor : public Base
     /** Number of valid entries in the dictionary. */
     std::size_t numEntries;
 
-    /**
-     * @defgroup CompressionStats Compression specific statistics.
-     * @{
-     */
+    struct DictionaryStats : public Stats::Group
+    {
+        const BaseDictionaryCompressor& compressor;
 
-    /** Number of data entries that were compressed to each pattern. */
-    Stats::Vector patternStats;
+        DictionaryStats(BaseStats &base_group,
+            BaseDictionaryCompressor& _compressor);
 
-    /**
-     * @}
-     */
+        void regStats() override;
+
+        /** Number of data entries that were compressed to each pattern. */
+        Stats::Vector patterns;
+    } dictionaryStats;
 
     /**
      * Trick function to get the number of patterns.
@@ -98,8 +100,6 @@ class BaseDictionaryCompressor : public Base
     typedef BaseDictionaryCompressorParams Params;
     BaseDictionaryCompressor(const Params *p);
     ~BaseDictionaryCompressor() = default;
-
-    void regStats() override;
 };
 
 /**
index 0b486e3f8831b92ff4e02b97c4500cbcdf2cf48b..6b6e5fbc6eb7a491145341c2d4b4fe69104301c7 100644 (file)
@@ -104,7 +104,7 @@ DictionaryCompressor<T>::compressValue(const T data)
     }
 
     // Update stats
-    patternStats[pattern->getPatternNumber()]++;
+    dictionaryStats.patterns[pattern->getPatternNumber()]++;
 
     // Push into dictionary
     if (pattern->shouldAllocate()) {