FWIW I've avoided looking at the "affected" stats, since IMHO they're
meaningless. A lot of people like to look at them to increase the
apparent significance of their optimization. If a change reduces a
shader's instructions by 99%, it's not that big of a deal if it's the
only shader where it does anything out of thousands/millions in the
shader library.

On to the implementation, I'd prefer having a "include" instead
"exclude" in here... and you can then alternatively pass
x.stats.iterkeys() (or None perhaps, to imply that) or just the list
of stats you want to analyze.

Also, having a mutable default argument is a recipe for disaster. It
doesn't matter here, but it's an object reference that gets stored,
and mutating that argument will cause the value of later invocations
to change.

On Fri, Aug 3, 2018 at 3:53 PM, Rhys Perry <pendingchao...@gmail.com> wrote:
> Signed-off-by: Rhys Perry <pendingchao...@gmail.com>
> ---
>  nv-report.py | 28 +++++++++++++++++++---------
>  1 file changed, 19 insertions(+), 9 deletions(-)
>
> diff --git a/nv-report.py b/nv-report.py
> index 487074fdd6..079b2e08a3 100644
> --- a/nv-report.py
> +++ b/nv-report.py
> @@ -46,11 +46,13 @@ class Stats(object):
>          assert name not in self.stats, name
>          self.stats[name] = stat
>
> -    def create_totals(self):
> +    def create_totals(self, exclude=set()):
>          for attr in STATS:
>              setattr(self, attr, 0)
>
>          for key, stat in self.stats.iteritems():
> +            if key in exclude:
> +                continue
>              for attr in STATS:
>                  setattr(self, attr, getattr(self, attr) + getattr(stat, 
> attr))
>
> @@ -83,14 +85,20 @@ def diff(a, b):
>          percentage = float('inf')
>      return "%d -> %d (%.2f%%)" % (a, b, percentage)
>
> -def print_summary(before, after):
> -    before.create_totals()
> -    after.create_totals()
> +def print_summary(before, after, keys, only_affected):
> +    exclude = set()
> +    for key in keys if only_affected else []:
> +        if before.stats[key] == after.stats[key]:
> +            exclude.add(key)
> +    before.create_totals(exclude)
> +    after.create_totals(exclude)
> +
> +    programs = "affected" if only_affected else "shared"
>
> -    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 "total instructions in %s programs :" % programs, 
> diff(before.inst, after.inst)
> +    print "total gprs used in %s programs    :" % programs, diff(before.gpr, 
> after.gpr)
> +    print "total shared used in %s programs  :" % programs, 
> diff(before.shared, after.shared)
> +    print "total local used in %s programs   :" % programs, 
> diff(before.local, after.local)
>
>  def print_helped_hurt(keys, before, after):
>      helped = Stat()
> @@ -132,7 +140,9 @@ def main(argv):
>              continue
>          keys.add(key)
>
> -    print_summary(before, after)
> +    print_summary(before, after, keys, False)
> +    print
> +    print_summary(before, after, keys, True)
>      print
>      print_helped_hurt(keys, before, after)
>
> --
> 2.14.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to