1""" NNAPI systrace parser: naming conventions and translations """ 2 3 4# Application phases 5PHASE_OVERALL = "PO" # Overall program, e.g., one benchmark case 6PHASE_WARMUP = "PWU" # Executions done for warmup 7PHASE_BENCHMARK = "PBM" # Executions done to benchmark after warmup 8# Main phases 9PHASE_INITIALIZATION = "PI" # Initialization - not related to a model 10PHASE_PREPARATION = "PP" # Model construction 11PHASE_COMPILATION = "PC" # Model compilation 12PHASE_EXECUTION = "PE" # Executing the model 13PHASE_TERMINATION = "PT" # Tearing down 14PHASE_UNSPECIFIED = "PU" # Helper code called from multiple phases 15# Subphases of execution 16PHASE_INPUTS_AND_OUTPUTS = "PIO" # Setting inputs/outputs and allocating buffers 17PHASE_TRANSFORMATION = "PTR" # Transforming data for computation 18PHASE_COMPUTATION = "PCO" # Computing operations' outputs 19PHASE_RESULTS = "PR" # Reading out results 20# Layers 21LAYER_APPLICATION = "LA" 22LAYER_RUNTIME = "LR" 23LAYER_IPC = "LI" 24LAYER_DRIVER = "LD" 25LAYER_CPU = "LC" 26LAYER_OTHER = "LO" 27LAYER_UTILITY = "LU" # Code used from multiple layers 28LAYER_IGNORE = "LX" # Don't count time 29# Markers 30MARKER_SWITCH = "[SW]" 31MARKER_SUBTRACT = "[SUB]" 32 33layers = [LAYER_APPLICATION, LAYER_RUNTIME, LAYER_IPC, LAYER_DRIVER, LAYER_CPU] 34phases = [PHASE_INITIALIZATION, PHASE_PREPARATION, PHASE_COMPILATION, 35 PHASE_EXECUTION, PHASE_TERMINATION] 36subphases = dict(PE=[PHASE_INPUTS_AND_OUTPUTS, PHASE_TRANSFORMATION, 37 PHASE_COMPUTATION, PHASE_RESULTS], 38 PO=([PHASE_WARMUP, PHASE_BENCHMARK] + phases), 39 PWU=[PHASE_EXECUTION], 40 PBM=[PHASE_EXECUTION]) 41names = { PHASE_INITIALIZATION : "Initialization", PHASE_PREPARATION : "Preparation", 42 PHASE_COMPILATION : "Compilation", PHASE_INPUTS_AND_OUTPUTS: "I/O", 43 PHASE_EXECUTION: "Execution", PHASE_RESULTS: "Results", 44 PHASE_WARMUP: "Warmup", PHASE_BENCHMARK: "Benchmark", 45 PHASE_TERMINATION: "Termination", 46 LAYER_APPLICATION : "Application", LAYER_RUNTIME: "Runtime", 47 LAYER_IPC: "IPC", LAYER_DRIVER: "Driver", LAYER_CPU: "CPU", 48 "total": "Total", "NONE": "" } 49layer_order = { LAYER_APPLICATION: [LAYER_RUNTIME], 50 LAYER_RUNTIME: [LAYER_IPC, LAYER_CPU], 51 LAYER_IPC: [LAYER_DRIVER] } 52 53 54def make_tag(layer, phase): 55 return "_".join([layer, phase]) 56 57def translate_hidl_mark_to_nn_and_tag(mark): 58 layer = None 59 if "::client" in mark: 60 if "notify" in mark: 61 # Call "up" into runtime from IPC. Ignore for now to not double-count 62 layer = LAYER_IGNORE 63 else: 64 # Call "down" into IPC 65 layer = LAYER_IPC 66 elif "::server" in mark: 67 if "notify" in mark: 68 # Call "up" into IPC. Ignore for now to not double-count 69 layer = LAYER_IGNORE 70 else: 71 # Call "down" in to driver 72 layer = LAYER_DRIVER 73 elif ("getCapabilities" in mark) or ("getSupportedOperations" in mark): 74 layer = LAYER_DRIVER 75 elif "HIDL" not in mark: 76 layer = LAYER_IGNORE 77 assert layer, mark 78 79 phase = PHASE_INITIALIZATION 80 if "IAllocator" in mark: 81 # Used in both preparation and execution phases 82 phase = "PU" 83 elif ("getCapabilities" in mark): 84 phase = PHASE_INITIALIZATION 85 elif ("prepareModel" in mark) or ("getSupportedOperations" in mark): 86 phase = PHASE_COMPILATION 87 elif ("IPreparedModelCallback") in mark: 88 phase = PHASE_COMPILATION 89 elif ("execute" in mark) or ("IExecutionCallback" in mark): 90 phase = PHASE_EXECUTION 91 92 return "NN_" + make_tag(layer, phase) 93 94def get_function_name_from_mark(mark): 95 function = mark.split("|")[2] 96 if "[NN_" in function: 97 function = function.replace(MARKER_SUBTRACT, "") 98 function = function.replace(MARKER_SWITCH, "") 99 function = function.split("]")[1] 100 function = function.replace("[", "") 101 function = function.replace("]", "") 102 return function 103