]> git.cworth.org Git - apitrace/blob - scripts/convert.py
Use skiplist-based FastCallSet within trace::CallSet
[apitrace] / scripts / convert.py
1 #!/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
31 import optparse
32 import os.path
33 import subprocess
34 import platform
35 import sys
36
37
38 def convert(inTrace, outPixrun):
39     try:
40         programFiles = os.environ['ProgramFiles(x86)']
41     except KeyError:
42         programFiles = os.environ['ProgramFiles']
43     try:
44         dxsdkDir = os.environ['DXSDK_DIR']
45     except KeyError:
46         dxsdkDir = os.path.join(programFiles, "Microsoft DirectX SDL (June 2010)")
47     pix = os.path.join(dxsdkDir, "Utilities", "bin", 'x86', 'PIXwin.exe')
48
49     pixExp = os.path.join(os.path.dirname(__file__), 'apitrace.PIXExp')
50
51     # http://social.msdn.microsoft.com/Forums/sv/devdocs/thread/15addc0c-036d-413a-854a-35637ccbb834
52     # http://src.chromium.org/svn/trunk/o3d/tests/test_driver.py
53     cmd = [
54         pix,
55         pixExp,
56         '-start',
57         '-runfile', os.path.abspath(outPixrun),
58         '-targetpath', os.path.abspath(options.retrace),
59         #'-targetstartfolder', ...,
60         '-targetargs', os.path.abspath(inTrace),
61     ]
62
63     if options.verbose:
64         sys.stderr.write(' '.join(cmd) + '\n')
65
66     ret = subprocess.call(cmd)
67     if ret:
68         sys.stderr.write('error: pix failued with exit code %u\n' % ret)
69         sys.exit(ret)
70     if os.path.exists(outPixrun):
71         sys.stderr.write('info: %s written\n' % outPixrun)
72         if False:
73             subprocess.call([pix, os.path.abspath(outPixrun)])
74     else:
75         sys.stderr.write('error: %s not written\n' % outPixrun)
76         sys.exit(1)
77
78
79 def main():
80     global options
81
82     # Parse command line options
83     optparser = optparse.OptionParser(
84         usage='\n\t%prog [options] <trace> ...',
85         version='%%prog')
86     optparser.add_option(
87         '-r', '--retrace', metavar='PROGRAM',
88         type='string', dest='retrace', default='d3dretrace',
89         help='retrace command [default: %default]')
90     optparser.add_option(
91         '-v', '--verbose',
92         action='store_true', dest='verbose', default=False,
93         help='verbose output')
94     optparser.add_option(
95         '-o', '--output', metavar='FILE',
96         type="string", dest="output",
97         help="output file [default: stdout]")
98
99     (options, args) = optparser.parse_args(sys.argv[1:])
100     if not args:
101         optparser.error("incorrect number of arguments")
102     
103     for arg in args:
104         if options.output:
105             output = options.output
106         else:
107             name, ext = os.path.splitext(os.path.basename(arg))
108             output = name + '.PIXRun'
109         convert(arg, output)
110
111
112 if __name__ == '__main__':
113     main()