<s> import os <EOL> import subprocess <EOL> import shutil <EOL> from wlauto import Instrument , Parameter <EOL> from wlauto . utils . types import list_of_strings , boolean <EOL> from wlauto . utils . misc import check_output <EOL> from wlauto . exceptions import ConfigError , InstrumentError <EOL> class systrace ( Instrument ) : <EOL> name = '<STR_LIT>' <EOL> description = """<STR_LIT>""" <EOL> parameters = [ <EOL> Parameter ( '<STR_LIT>' , kind = int , default = <NUM_LIT> , <EOL> description = """<STR_LIT>""" ) , <EOL> Parameter ( '<STR_LIT>' , kind = boolean , default = False , <EOL> description = """<STR_LIT>""" ) , <EOL> Parameter ( '<STR_LIT>' , kind = list_of_strings , <EOL> description = """<STR_LIT>""" ) , <EOL> Parameter ( '<STR_LIT>' , kind = list_of_strings , <EOL> default = [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> description = """<STR_LIT>""" ) , <EOL> Parameter ( '<STR_LIT>' , kind = list_of_strings , <EOL> description = """<STR_LIT>""" ) , <EOL> Parameter ( "<STR_LIT>" , kind = boolean , default = False , <EOL> description = """<STR_LIT>""" ) , <EOL> Parameter ( "<STR_LIT>" , kind = boolean , default = True , <EOL> description = """<STR_LIT>""" ) <EOL> ] <EOL> def initialize ( self , context ) : <EOL> cmd_options = { } <EOL> if context . device . get_sdk_version ( ) >= <NUM_LIT> : <EOL> if self . app_names : <EOL> cmd_options [ "<STR_LIT>" ] = "<STR_LIT:U+002C>" . join ( self . app_names ) <EOL> if self . buffer_size : <EOL> cmd_options [ "<STR_LIT>" ] = self . buffer_size <EOL> if self . use_circular_buffer : <EOL> cmd_options [ "<STR_LIT:-c>" ] = None <EOL> if self . kernel_functions : <EOL> cmd_options [ "<STR_LIT>" ] = "<STR_LIT:U+002C>" . join ( self . kernel_functions ) <EOL> if self . ignore_signals : <EOL> cmd_options [ "<STR_LIT>" ] = None <EOL> opt_string = '<STR_LIT>' . join ( [ '<STR_LIT>' . format ( name , value or "<STR_LIT>" ) <EOL> for name , value in cmd_options . iteritems ( ) ] ) <EOL> self . start_cmd = "<STR_LIT>" . format ( opt_string , <EOL> "<STR_LIT:U+0020>" . join ( self . categories ) ) <EOL> self . output_file = os . path . join ( self . device . working_directory , "<STR_LIT>" ) <EOL> self . stop_cmd = "<STR_LIT>" . format ( "<STR_LIT>" if self . compress_trace else "<STR_LIT>" , <EOL> self . output_file ) <EOL> available_categories = [ cat . strip ( ) . split ( "<STR_LIT>" ) [ <NUM_LIT:0> ] for cat in <EOL> context . device . execute ( "<STR_LIT>" ) . splitlines ( ) ] <EOL> for category in self . categories : <EOL> if category not in available_categories : <EOL> raise ConfigError ( "<STR_LIT>" <EOL> . format ( category , available_categories ) ) <EOL> else : <EOL> raise InstrumentError ( "<STR_LIT>" ) <EOL> def setup ( self , context ) : <EOL> self . device . execute ( "<STR_LIT>" ) <EOL> def start ( self , context ) : <EOL> result = self . device . execute ( self . start_cmd ) <EOL> if "<STR_LIT:error>" in result : <EOL> raise InstrumentError ( result ) <EOL> def stop ( self , context ) : <EOL> self . p = self . device . execute ( self . stop_cmd , background = True ) <EOL> def update_result ( self , context ) : <EOL> self . logger . debug ( "<STR_LIT>" ) <EOL> self . p . wait ( ) <EOL> context . device . pull_file ( self . output_file , context . output_directory ) <EOL> cmd = "<STR_LIT>" <EOL> cmd = cmd . format ( os . path . join ( os . environ [ '<STR_LIT>' ] , <EOL> "<STR_LIT>" ) , <EOL> os . path . join ( context . output_directory , "<STR_LIT>" ) , <EOL> os . path . join ( context . output_directory , "<STR_LIT>" ) ) <EOL> self . logger . debug ( cmd ) <EOL> _ , error = check_output ( cmd . split ( "<STR_LIT:U+0020>" ) , timeout = <NUM_LIT:10> ) <EOL> if error : <EOL> raise InstrumentError ( error ) <EOL> context . add_iteration_artifact ( '<STR_LIT>' , <EOL> path = os . path . join ( context . output_directory , <EOL> "<STR_LIT>" ) , <EOL> kind = '<STR_LIT:data>' , <EOL> description = '<STR_LIT>' ) <EOL> context . add_iteration_artifact ( '<STR_LIT>' , <EOL> path = os . path . join ( context . output_directory , <EOL> "<STR_LIT>" ) , <EOL> kind = '<STR_LIT:data>' , <EOL> description = '<STR_LIT>' ) </s>
