stats: add option to disable alignment spaces in stats.txt file
authorCiro Santilli <ciro.santilli@arm.com>
Mon, 16 Mar 2020 18:02:26 +0000 (18:02 +0000)
committerCiro Santilli <ciro.santilli@arm.com>
Fri, 26 Jun 2020 11:20:28 +0000 (11:20 +0000)
The alignment spaces in stats.txt takes up a lot of space and increases
simulation time, this commit adds the option to disable them with:

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

Sample old lines with ?desc=False:

system.cpu.op_class::FloatMultAcc                   0      0.00%     65.92%
system.cpu.op_class::FloatDiv                       0      0.00%     65.92%

Sample new lines with ?desc=False;spaces=False:

system.cpu.op_class::FloatMultAcc 0 0.00% 65.92%
system.cpu.op_class::FloatDiv 0 0.00% 65.92%

On a 1000 dumpstats m5op loop spaces=False reduces:

* size: from 38MB to 20MB
* time: from 4.5s to 3.5s

Change-Id: Ib738b996b5646c329094cf61aaa1d977e844e759
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/28627
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
src/base/stats/text.cc
src/base/stats/text.hh
src/python/m5/stats/__init__.py

index 96cbe34501f4276ef027ab0439640470224a39c2..fa342a2207aca73d402ba1e2f3e377fddf059118 100644 (file)
@@ -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
  * All rights reserved.
  *
  * The license below extends only to copyright in the software and shall
@@ -95,18 +95,16 @@ namespace Stats {
 std::list<Info *> &statsList();
 
 Text::Text()
 std::list<Info *> &statsList();
 
 Text::Text()
-    : mystream(false), stream(NULL), descriptions(false)
+    : mystream(false), stream(NULL), descriptions(false), spaces(false)
 {
 }
 
 {
 }
 
-Text::Text(std::ostream &stream)
-    : mystream(false), stream(NULL), descriptions(false)
+Text::Text(std::ostream &stream) : Text()
 {
     open(stream);
 }
 
 {
     open(stream);
 }
 
-Text::Text(const std::string &file)
-    : mystream(false), stream(NULL), descriptions(false)
+Text::Text(const std::string &file) : Text()
 {
     open(file);
 }
 {
     open(file);
 }
@@ -229,10 +227,28 @@ struct ScalarPrint
     string desc;
     Flags flags;
     bool descriptions;
     string desc;
     Flags flags;
     bool descriptions;
+    bool spaces;
     int precision;
     Result pdf;
     Result cdf;
     int precision;
     Result pdf;
     Result cdf;
-
+    int nameSpaces;
+    int valueSpaces;
+    int pdfstrSpaces;
+    int cdfstrSpaces;
+
+    ScalarPrint(bool spaces) : spaces(spaces) {
+        if (spaces) {
+            nameSpaces = 40;
+            valueSpaces = 12;
+            pdfstrSpaces = 10;
+            cdfstrSpaces = 10;
+        } else {
+            nameSpaces = 0;
+            valueSpaces = 0;
+            pdfstrSpaces = 0;
+            cdfstrSpaces = 0;
+        }
+    }
     void update(Result val, Result total);
     void operator()(ostream &stream, bool oneLine = false) const;
 };
     void update(Result val, Result total);
     void operator()(ostream &stream, bool oneLine = false) const;
 };
