skia2/tools/malisc/malisc.py
Eric Boren a1db799824 Fix Python3 compatibility
Bug: skia:11768
Change-Id: I6107362457dce380e3fb1647ad58d8e33e453e2d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/388743
Commit-Queue: Eric Boren <borenet@google.com>
Reviewed-by: Ravi Mistry <rmistry@google.com>
2021-03-25 14:15:35 +00:00

45 lines
1.2 KiB
Python

# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
from __future__ import print_function
import json
import os
import subprocess
import sys
if len(sys.argv) != 3:
print(sys.argv[0], ' <compiler> <folder>')
sys.exit(1)
compiler = sys.argv[1]
folder = sys.argv[2]
stats = {}
for filename in os.listdir(folder):
basename, ext = os.path.splitext(filename)
if ext not in ['.frag', '.spv']:
continue
cmdline = [compiler]
if ext == '.spv':
cmdline.extend(['-f', '-p'])
cmdline.append(os.path.join(folder, filename))
try:
output = subprocess.check_output(cmdline)
except subprocess.CalledProcessError:
continue
stats.setdefault(basename, {})
for line in output.splitlines():
if line.startswith('Instructions Emitted'):
inst = line.split(':')[1].split()
stats[basename][ext] = inst
for k, v in stats.iteritems():
gl = v.get('.frag', ['', '', ''])
vk = v.get('.spv', ['', '', ''])
print('{0},{1},{2},{3},{4},{5},{6}'.format(
k, gl[0], gl[1], gl[2], vk[0], vk[1], vk[2]))