Home | History | Annotate | Download | only in parser
      1 """ NNAPI systrace parser: naming conventions and translations """
      2 
      3 
      4 # Application phases
      5 PHASE_OVERALL = "PO"      # Overall program, e.g., one benchmark case
      6 PHASE_WARMUP = "PWU"      # Executions done for warmup
      7 PHASE_BENCHMARK = "PBM"   # Executions done to benchmark after warmup
      8 # Main phases
      9 PHASE_INITIALIZATION = "PI" # Initialization - not related to a model
     10 PHASE_PREPARATION = "PP"  # Model construction
     11 PHASE_COMPILATION = "PC"  # Model compilation
     12 PHASE_EXECUTION = "PE"    # Executing the model
     13 PHASE_TERMINATION = "PT"  # Tearing down
     14 PHASE_UNSPECIFIED = "PU"  # Helper code called from multiple phases
     15 # Subphases of execution
     16 PHASE_INPUTS_AND_OUTPUTS = "PIO"  # Setting inputs/outputs and allocating buffers
     17 PHASE_TRANSFORMATION = "PTR"      # Transforming data for computation
     18 PHASE_COMPUTATION = "PCO"         # Computing operations' outputs
     19 PHASE_RESULTS = "PR"              # Reading out results
     20 # Layers
     21 LAYER_APPLICATION = "LA"
     22 LAYER_RUNTIME = "LR"
     23 LAYER_IPC = "LI"
     24 LAYER_DRIVER = "LD"
     25 LAYER_CPU = "LC"
     26 LAYER_OTHER = "LO"
     27 LAYER_UTILITY = "LU"              # Code used from multiple layers
     28 LAYER_IGNORE = "LX"               # Don't count time
     29 # Markers
     30 MARKER_SWITCH = "[SW]"
     31 MARKER_SUBTRACT = "[SUB]"
     32 
     33 layers = [LAYER_APPLICATION, LAYER_RUNTIME, LAYER_IPC, LAYER_DRIVER, LAYER_CPU]
     34 phases = [PHASE_INITIALIZATION, PHASE_PREPARATION, PHASE_COMPILATION,
     35           PHASE_EXECUTION, PHASE_TERMINATION]
     36 subphases = 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])
     41 names = { 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": "" }
     49 layer_order = { LAYER_APPLICATION: [LAYER_RUNTIME],
     50                 LAYER_RUNTIME: [LAYER_IPC, LAYER_CPU],
     51                 LAYER_IPC: [LAYER_DRIVER] }
     52 
     53 
     54 def make_tag(layer, phase):
     55   return "_".join([layer, phase])
     56 
     57 def 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 
     94 def 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