[Mesa-dev] [PATCH shader-db v2 3/5] nv-report: additionally report changes in only affected programs

Ilia Mirkin imirkin at alum.mit.edu
Sun Aug 5 15:46:18 UTC 2018


On Sun, Aug 5, 2018 at 8:06 AM, Rhys Perry <pendingchaos02 at gmail.com> wrote:
> v2: change compute_totals() to take an include instead of an exclude list
> v2: show number of affected programs
> v2: flip around the shared and affected statistics
>
> Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
> ---
>  nv-report.py | 35 +++++++++++++++++++++++++----------
>  1 file changed, 25 insertions(+), 10 deletions(-)
>
> diff --git a/nv-report.py b/nv-report.py
> index 91007625ff..5049207c22 100644
> --- a/nv-report.py
> +++ b/nv-report.py
> @@ -35,6 +35,9 @@ class Stat(object):
>                  return False
>          return True
>
> +    def __ne__(self, other):
> +        return not (self == other)
> +
>  class Stats(object):
>
>      def __init__(self):
> @@ -46,9 +49,9 @@ class Stats(object):
>          assert name not in self.stats, name
>          self.stats[name] = stat
>
> -    def compute_totals(self):
> +    def compute_totals(self, stat_keys):
>          for attr in STATS:
> -            stats = self.stats.itervalues()
> +            stats = [self.stats[key] for key in stat_keys]

Your call, but making this a generator would avoid the copy. i.e.

stats = (self.stats[key] for key in stat_keys)

This would mean that the logic would run each time you iterate, but
since you only iterate once...

>              setattr(self, attr, sum(getattr(stat, attr) for stat in stats))

Or alternatively, this could be

... sum(getattr(self.stats[key], attr) for key in stat_keys)

which is probably the simplest option.

Also come to think of it, this is the wrong abstraction. Ideally the
caller would create a new Stats object with just the stats that need
analysis. But we've already spent way too much time on this, so I
don't really care.

>
>  RE = {
> @@ -80,14 +83,24 @@ def diff(a, b):
>          percentage = float('inf')
>      return "%d -> %d (%.2f%%)" % (a, b, percentage)
>
> -def print_summary(before, after):
> -    before.compute_totals()
> -    after.compute_totals()
> +def print_summary(before, after, keys, only_affected):
> +    if only_affected:
> +        stat_keys = [key for key in keys if before.stats[key] != after.stats[key]]
> +    else:
> +        stat_keys = keys
> +    before.compute_totals(stat_keys)
> +    after.compute_totals(stat_keys)
>
> -    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)
> +    if only_affected:
> +        affected = len(stat_keys)
> +        programs = "%d (%.2f%%) affected programs" % (affected, affected/float(len(keys))*100.0)
> +    else:
> +        programs = "shared programs"
> +
> +    print "total instructions in %s :" % programs, diff(before.inst, after.inst)
> +    print "total gprs used in %s    :" % programs, diff(before.gpr, after.gpr)
> +    print "total shared used in %s  :" % programs, diff(before.shared, after.shared)
> +    print "total local used in %s   :" % programs, diff(before.local, after.local)
>
>  def print_helped_hurt(keys, before, after):
>      helped = Stat()
> @@ -129,7 +142,9 @@ def main(argv):
>              continue
>          keys.add(key)
>
> -    print_summary(before, after)
> +    print_summary(before, after, keys, True)
> +    print
> +    print_summary(before, after, keys, False)
>      print
>      print_helped_hurt(keys, before, after)
>
> --
> 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