Ciro Santilli has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/28629 )

Change subject: stats: add option to remove names from all stats but first dump
......................................................................

stats: add option to remove names from all stats but first dump

With:

--stats-file stats.txt?names=False

names are only printed on the first dump of the run, e.g.:

---------- Begin Simulation Statistics ----------
system.cpu0.Branches 21667
system.cpu0.committedInsts 105034
---------- End Simulation Statistics   ----------

---------- Begin Simulation Statistics ----------
21673
105054
---------- End Simulation Statistics   ----------

---------- Begin Simulation Statistics ----------
21683
105094
---------- End Simulation Statistics   ----------

For this to work, stats that were omitted due to the nozero and nonan must
always be printed however to have the same number of lines per dump, but I
have observed a 5x reduction in dump sizes in a simple se.py loop setup, so
it is still highly worth it in that setup.

The use case is for users that are already post-processing the dumps after
the run is over to datamine it, so they don't need the names every time
for visual inspection.

Change-Id: Ibe589997511536bdc9f510e78b5e99bd09fff0bc
---
M src/base/stats/hdf5.cc
M src/base/stats/hdf5.hh
M src/base/stats/output.hh
M src/base/stats/text.cc
M src/base/stats/text.hh
M src/python/m5/stats/__init__.py
6 files changed, 85 insertions(+), 51 deletions(-)



diff --git a/src/base/stats/hdf5.cc b/src/base/stats/hdf5.cc
index 963be6e..ca1ce22 100644
--- a/src/base/stats/hdf5.cc
+++ b/src/base/stats/hdf5.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016-2019 Arm Limited
+ * Copyright (c) 2016-2020 Arm Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -83,7 +83,7 @@
 }

 void
-Hdf5::end()
+Hdf5::doEnd()
 {
     assert(valid());

diff --git a/src/base/stats/hdf5.hh b/src/base/stats/hdf5.hh
index 8944a55..89be2c9 100644
--- a/src/base/stats/hdf5.hh
+++ b/src/base/stats/hdf5.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016-2019 Arm Limited
+ * Copyright (c) 2016-2020 Arm Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -63,7 +63,7 @@

   public: // Output interface
     void begin() override;
-    void end() override;
+    void doEnd() override;
     bool valid() const override;

     void beginGroup(const char *name) override;
diff --git a/src/base/stats/output.hh b/src/base/stats/output.hh
index 6ff4a5d..df70f27 100644
--- a/src/base/stats/output.hh
+++ b/src/base/stats/output.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Arm Limited
+ * Copyright (c) 2019-2020 Arm Limited
  * All rights reserved.
  *
  * The license below extends only to copyright in the software and shall
@@ -57,10 +57,19 @@

 struct Output
 {
+  protected:
+    bool firstBegin;
+
+  public:
+    Output() : firstBegin(true) {}
     virtual ~Output() {}

     virtual void begin() = 0;
-    virtual void end() = 0;
+    void end() {
+        doEnd();
+        firstBegin = false;
+    }
+    virtual void doEnd() = 0;
     virtual bool valid() const = 0;

     virtual void beginGroup(const char *name) = 0;
diff --git a/src/base/stats/text.cc b/src/base/stats/text.cc
index fa342a2..aabcc0c 100644
--- a/src/base/stats/text.cc
+++ b/src/base/stats/text.cc
@@ -95,7 +95,8 @@
 std::list<Info *> &statsList();

 Text::Text()
-    : mystream(false), stream(NULL), descriptions(false), spaces(false)
+    : mystream(false), stream(NULL), descriptions(false), spaces(false),
+      names(false)
 {
 }

@@ -155,7 +156,7 @@
 }

 void
-Text::end()
+Text::doEnd()
 {
ccprintf(*stream, "\n---------- End Simulation Statistics ----------\n");
     stream->flush();
@@ -228,6 +229,7 @@
     Flags flags;
     bool descriptions;
     bool spaces;
+    bool names;
     int precision;
     Result pdf;
     Result cdf;
@@ -250,7 +252,8 @@
         }
     }
     void update(Result val, Result total);
-    void operator()(ostream &stream, bool oneLine = false) const;
+    void operator()(ostream &stream, bool oneLine = false,
+            bool firstBegin = false) const;
 };

 void
