def saveAs(self): from patrace import InputFile, OutputFile filename = str( QFileDialog.getSaveFileName(parent=self, caption="Save As Trace", directory='', filter='*.pat')) if filename: if not filename.endswith('.pat'): filename += '.pat' input_trace = InputFile() input_trace.Open(self.trace_path) output_trace = OutputFile() output_trace.Open(filename) output_trace.jsonHeader = json.dumps( json.loads(self.headerEditor.json_string)) for call in input_trace.Calls(): output_trace.WriteCall(call) input_trace.Close() output_trace.Close()
def remap(trace): remapper = Remapper() with InputFile(trace) as input: remapper.run(trace, input) return remapper.num_calls_remapped
def __init__(self, trace_path): QMainWindow.__init__(self) self.trace_path = trace_path self.setWindowTitle(trace_path) self.create_menus() self.create_tabs() from patrace import InputFile self.trace = InputFile() self.trace.Open(self.trace_path, True) self.header_version = self.trace.version self.json_header = self.trace.jsonHeader self.trace.Close() self.populateUI()
def run(self): with InputFile(self.args.file) as input: with OutputFile(self.args.newfile) as output: output.jsonHeader = input.jsonHeader for call in input.Calls(): if self.store_call(call): output.WriteCall(call) if call.name == 'eglSwapBuffers': self.current_frame += 1
def get_call_numbers(trace_path, func_name, min_call_num, max_call_num): out = list() with InputFile(trace_path) as input: for call in input.Calls(): if max_call_num and call.number > max_call_num: break if min_call_num <= call.number and call.name == func_name: out.append((call.number, str(call.name), [a.asUInt for a in call.args])) return out
def extract(file): extractor = TextureExtractor(file) if not os.path.exists(file): print("File does not exists: {}".format(file)) return with InputFile(file) as input: extractor.run(input) extractor.generate_checkerboard() extractor.generate_html()
def inject(oldfile, newfile): if not os.path.exists(oldfile): print("File does not exists: {}".format(oldfile)) return injector = Injector() with InputFile(oldfile) as input: with OutputFile(newfile) as output: injector.run(input, output) return injector.num_calls_injected
def remap(oldfile, newfile): remapper = Remapper() if not os.path.exists(oldfile): print("File does not exists: {}".format(oldfile)) return with InputFile(oldfile) as input: with OutputFile(newfile) as output: remapper.run(input, output) return remapper.num_calls_remapped
def main(): trace_filepath = sys.argv[1] if not os.path.exists(trace_filepath): print("File does not exists: {0}".format(trace_filepath)) sys.exit(1) with InputFile(trace_filepath) as input: with OutputFile('output.pat') as output: output.jsonHeader = input.jsonHeader for call in input.Calls(): OutputCall(output, call)
def main(): # try to load PATrace module if not os.curdir in sys.path: sys.path.append(os.curdir) # parse the argments parser = OptionParser() parser.add_option( '-j', '--display_json', default=False, action='store_true', dest='display_json', help= 'Just display the version and the json string in the header and exit.') (options, args) = parser.parse_args() if len(args) == 0 or not os.path.exists(args[0]): print("The input trace doesn't exist, exit.") sys.exit() if options.display_json: with InputFile(args[0], True) as trace: header_version = trace.version json_header = trace.jsonHeader print() print('Trace version : %s' % header_version) print('Trace JSON string :') print(json.dumps(json.loads(json_header), indent=4, sort_keys=True)) sys.exit() try: from PyQt4.QtGui import * except ImportError: print( 'PyQt4 (a set of Python bindings for Qt 4 that exposes much of the functionality of Qt 4 to Python) is required.' ) print( 'You can install it with "apt-get install python-qt4" under Ubuntu.' ) sys.exit() from patracetools.trace_editor_ui import MainWindow app = QApplication(sys.argv) window = MainWindow(args[0]) window.setGeometry(0, 0, 800, 600) window.show() sys.exit(app.exec_())
def main(): parser = argparse.ArgumentParser( description='Upgrade .pat trace file to use the newest binary format') parser.add_argument('file', help='Path to the .pat trace file') parser.add_argument('--newfile', default='trace_out.pat', help="Specifies the path to the output trace file") args = parser.parse_args() upgrader = Upgrader(args) with InputFile(args.file) as input: with OutputFile(args.newfile) as output: upgrader.run(input, output) print("Number of calls in trace {num}".format(num=upgrader.num_calls))
def main(): trace_filepath = sys.argv[1] if not os.path.exists(trace_filepath): print("File does not exists: {0}".format(trace_filepath)) sys.exit(1) with InputFile(trace_filepath) as input: header = json.loads(input.jsonHeader) if 'defaultTid' in header: thread_id = header['defaultTid'] with OutputFile('output.pat') as output: output.jsonHeader = input.jsonHeader for call in input.Calls(): if call.thread_id == thread_id: OutputCall(output, call, thread_id) else: output.WriteCall(call)
def main(): parser = argparse.ArgumentParser( description='Remap thread ids in a .pat trace') parser.add_argument('file', help='Path to the .pat trace file') parser.add_argument('--newfile', default='trace_out.pat', help="Specifies the path to the output trace file") parser.add_argument('--samples', type=int, default=0, help="Only functions with this name will be remapped", choices=[0, 2, 4, 8, 16]) args = parser.parse_args() with InputFile(args.file) as input: with OutputFile(args.newfile) as output: modified_fbos = change_msaa_samples(input, output, args.samples) print 'Modified FBOs: ' + str(modified_fbos)
def main(): parser = argparse.ArgumentParser(description='Change the resolution for all threads in trace') parser.add_argument('file', help='Path to the .pat trace file') parser.add_argument('width', type=int, help='Resolution width in pixels') parser.add_argument('height', type=int, help='Resolution height in pixels') parser.add_argument('--newfile', default='trace_out.pat', help="Specifies the path to the output trace file") args = parser.parse_args() with InputFile(args.file) as input: with OutputFile(args.newfile) as output: # Modify header, if we are remaping the default tid header = json.loads(input.jsonHeader) for thread in header['threads']: thread['winH'] = args.height thread['winW'] = args.width output.jsonHeader = json.dumps(header) for call in input.Calls(): output.WriteCall(call)
def main(): parser = argparse.ArgumentParser( description='Remap thread ids in a .pat trace') parser.add_argument('file', help='Path to the .pat trace file') parser.add_argument( 'oldtid', type=int, help= 'The thread id to remap. If set to -1, all thread ids will be remapped.' ) parser.add_argument('newtid', type=int, help='The new thread id') parser.add_argument('--newfile', default='trace_out.pat', help="Specifies the path to the output trace file") parser.add_argument('--include', default='', help="Only functions with this name will be remapped") parser.add_argument('--begin', type=int, default=0, help="Skip this many calls before remapping starts") parser.add_argument('--count', type=int, default=-1, help="Remap this many calls. -1 means remap all.") parser.add_argument( '--calls', metavar='N', type=int, nargs='+', help= "List of call numbers to remap. If used, all other options are ignored." ) args = parser.parse_args() remapper = Remapper(args) with InputFile(args.file) as input: with OutputFile(args.newfile) as output: remapper.run(input, output) print("Number of calls remapped {num}".format( num=remapper.num_calls_remapped))
def main(): parser = argparse.ArgumentParser( description='trim a tracefile', epilog='Remember that you wont be able to playback the trace if the ' 'range doesn\'t include resources (texture,shader,vbo) needed ' 'for selected range.') parser.add_argument('-f', '--frame_range', type=int, nargs=2, required=True, help='Specify the frame range to record drawcalls') parser.add_argument('input_trace', help='Specify the PAT trace to parse') parser.add_argument('output_trace', help='Specify name of trace to create') args = parser.parse_args() if not args.output_trace.endswith('.pat'): args.output_trace += '.pat' JSON_HEADER_FRAME_COUNT_KEY = 'frameCnt' JSON_HEADER_CALL_COUNT_KEY = 'callCnt' with InputFile(args.input_trace) as input: with OutputFile(args.output_trace) as output: jsonHeader = json.loads(input.jsonHeader) call_count = 0 for index in range(args.frame_range[0], args.frame_range[1] + 1): for call in input.FrameCalls(index): output.WriteCall(call) call_count += 1 if JSON_HEADER_FRAME_COUNT_KEY in jsonHeader: jsonHeader[JSON_HEADER_FRAME_COUNT_KEY] = args.frame_range[ 1] - args.frame_range[0] + 1 if JSON_HEADER_CALL_COUNT_KEY in jsonHeader: jsonHeader[JSON_HEADER_CALL_COUNT_KEY] = call_count output.jsonHeader = json.dumps(jsonHeader, indent=4)
class MainWindow(QMainWindow): def __init__(self, trace_path): QMainWindow.__init__(self) self.trace_path = trace_path self.setWindowTitle(trace_path) self.create_menus() self.create_tabs() from patrace import InputFile self.trace = InputFile() self.trace.Open(self.trace_path, True) self.header_version = self.trace.version self.json_header = self.trace.jsonHeader self.trace.Close() self.populateUI() def closeEvent(self, event): super(MainWindow, self).closeEvent(event) def saveAs(self): from patrace import InputFile, OutputFile filename = str( QFileDialog.getSaveFileName(parent=self, caption="Save As Trace", directory='', filter='*.pat')) if filename: if not filename.endswith('.pat'): filename += '.pat' input_trace = InputFile() input_trace.Open(self.trace_path) output_trace = OutputFile() output_trace.Open(filename) output_trace.jsonHeader = json.dumps( json.loads(self.headerEditor.json_string)) for call in input_trace.Calls(): output_trace.WriteCall(call) input_trace.Close() output_trace.Close() def create_menus(self): fileMenu = self.menuBar().addMenu(self.tr('&File')) saveAsAction = QAction(self.tr('&Save As'), self) saveAsAction.setShortcuts(QKeySequence.SaveAs) saveAsAction.triggered.connect(self.saveAs) fileMenu.addAction(saveAsAction) def create_tabs(self): # Set a tab widget as the central widget tabWidget = QTabWidget() self.setCentralWidget(tabWidget) # First tab for header editing headerView = QWidget() headerViewLayout = QGridLayout(headerView) self.headerEditor = HeaderEditor(self) tabWidget.addTab(self.headerEditor, 'Header') def populateUI(self): self.headerEditor.header_version = self.header_version if self.json_header: self.headerEditor.json_string = json.dumps(json.loads( self.json_header), indent=4, sort_keys=True)