blob: dffad3f92b45d1a37ad406855420b0df00938b00 [file] [log] [blame]
José Fonseca2cce1922012-12-11 19:51:26 +00001#!/usr/bin/env python
2##########################################################################
3#
4# Copyright 2012 VMware Inc.
5# All Rights Reserved.
6#
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and associated documentation files (the 'Software'), to deal
9# in the Software without restriction, including without limitation the rights
10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11# copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included in
15# all copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23# THE SOFTWARE.
24#
25##########################################################################/
26
27'''Convert traces to/from PIX.
28'''
29
30
31import optparse
32import os.path
33import subprocess
34import platform
35import sys
36
37
38def convert(inTrace, outPixrun):
39 try:
40 dxsdkDir = os.environ['DXSDK_DIR']
41 except KeyError:
42 dxsdkDir = os.path.join(programFiles, "Microsoft DirectX SDL (June 2010)")
43 pix = os.path.join(dxsdkDir, "Utilities", "bin", 'x86', 'PIXwin.exe')
44
45 pixExp = os.path.join(os.path.dirname(__file__), 'apitrace.PIXExp')
46
47 # http://social.msdn.microsoft.com/Forums/sv/devdocs/thread/15addc0c-036d-413a-854a-35637ccbb834
48 # http://src.chromium.org/svn/trunk/o3d/tests/test_driver.py
49 cmd = [
50 pix,
51 pixExp,
52 '-start',
53 '-runfile', os.path.abspath(outPixrun),
54 '-targetpath', os.path.abspath(options.retrace),
55 #'-targetstartfolder', ...,
56 '-targetargs', os.path.abspath(inTrace),
57 ]
58
59 if options.verbose:
60 sys.stderr.write(' '.join(cmd) + '\n')
61
62 ret = subprocess.call(cmd)
63 if ret:
64 sys.stderr.write('error: pix failued with exit code %u\n' % ret)
65 sys.exit(ret)
66 if os.path.exists(outPixrun):
67 sys.stderr.write('info: %s written\n' % outPixrun)
68 if False:
69 subprocess.call([pix, os.path.abspath(outPixrun)])
70 else:
71 sys.stderr.write('error: %s not written\n' % outPixrun)
72 sys.exit(1)
73
74
75def main():
76 global options
77
78 # Parse command line options
79 optparser = optparse.OptionParser(
80 usage='\n\t%prog [options] <trace> ...',
81 version='%%prog')
82 optparser.add_option(
83 '-r', '--retrace', metavar='PROGRAM',
84 type='string', dest='retrace', default='d3dretrace',
85 help='retrace command [default: %default]')
86 optparser.add_option(
87 '-v', '--verbose',
88 action='store_true', dest='verbose', default=False,
89 help='verbose output')
90 optparser.add_option(
91 '-o', '--output', metavar='FILE',
92 type="string", dest="output",
93 help="output file [default: stdout]")
94
95 (options, args) = optparser.parse_args(sys.argv[1:])
96 if not args:
97 optparser.error("incorrect number of arguments")
98
99 for arg in args:
100 if options.output:
101 output = options.output
102 else:
103 name, ext = os.path.splitext(os.path.basename(arg))
104 output = name + '.PIXRun'
105 convert(arg, output)
106
107
108if __name__ == '__main__':
109 main()