Ciro Santilli has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/28627 )

Change subject: stats: add option to disable alignment spaces in stats.txt file
......................................................................

stats: add option to disable alignment spaces in stats.txt file

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.sandb...@arm.com>
Maintainer: Andreas Sandberg <andreas.sandb...@arm.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/base/stats/text.cc
M src/base/stats/text.hh
M src/python/m5/stats/__init__.py
3 files changed, 71 insertions(+), 28 deletions(-)

Approvals:
  Andreas Sandberg: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/base/stats/text.cc b/src/base/stats/text.cc
index 96cbe34..fa342a2 100644
--- a/src/base/stats/text.cc
+++ b/src/base/stats/text.cc
@@ -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
@@ -95,18 +95,16 @@
 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);
 }

-Text::Text(const std::string &file)
-    : mystream(false), stream(NULL), descriptions(false)
+Text::Text(const std::string &file) : Text()
 {
     open(file);
 }
@@ -229,10 +227,28 @@
     string desc;
     Flags flags;
     bool descriptions;
+    bool spaces;
     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;
 };
@@ -263,12 +279,16 @@
         ccprintf(cdfstr, "%.2f%%", cdf * 100.0);

     if (oneLine) {
-        ccprintf(stream, " |%12s %10s %10s",
- ValueToString(value, precision), pdfstr.str(), cdfstr.str());
+        ccprintf(stream, " |");
     } 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);
@@ -286,11 +306,21 @@
     vector<string> subdescs;
     Flags flags;
     bool descriptions;
+    bool spaces;
     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;
 };

@@ -308,7 +338,7 @@

     string base = name + separatorString;

-    ScalarPrint print;
+    ScalarPrint print(spaces);
     print.name = name;
     print.desc = desc;
     print.precision = precision;
@@ -332,7 +362,7 @@

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

@@ -373,7 +403,9 @@
     string desc;
     Flags flags;
     bool descriptions;
+    bool spaces;
     int precision;
+    int nameSpaces;

     const DistData &data;

@@ -389,8 +421,8 @@
     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);

@@ -411,6 +443,12 @@
     flags = info.flags;
     precision = info.precision;
     descriptions = text->descriptions;
+    spaces = text->spaces;
+    if (spaces) {
+        nameSpaces = 40;
+    } else {
+        nameSpaces = 0;
+    }
 }

 void
@@ -419,7 +457,7 @@
     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;
@@ -488,7 +526,7 @@
     }

     if (flags.isSet(oneline)) {
-        ccprintf(stream, "%-40s", name);
+        ccprintf(stream, "%-*s", nameSpaces, name);
     }

     for (off_type i = 0; i < size; ++i) {
@@ -546,7 +584,7 @@
     if (noOutput(info))
         return;

-    ScalarPrint print;
+    ScalarPrint print(spaces);
     print.value = info.result();
     print.name = statName(info.name);
     print.desc = info.desc;
@@ -566,7 +604,7 @@
         return;

     size_type size = info.size();
-    VectorPrint print;
+    VectorPrint print(spaces);

     print.name = statName(info.name);
     print.separatorString = info.separatorString;
@@ -606,7 +644,7 @@
         return;

     bool havesub = false;
-    VectorPrint print;
+    VectorPrint print(spaces);

     if (!info.y_subnames.empty()) {
         for (off_type i = 0; i < info.y; ++i) {
@@ -705,6 +743,7 @@
     string desc;
     Flags flags;
     bool descriptions;
+    bool spaces;
     int precision;

     const SparseHistData &data;
@@ -731,6 +770,7 @@
     flags = info.flags;
     precision = info.precision;
     descriptions = text->descriptions;
+    spaces = text->spaces;
 }

 /* Grab data from map and write to output stream */
@@ -739,7 +779,7 @@
 {
     string base = name + separatorString;

-    ScalarPrint print;
+    ScalarPrint print(spaces);
     print.precision = precision;
     print.flags = flags;
     print.descriptions = descriptions;
@@ -774,7 +814,7 @@
 }

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

diff --git a/src/base/stats/text.hh b/src/base/stats/text.hh
index 6a2a609..5762fd9 100644
--- a/src/base/stats/text.hh
+++ b/src/base/stats/text.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
@@ -65,6 +65,7 @@

   public:
     bool descriptions;
+    bool spaces;

   public:
     Text();
@@ -97,7 +98,7 @@

 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

diff --git a/src/python/m5/stats/__init__.py b/src/python/m5/stats/__init__.py
index 7b810c6..1e37a14 100644
--- a/src/python/m5/stats/__init__.py
+++ b/src/python/m5/stats/__init__.py
@@ -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
@@ -131,7 +131,7 @@
     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
@@ -140,13 +140,14 @@

     Parameters:
       * desc (bool): Output stat descriptions (default: True)
+      * spaces (bool): Output alignment spaces (default: True)

     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):

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/28627
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: Ib738b996b5646c329094cf61aaa1d977e844e759
Gerrit-Change-Number: 28627
Gerrit-PatchSet: 5
Gerrit-Owner: Ciro Santilli <ciro.santi...@arm.com>
Gerrit-Reviewer: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Ciro Santilli <ciro.santi...@arm.com>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
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