diff options
author | José Fonseca <jfonseca@vmware.com> | 2013-04-25 15:22:53 +0100 |
---|---|---|
committer | José Fonseca <jfonseca@vmware.com> | 2013-04-26 11:43:45 +0100 |
commit | 8b9f78ba244ee2b4667d0c87a28f959b78d6e5f3 (patch) | |
tree | b392083fc77b9880180edcb696470834dd88bb95 /scripts | |
parent | 2d8f30599bebc47d1b5ba7524714ee12dae033f8 (diff) |
scripts/convert: Allow converting from PIX.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/convert.py | 96 |
1 files changed, 79 insertions, 17 deletions
diff --git a/scripts/convert.py b/scripts/convert.py index d5660c0d..e98f6d5e 100755 --- a/scripts/convert.py +++ b/scripts/convert.py @@ -35,7 +35,7 @@ import platform import sys -def convert(inTrace, outPixrun): +def getPixExe(): try: programFiles = os.environ['ProgramFiles(x86)'] except KeyError: @@ -44,14 +44,30 @@ def convert(inTrace, outPixrun): dxsdkDir = os.environ['DXSDK_DIR'] except KeyError: dxsdkDir = os.path.join(programFiles, "Microsoft DirectX SDL (June 2010)") - pix = os.path.join(dxsdkDir, "Utilities", "bin", 'x86', 'PIXwin.exe') + pixExe = os.path.join(dxsdkDir, "Utilities", "bin", 'x86', 'PIXwin.exe') + return pixExe + + +def callProcess(cmd): + if options.verbose: + sys.stderr.write(' '.join(cmd) + '\n') + ret = subprocess.call(cmd) + if ret: + exeName = os.path.basename(cmd[0]) + sys.stderr.write('error: %s failed with exit code %u\n' % (exeName, ret)) + sys.exit(ret) + return ret + + +def convertToPix(inTrace, outPixrun): + pix = getPixPath() pixExp = os.path.join(os.path.dirname(__file__), 'apitrace.PIXExp') # http://social.msdn.microsoft.com/Forums/sv/devdocs/thread/15addc0c-036d-413a-854a-35637ccbb834 # http://src.chromium.org/svn/trunk/o3d/tests/test_driver.py cmd = [ - pix, + getPixExe(), pixExp, '-start', '-runfile', os.path.abspath(outPixrun), @@ -60,22 +76,47 @@ def convert(inTrace, outPixrun): '-targetargs', os.path.abspath(inTrace), ] - if options.verbose: - sys.stderr.write(' '.join(cmd) + '\n') - - ret = subprocess.call(cmd) - if ret: - sys.stderr.write('error: pix failued with exit code %u\n' % ret) - sys.exit(ret) + callProcess(cmd) if os.path.exists(outPixrun): sys.stderr.write('info: %s written\n' % outPixrun) - if False: + if options.verify: subprocess.call([pix, os.path.abspath(outPixrun)]) else: sys.stderr.write('error: %s not written\n' % outPixrun) sys.exit(1) +def convertFromPix(inPix, outTrace): + pixExe = getPixExe() + + if False: + cmd = [ + pixExe, + inPix, + '-exporttocsv', 'c:\test.csv', + ] + callProcess(cmd) + + cmd = [ + options.apitrace, + 'trace', + '-a', options.api, + '-o', outTrace, + pixExe, + inPix, + '-playstandalone', + ] + + callProcess(cmd) + if os.path.exists(outTrace): + sys.stderr.write('info: %s written\n' % outTrace) + if options.verify: + subprocess.call([options.retrace, os.path.abspath(outTrace)]) + else: + sys.stderr.write('error: %s not written\n' % outTrace) + sys.exit(1) + + def main(): global options @@ -84,8 +125,16 @@ def main(): usage='\n\t%prog [options] <trace> ...', version='%%prog') optparser.add_option( + '--apitrace', metavar='PROGRAM', + type='string', dest='apitrace', default='apitrace.exe', + help='retrace command [default: %default]') + optparser.add_option( + '-a', '--api', metavar='API', + type='string', dest='api', default='d3d9', + help='api [default: %default]') + optparser.add_option( '-r', '--retrace', metavar='PROGRAM', - type='string', dest='retrace', default='d3dretrace', + type='string', dest='retrace', default='d3dretrace.exe', help='retrace command [default: %default]') optparser.add_option( '-v', '--verbose', @@ -95,18 +144,31 @@ def main(): '-o', '--output', metavar='FILE', type="string", dest="output", help="output file [default: stdout]") + optparser.add_option( + '--verify', + action='store_true', dest='verify', default=False, + help='verify output by replaying it') (options, args) = optparser.parse_args(sys.argv[1:]) if not args: optparser.error("incorrect number of arguments") - for arg in args: + for inFile in args: + name, inExt = os.path.splitext(os.path.basename(inFile)) + inExt = inExt + if inExt.lower() == '.trace': + convert = convertToPix + outExt = '.PIXRun' + elif inExt.lower() == '.pixrun': + convert = convertFromPix + outExt = '.trace' + else: + optparser.error("unexpected file extensions `%s`" % inExt) if options.output: - output = options.output + outFile = options.output else: - name, ext = os.path.splitext(os.path.basename(arg)) - output = name + '.PIXRun' - convert(arg, output) + outFile = name + outExt + convert(inFile, outFile) if __name__ == '__main__': |