Brian Osman | 5aa11fb | 2019-04-08 16:40:36 -0400 | [diff] [blame] | 1 | # Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | import json |
| 6 | import os |
| 7 | import subprocess |
| 8 | import sys |
| 9 | |
| 10 | if len(sys.argv) != 3: |
| 11 | print sys.argv[0], ' <compiler> <folder>' |
| 12 | sys.exit(1) |
| 13 | |
| 14 | compiler = sys.argv[1] |
| 15 | folder = sys.argv[2] |
| 16 | |
Brian Osman | be2062c | 2019-04-15 09:26:13 -0400 | [diff] [blame^] | 17 | stats = {} |
Brian Osman | 5aa11fb | 2019-04-08 16:40:36 -0400 | [diff] [blame] | 18 | |
Brian Osman | be2062c | 2019-04-15 09:26:13 -0400 | [diff] [blame^] | 19 | for filename in os.listdir(folder): |
| 20 | basename, ext = os.path.splitext(filename) |
| 21 | if ext not in ['.frag', '.spv']: |
| 22 | continue |
| 23 | cmdline = [compiler] |
| 24 | if ext == '.spv': |
| 25 | cmdline.extend(['-f', '-p']) |
| 26 | cmdline.append(os.path.join(folder, filename)) |
Brian Osman | 5aa11fb | 2019-04-08 16:40:36 -0400 | [diff] [blame] | 27 | try: |
Brian Osman | be2062c | 2019-04-15 09:26:13 -0400 | [diff] [blame^] | 28 | output = subprocess.check_output(cmdline) |
Brian Osman | 5aa11fb | 2019-04-08 16:40:36 -0400 | [diff] [blame] | 29 | except subprocess.CalledProcessError: |
| 30 | continue |
Brian Osman | be2062c | 2019-04-15 09:26:13 -0400 | [diff] [blame^] | 31 | stats.setdefault(basename, {}) |
Brian Osman | 5aa11fb | 2019-04-08 16:40:36 -0400 | [diff] [blame] | 32 | for line in output.splitlines(): |
| 33 | if line.startswith('Instructions Emitted'): |
| 34 | inst = line.split(':')[1].split() |
Brian Osman | be2062c | 2019-04-15 09:26:13 -0400 | [diff] [blame^] | 35 | stats[basename][ext] = inst |
| 36 | |
| 37 | for k, v in stats.iteritems(): |
| 38 | gl = v.get('.frag', ['', '', '']) |
| 39 | vk = v.get('.spv', ['', '', '']) |
| 40 | print '{0},{1},{2},{3},{4},{5},{6}'.format(k, gl[0], gl[1], gl[2], vk[0], vk[1], vk[2]) |