[Mesa-dev] [PATCH shader-db 2/5] nv-report: move code out of main()

Ilia Mirkin imirkin at alum.mit.edu
Fri Aug 3 21:20:45 UTC 2018


On Fri, Aug 3, 2018 at 3:53 PM, Rhys Perry <pendingchaos02 at gmail.com> wrote:
> Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
> ---
>  nv-report.py | 49 +++++++++++++++++++++++++++++++++----------------
>  1 file changed, 33 insertions(+), 16 deletions(-)
>
> diff --git a/nv-report.py b/nv-report.py
> index 3f0be63557..487074fdd6 100644
> --- a/nv-report.py
> +++ b/nv-report.py
> @@ -45,8 +45,14 @@ class Stats(object):
>      def record(self, name, stat):
>          assert name not in self.stats, name
>          self.stats[name] = stat
> +
> +    def create_totals(self):

compute_totals makes more sense to me.

>          for attr in STATS:
> -            setattr(self, attr, getattr(self, attr) + getattr(stat, attr))
> +            setattr(self, attr, 0)
> +
> +        for key, stat in self.stats.iteritems():
> +            for attr in STATS:
> +                setattr(self, attr, getattr(self, attr) + getattr(stat, attr))

Confusing way of doing it, no?

for attr in STATS:
  setattr(self, attr, sum(getattr(stat, attr) for stat in
self.stats.itervalues()))

should do the trick.

>
>  RE = {
>          "name":   re.compile(r"^(.*) - "),
> @@ -54,7 +60,7 @@ RE = {
>  for attr in ["type"] + STATS:
>      RE[attr] = re.compile(attr + ": (\d+)")
>
> -def analyze(fname):
> +def read_stats(fname):
>      stats = Stats()
>      with open(fname, "r") as f:
>          for line in f.xreadlines():
> @@ -77,19 +83,19 @@ def diff(a, b):
>          percentage = float('inf')
>      return "%d -> %d (%.2f%%)" % (a, b, percentage)
>
> -def main(argv):
> -    # Count up each of the metrics in the before and after, and
> -    # produce hurt/helped comparisons.
> -    before = analyze(argv[1])
> -    after = analyze(argv[2])
> -    keys = set(before.stats.keys()) | set(after.stats.keys())
> +def print_summary(before, after):
> +    before.create_totals()
> +    after.create_totals()
> +
> +    print "total instructions in shared programs :", diff(before.inst, after.inst)
> +    print "total gprs used in shared programs    :", diff(before.gpr, after.gpr)
> +    print "total shared used in shared programs  :", diff(before.shared, after.shared)
> +    print "total local used in shared programs   :", diff(before.local, after.local)
>
> +def print_helped_hurt(keys, before, after):
>      helped = Stat()
>      hurt = Stat()
>      for key in keys:
> -        if key not in after.stats or key not in before.stats:
> -            print "Missing", key
> -            continue
>          a = after.stats[key]
>          b = before.stats[key]
>          if a != b:
> @@ -105,11 +111,6 @@ def main(argv):
>                      setattr(hurt, attr,
>                              getattr(hurt, attr) + 1)
>
> -    print "total instructions in shared programs :", diff(before.inst, after.inst)
> -    print "total gprs used in shared programs    :", diff(before.gpr, after.gpr)
> -    print "total shared used in shared programs  :", diff(before.shared, after.shared)
> -    print "total local used in shared programs   :", diff(before.local, after.local)
> -    print
>      print ("%10s " * (len(STATS) + 1)) % tuple([""] + STATS)
>      print "%10s " % "helped",
>      for attr in STATS:
> @@ -118,6 +119,22 @@ def main(argv):
>      print "%10s " % "hurt",
>      for attr in STATS:
>          print "%10d " % getattr(hurt, attr),
> +    print
> +
> +def main(argv):
> +    before = read_stats(argv[1])
> +    after = read_stats(argv[2])
> +
> +    keys = set()
> +    for key in set(before.stats.keys()) | set(after.stats.keys()):
> +        if key not in after.stats or key not in before.stats:
> +            print "Missing", key
> +            continue
> +        keys.add(key)
> +
> +    print_summary(before, after)
> +    print
> +    print_helped_hurt(keys, before, after)
>
>
>  if __name__ == "__main__":
> --
> 2.14.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list