@@ -264,10 +267,12 @@
 }

 void
-ScalarPrint::operator()(ostream &stream, bool oneLine) const
+ScalarPrint::operator()(ostream &stream, bool oneLine, bool firstBegin) const
 {
-    if ((flags.isSet(nozero) && (!oneLine) && value == 0.0) ||
-        (flags.isSet(nonan) && std::isnan(value)))
+    if (names && (
+        (flags.isSet(nozero) && (!oneLine) && value == 0.0) ||
+        (flags.isSet(nonan) && std::isnan(value))
+    ))
         return;

     stringstream pdfstr, cdfstr;
@@ -281,7 +286,9 @@
     if (oneLine) {
         ccprintf(stream, " |");
     } else {
-        ccprintf(stream, "%-*s ", nameSpaces, name);
+        if (names || firstBegin) {
+            ccprintf(stream, "%-*s ", nameSpaces, name);
+        }
     }
     ccprintf(stream, "%*s", valueSpaces, ValueToString(value, precision));
     if (spaces || pdfstr.rdbuf()->in_avail())
@@ -307,6 +314,7 @@
     Flags flags;
     bool descriptions;
     bool spaces;
+    bool names;
     int precision;
     VResult vec;
     Result total;
@@ -321,11 +329,11 @@
             nameSpaces = 0;
         }
     }
-    void operator()(ostream &stream) const;
+    void operator()(ostream &stream, bool firstBegin) const;
 };

 void
-VectorPrint::operator()(std::ostream &stream) const
+VectorPrint::operator()(std::ostream &stream, bool firstBegin) const
 {
     size_type _size = vec.size();
     Result _total = 0.0;
@@ -340,6 +348,7 @@

     ScalarPrint print(spaces);
     print.name = name;
+    print.names = names;
     print.desc = desc;
     print.precision = precision;
     print.descriptions = descriptions;
@@ -356,13 +365,15 @@
         if (forceSubnames)
print.name = base + (havesub ? subnames[0] : std::to_string(0));
         print.value = vec[0];
-        print(stream);
+        print(stream, false, firstBegin);
         return;
     }

     if ((!flags.isSet(nozero)) || (total != 0)) {
         if (flags.isSet(oneline)) {
-            ccprintf(stream, "%-*s", nameSpaces, name);
+            if (names || firstBegin) {
+                ccprintf(stream, "%-*s", nameSpaces, name);
+            }
             print.flags = print.flags & (~nozero);
         }

@@ -374,7 +385,7 @@
             print.desc = subdescs.empty() ? desc : subdescs[i];

             print.update(vec[i], _total);
-            print(stream, flags.isSet(oneline));
+            print(stream, flags.isSet(oneline), firstBegin);
         }

         if (flags.isSet(oneline)) {
@@ -392,7 +403,7 @@
         print.name = base + "total";
         print.desc = desc;
         print.value = total;
-        print(stream);
+        print(stream, false, firstBegin);
     }
 }

@@ -404,6 +415,7 @@
     Flags flags;
     bool descriptions;
     bool spaces;
+    bool names;
     int precision;
     int nameSpaces;

@@ -412,7 +424,7 @@
     DistPrint(const Text *text, const DistInfo &info);
     DistPrint(const Text *text, const VectorDistInfo &info, int i);
     void init(const Text *text, const Info &info);
-    void operator()(ostream &stream) const;
+    void operator()(ostream &stream, bool firstBegin) const;
 };

 DistPrint::DistPrint(const Text *text, const DistInfo &info)
@@ -449,15 +461,17 @@
     } else {
         nameSpaces = 0;
     }
+    names = text->names;
 }

 void
