def main_impl(arguments): # Parse the command line options. options, categories = parse_options(arguments) # Override --atrace-categories and --ftrace-categories flags if command-line # categories are provided. if categories: if options.target == 'android': options.atrace_categories = categories elif options.target == 'linux': options.ftrace_categories = categories else: raise RuntimeError( 'Categories are only valid for atrace/ftrace. Target ' 'platform must be either Android or Linux.') if options.target == 'android' and not options.from_file: initialize_devil() if not options.device_serial_number: devices = [ a.GetDeviceSerial() for a in adb_wrapper.AdbWrapper.Devices() ] if len(devices) == 0: raise RuntimeError('No ADB devices connected.') elif len(devices) >= 2: raise RuntimeError( 'Multiple devices connected, serial number required') options.device_serial_number = devices[0] # If list_categories is selected, just print the list of categories. # In this case, use of the tracing controller is not necessary. if options.list_categories: if options.target == 'android': atrace_agent.list_categories(options) elif options.target == 'linux': ftrace_agent.list_categories(options) return # Set up the systrace runner and start tracing. controller = systrace_runner.SystraceRunner( os.path.dirname(os.path.abspath(__file__)), options) controller.StartTracing() # Wait for the given number of seconds or until the user presses enter. # pylint: disable=superfluous-parens # (need the parens so no syntax error if trying to load with Python 3) if options.from_file is not None: print('Reading results from file.') elif options.trace_time: print('Starting tracing (%d seconds)' % options.trace_time) time.sleep(options.trace_time) else: raw_input('Starting tracing (stop with enter)') # Stop tracing and collect the output. print('Tracing completed. Collecting output...') controller.StopTracing() print('Outputting Systrace results...') controller.OutputSystraceResults(write_json=options.write_json)
def main(): # Parse the command line options. options, categories = parse_options(sys.argv) initialize_devil() if options.target == 'android' and not options.device_serial_number: devices = util.get_device_serials() if len(devices) == 0: raise RuntimeError('No ADB devices connected.') elif len(devices) >= 2: raise RuntimeError( 'Multiple devices connected, serial number required') options.device_serial_number = devices[0] # If list_categories is selected, just print the list of categories. # In this case, use of the tracing controller is not necessary. if options.list_categories: if options.target == 'android': atrace_agent.list_categories(options) elif options.target == 'linux': ftrace_agent.list_categories(options) return # Set up the systrace runner and start tracing. script_dir = os.path.dirname(os.path.abspath(__file__)) controller = systrace_runner.SystraceRunner(script_dir, options, categories) controller.StartTracing() # Wait for the given number of seconds or until the user presses enter. # pylint: disable=superfluous-parens # (need the parens so no syntax error if trying to load with Python 3) if options.from_file is not None: print('Reading results from file.') elif options.trace_time: print('Starting tracing (%d seconds)' % options.trace_time) time.sleep(options.trace_time) else: raw_input('Starting tracing (stop with enter)') # Stop tracing and collect the output. print('Tracing completed. Collecting output...') controller.StopTracing() print('Outputting Systrace results...') controller.OutputSystraceResults(write_json=options.write_json)