@@ -263,12 +279,16 @@ ScalarPrint::operator()(ostream &stream, bool oneLine) const
         ccprintf(cdfstr, "%.2f%%", cdf * 100.0);
 
     if (oneLine) {
         ccprintf(cdfstr, "%.2f%%", cdf * 100.0);
 
     if (oneLine) {
-        ccprintf(stream, " |%12s %10s %10s",
-                 ValueToString(value, precision), pdfstr.str(), cdfstr.str());
+        ccprintf(stream, " |");
     } else {
     } else {
-        ccprintf(stream, "%-40s %12s %10s %10s", name,
-                 ValueToString(value, precision), pdfstr.str(), cdfstr.str());
-
+        ccprintf(stream, "%-*s ", nameSpaces, name);
+    }
+    ccprintf(stream, "%*s", valueSpaces, ValueToString(value, precision));
+    if (spaces || pdfstr.rdbuf()->in_avail())
+        ccprintf(stream, " %*s", pdfstrSpaces, pdfstr.str());
+    if (spaces || cdfstr.rdbuf()->in_avail())
+        ccprintf(stream, " %*s", cdfstrSpaces, cdfstr.str());
+    if (!oneLine) {
         if (descriptions) {
             if (!desc.empty())
                 ccprintf(stream, " # %s", desc);
         if (descriptions) {
             if (!desc.empty())
                 ccprintf(stream, " # %s", desc);
@@ -286,11 +306,21 @@ struct VectorPrint
     vector<string> subdescs;
     Flags flags;
     bool descriptions;
     vector<string> subdescs;
     Flags flags;
     bool descriptions;
+    bool spaces;
     int precision;
     VResult vec;
     Result total;
     bool forceSubnames;
     int precision;
     VResult vec;
     Result total;
     bool forceSubnames;
-
+    int nameSpaces;
+
+    VectorPrint() = delete;
+    VectorPrint(bool spaces) : spaces(spaces) {
+        if (spaces) {
+            nameSpaces = 40;
+        } else {
+            nameSpaces = 0;
+        }
+    }
     void operator()(ostream &stream) const;
 };
 
     void operator()(ostream &stream) const;
 };
 
@@ -308,7 +338,7 @@ VectorPrint::operator()(std::ostream &stream) const
 
     string base = name + separatorString;
 
 
     string base = name + separatorString;
 
-    ScalarPrint print;
+    ScalarPrint print(spaces);
     print.name = name;
     print.desc = desc;
     print.precision = precision;
     print.name = name;
     print.desc = desc;
     print.precision = precision;
@@ -332,7 +362,7 @@ VectorPrint::operator()(std::ostream &stream) const
 
     if ((!flags.isSet(nozero)) || (total != 0)) {
         if (flags.isSet(oneline)) {
 
     if ((!flags.isSet(nozero)) || (total != 0)) {
         if (flags.isSet(oneline)) {
-            ccprintf(stream, "%-40s", name);
+            ccprintf(stream, "%-*s", nameSpaces, name);
             print.flags = print.flags & (~nozero);
         }
 
             print.flags = print.flags & (~nozero);
         }
 
@@ -373,7 +403,9 @@ struct DistPrint
     string desc;
     Flags flags;
     bool descriptions;
     string desc;
     Flags flags;
     bool descriptions;
+    bool spaces;
     int precision;
     int precision;
+    int nameSpaces;
 
     const DistData &data;
 
 
     const DistData &data;
 
@@ -389,8 +421,8 @@ DistPrint::DistPrint(const Text *text, const DistInfo &info)
     init(text, info);
 }
 
     init(text, info);
 }
 
-DistPrint::DistPrint(const Text *text, const VectorDistInfo &info, int i)
-    : data(info.data[i])
+DistPrint::DistPrint(const Text *text, const VectorDistInfo &info,
+    int i) : data(info.data[i])
 {
     init(text, info);
 
 {
     init(text, info);
 
@@ -411,6 +443,12 @@ DistPrint::init(const Text *text, const Info &info)
     flags = info.flags;
     precision = info.precision;
     descriptions = text->descriptions;
     flags = info.flags;
     precision = info.precision;
     descriptions = text->descriptions;
+    spaces = text->spaces;
+    if (spaces) {
+        nameSpaces = 40;
+    } else {
+        nameSpaces = 0;
+    }
 }
 
 void
 }
 
 void
@@ -419,7 +457,7 @@ DistPrint::operator()(ostream &stream) const
     if (flags.isSet(nozero) && data.samples == 0) return;
     string base = name + separatorString;
 
     if (flags.isSet(nozero) && data.samples == 0) return;
     string base = name + separatorString;
 
-    ScalarPrint print;
+    ScalarPrint print(spaces);
     print.precision = precision;
     print.flags = flags;
     print.descriptions = descriptions;
     print.precision = precision;
     print.flags = flags;
     print.descriptions = descriptions;
@@ -488,7 +526,7 @@ DistPrint::operator()(ostream &stream) const
     }
 
     if (flags.isSet(oneline)) {
     }
 
     if (flags.isSet(oneline)) {
-        ccprintf(stream, "%-40s", name);
+        ccprintf(stream, "%-*s", nameSpaces, name);
     }
 
     for (off_type i = 0; i < size; ++i) {
     }
 
     for (off_type i = 0; i < size; ++i) {
@@ -546,7 +584,7 @@ Text::visit(const ScalarInfo &info)
     if (noOutput(info))
         return;
 
     if (noOutput(info))
         return;
 
-    ScalarPrint print;
+    ScalarPrint print(spaces);
     print.value = info.result();
     print.name = statName(info.name);
     print.desc = info.desc;
     print.value = info.result();
     print.name = statName(info.name);
     print.desc = info.desc;
@@ -566,7 +604,7 @@ Text::visit(const VectorInfo &info)
         return;
 
     size_type size = info.size();
         return;
 
     size_type size = info.size();
-    VectorPrint print;
+    VectorPrint print(spaces);
 
     print.name = statName(info.name);
     print.separatorString = info.separatorString;
 
     print.name = statName(info.name);
     print.separatorString = info.separatorString;
@@ -606,7 +644,7 @@ Text::visit(const Vector2dInfo &info)
         return;
 
     bool havesub = false;
         return;
 
     bool havesub = false;
-    VectorPrint print;
+    VectorPrint print(spaces);
 
     if (!info.y_subnames.empty()) {
         for (off_type i = 0; i < info.y; ++i) {
 
     if (!info.y_subnames.empty()) {
         for (off_type i = 0; i < info.y; ++i) {
@@ -705,6 +743,7 @@ struct SparseHistPrint
     string desc;
     Flags flags;
     bool descriptions;
     string desc;
     Flags flags;
     bool descriptions;
+    bool spaces;
     int precision;
 
     const SparseHistData &data;
     int precision;
 
     const SparseHistData &data;
@@ -731,6 +770,7 @@ SparseHistPrint::init(const Text *text, const Info &info)
     flags = info.flags;
     precision = info.precision;
     descriptions = text->descriptions;
     flags = info.flags;
     precision = info.precision;
     descriptions = text->descriptions;
+    spaces = text->spaces;
 }
 
 /* Grab data from map and write to output stream */
 }
 
 /* Grab data from map and write to output stream */
@@ -739,7 +779,7 @@ SparseHistPrint::operator()(ostream &stream) const
 {
     string base = name + separatorString;
 
 {
     string base = name + separatorString;
 
-    ScalarPrint print;
+    ScalarPrint print(spaces);
     print.precision = precision;
     print.flags = flags;
     print.descriptions = descriptions;
     print.precision = precision;
     print.flags = flags;
     print.descriptions = descriptions;
@@ -774,7 +814,7 @@ Text::visit(const SparseHistInfo &info)
 }
 
 Output *
 }
 
 Output *
-initText(const string &filename, bool desc)
+initText(const string &filename, bool desc, bool spaces)
 {
     static Text text;
     static bool connected = false;
 {
     static Text text;
     static bool connected = false;
@@ -782,6 +822,7 @@ initText(const string &filename, bool desc)
     if (!connected) {
         text.open(*simout.findOrCreate(filename)->stream());
         text.descriptions = desc;
     if (!connected) {
         text.open(*simout.findOrCreate(filename)->stream());
         text.descriptions = desc;
+        text.spaces = spaces;
         connected = true;
     }
 
         connected = true;
     }
 
index 6a2a60941727046f8342cc35067bd6a122b375c0..5762fd96c735945bcdaf830b0e368344053c2a39 100644 (file)
@@ -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
  * All rights reserved.
  *
  * The license below extends only to copyright in the software and shall
@@ -65,6 +65,7 @@ class Text : public Output
 
   public:
     bool descriptions;
 
   public:
     bool descriptions;
+    bool spaces;
 
   public:
     Text();
 
   public:
     Text();
@@ -97,7 +98,7 @@ class Text : public Output
 
 std::string ValueToString(Result value, int precision);
 
 
 std::string ValueToString(Result value, int precision);
 
-Output *initText(const std::string &filename, bool desc);
+Output *initText(const std::string &filename, bool desc, bool spaces);
 
 } // namespace Stats
 
 
 } // namespace Stats
 
index 7b810c6b6e2e1d04cd4f7281615ed96d37954d0a..1e37a14b3c3cac032d8f6291c80bcc64494999b3 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2017-2019 ARM Limited
+# Copyright (c) 2017-2020 ARM Limited
 # All rights reserved.
 #
 # The license below extends only to copyright in the software and shall
 # All rights reserved.
 #
 # The license below extends only to copyright in the software and shall
@@ -131,7 +131,7 @@ def _url_factory(schemes, enable=True):
     return decorator
 
 @_url_factory([ None, "", "text", "file", ])
     return decorator
 
 @_url_factory([ None, "", "text", "file", ])
-def _textFactory(fn, desc=True):
+def _textFactory(fn, desc=True, spaces=True):
     """Output stats in text format.
 
     Text stat files contain one stat per line with an optional
     """Output stats in text format.
 
     Text stat files contain one stat per line with an optional
@@ -140,13 +140,14 @@ def _textFactory(fn, desc=True):
 
     Parameters:
       * desc (bool): Output stat descriptions (default: True)
 
     Parameters:
       * desc (bool): Output stat descriptions (default: True)
+      * spaces (bool): Output alignment spaces (default: True)
 
     Example:
 
     Example:
-      text://stats.txt?desc=False
+      text://stats.txt?desc=False;spaces=False
 
     """
 
 
     """
 
-    return _m5.stats.initText(fn, desc)
+    return _m5.stats.initText(fn, desc, spaces)
 
 @_url_factory([ "h5", ], enable=hasattr(_m5.stats, "initHDF5"))
 def _hdf5Factory(fn, chunking=10, desc=True, formulas=True):
 
 @_url_factory([ "h5", ], enable=hasattr(_m5.stats, "initHDF5"))
 def _hdf5Factory(fn, chunking=10, desc=True, formulas=True):