-DistPrint::operator()(ostream &stream) const
+DistPrint::operator()(ostream &stream, bool firstBegin) const
 {
-    if (flags.isSet(nozero) && data.samples == 0) return;
+    if (names && flags.isSet(nozero) && data.samples == 0) return;
     string base = name + separatorString;

     ScalarPrint print(spaces);
+    print.names = names;
     print.precision = precision;
     print.flags = flags;
     print.descriptions = descriptions;
@@ -468,29 +482,29 @@
     if (flags.isSet(oneline)) {
         print.name = base + "bucket_size";
         print.value = data.bucket_size;
-        print(stream);
+        print(stream, false, firstBegin);

         print.name = base + "min_bucket";
         print.value = data.min;
-        print(stream);
+        print(stream, false, firstBegin);

         print.name = base + "max_bucket";
         print.value = data.max;
-        print(stream);
+        print(stream, false, firstBegin);
     }

     print.name = base + "samples";
     print.value = data.samples;
-    print(stream);
+    print(stream, false, firstBegin);

     print.name = base + "mean";
     print.value = data.samples ? data.sum / data.samples : NAN;
-    print(stream);
+    print(stream, false, firstBegin);

     if (data.type == Hist) {
         print.name = base + "gmean";
         print.value = data.samples ? exp(data.logs / data.samples) : NAN;
-        print(stream);
+        print(stream, false, firstBegin);
     }

     Result stdev = NAN;
@@ -499,7 +513,7 @@
                      (data.samples * (data.samples - 1.0)));
     print.name = base + "stdev";
     print.value = stdev;
-    print(stream);
+    print(stream, false, firstBegin);

     if (data.type == Deviation)
         return;
@@ -522,7 +536,7 @@
     if (data.type == Dist && data.underflow != NAN) {
         print.name = base + "underflows";
         print.update(data.underflow, total);
-        print(stream);
+        print(stream, false, firstBegin);
     }

     if (flags.isSet(oneline)) {
@@ -541,7 +555,7 @@

         print.name = namestr.str();
         print.update(data.cvec[i], total);
-        print(stream, flags.isSet(oneline));
+        print(stream, flags.isSet(oneline), firstBegin);
     }

     if (flags.isSet(oneline)) {
@@ -555,7 +569,7 @@
     if (data.type == Dist && data.overflow != NAN) {
         print.name = base + "overflows";
         print.update(data.overflow, total);
-        print(stream);
+        print(stream, false, firstBegin);
     }

     print.pdf = NAN;
@@ -564,18 +578,18 @@
     if (data.type == Dist && data.min_val != NAN) {
         print.name = base + "min_value";
         print.value = data.min_val;
-        print(stream);
+        print(stream, false, firstBegin);
     }

     if (data.type == Dist && data.max_val != NAN) {
         print.name = base + "max_value";
         print.value = data.max_val;
-        print(stream);
+        print(stream, false, firstBegin);
     }

     print.name = base + "total";
     print.value = total;
-    print(stream);
+    print(stream, false, firstBegin);
 }

 void
@@ -585,6 +599,7 @@
         return;

     ScalarPrint print(spaces);
+    print.names = names;
     print.value = info.result();
     print.name = statName(info.name);
     print.desc = info.desc;
@@ -594,7 +609,7 @@
     print.pdf = NAN;
     print.cdf = NAN;

-    print(*stream);
+    print(*stream, false, firstBegin);
 }

 void
@@ -611,6 +626,7 @@
     print.desc = info.desc;
     print.flags = info.flags;
     print.descriptions = descriptions;
+    print.names = names;
     print.precision = info.precision;
     print.vec = info.result();
     print.total = info.total();
@@ -634,7 +650,7 @@
         }
     }

-    print(*stream);
+    print(*stream, firstBegin);
 }

 void
@@ -657,6 +673,7 @@
     print.flags = info.flags;
     print.separatorString = info.separatorString;
     print.descriptions = descriptions;
+    print.names = names;
     print.precision = info.precision;
     print.forceSubnames = true;

@@ -687,7 +704,7 @@
         print.desc = info.desc;
         print.vec = yvec;
         print.total = total;
-        print(*stream);
+        print(*stream, firstBegin);
     }

     // Create a subname for printing the total
@@ -700,7 +717,7 @@
         print.desc = info.desc;
         print.vec = VResult(1, info.total());
         print.flags = print.flags & ~total;
-        print(*stream);
+        print(*stream, firstBegin);
     }
 }

@@ -711,7 +728,7 @@
         return;

     DistPrint print(this, info);
-    print(*stream);
+    print(*stream, firstBegin);
 }

 void
@@ -722,7 +739,7 @@

     for (off_type i = 0; i < info.size(); ++i) {
         DistPrint print(this, info, i);
-        print(*stream);
+        print(*stream, firstBegin);
     }
 }

@@ -744,13 +761,14 @@
     Flags flags;
     bool descriptions;
     bool spaces;
+    bool names;
     int precision;

     const SparseHistData &data;

     SparseHistPrint(const Text *text, const SparseHistInfo &info);
     void init(const Text *text, const Info &info);
-    void operator()(ostream &stream) const;
+    void operator()(ostream &stream, bool firstBegin) const;
 };

 /* Call initialization function */
@@ -771,15 +789,17 @@
     precision = info.precision;
     descriptions = text->descriptions;
     spaces = text->spaces;
+    names = text->names;
 }

 /* Grab data from map and write to output stream */
 void
-SparseHistPrint::operator()(ostream &stream) const
+SparseHistPrint::operator()(ostream &stream, bool firstBegin) const
 {
     string base = name + separatorString;

     ScalarPrint print(spaces);
+    print.names = names;
     print.precision = precision;
     print.flags = flags;
     print.descriptions = descriptions;
@@ -789,7 +809,7 @@

     print.name = base + "samples";
     print.value = data.samples;
-    print(stream);
+    print(stream, false, firstBegin);

     MCounter::const_iterator it;
     for (it = data.cmap.begin(); it != data.cmap.end(); it++) {
@@ -799,7 +819,7 @@
         namestr <<(*it).first;
         print.name = namestr.str();
         print.value = (*it).second;
-        print(stream);
+        print(stream, false, firstBegin);
     }
 }

@@ -810,11 +830,11 @@
         return;

     SparseHistPrint print(this, info);
-    print(*stream);
+    print(*stream, firstBegin);
 }

 Output *
-initText(const string &filename, bool desc, bool spaces)
+initText(const string &filename, bool desc, bool spaces, bool names)
 {
     static Text text;
     static bool connected = false;
@@ -823,6 +843,7 @@
         text.open(*simout.findOrCreate(filename)->stream());
         text.descriptions = desc;
         text.spaces = spaces;
+        text.names = names;
         connected = true;
     }

diff --git a/src/base/stats/text.hh b/src/base/stats/text.hh
index 5762fd9..93841db 100644
--- a/src/base/stats/text.hh
+++ b/src/base/stats/text.hh
@@ -66,6 +66,7 @@
   public:
     bool descriptions;
     bool spaces;
+    bool names;

   public:
     Text();
@@ -93,12 +94,13 @@
     // Implement Output
     bool valid() const override;
     void begin() override;
-    void end() override;
+    void doEnd() override;
 };

 std::string ValueToString(Result value, int precision);

-Output *initText(const std::string &filename, bool desc, bool spaces);
+Output *initText(const std::string &filename,
+        bool desc, bool spaces, bool names);

 } // namespace Stats

diff --git a/src/python/m5/stats/__init__.py b/src/python/m5/stats/__init__.py
index 6c4a42c..34a8923 100644
--- a/src/python/m5/stats/__init__.py
+++ b/src/python/m5/stats/__init__.py
@@ -131,7 +131,7 @@
     return decorator

 @_url_factory([ None, "", "text", "file", ])
-def _textFactory(fn, desc=True, spaces=True):
+def _textFactory(fn, desc=True, spaces=True, names=True):
     """Output stats in text format.

     Text stat files contain one stat per line with an optional
@@ -141,13 +141,15 @@
     Parameters:
       * desc (bool): Output stat descriptions (default: True)
       * spaces (bool): Output alignment spaces (default: True)
+      * names (bool): Output stat names on dumps besides the first one
+                        (default: True)

     Example:
       text://stats.txt?desc=False;spaces=False

     """

-    return _m5.stats.initText(fn, desc, spaces)
+    return _m5.stats.initText(fn, desc, spaces, names)

 @_url_factory([ "h5", ], enable=hasattr(_m5.stats, "initHDF5"))
 def _hdf5Factory(fn, chunking=10, desc=True, formulas=True):

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/28629
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: Ibe589997511536bdc9f510e78b5e99bd09fff0bc
Gerrit-Change-Number: 28629
Gerrit-PatchSet: 1
Gerrit-Owner: Ciro Santilli <ciro.santi...@arm.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to