class_docstr: This simple profiler records the duration of model prediction in seconds,
  and compute the net percentage duration of each sub models via 'model_dependencies'.
  Usage:
      model = modelkit.load_model(...)
      profiler = SimpleProfiler(model)
      res = model(item)
      profiler.summary() # return profiling result (Dict) or str
  
  Attributes:
      recording_hook (Dict[str, float]): record start/end time of each model call
      durations (List[float]): record duration of each model call
      net_durations (List[float]): record net duration of each model call. Net
          duration is the duration minus all the other sub models' duration.
      graph (Dict[str, Set]): model dependencies graph, get all direct children names
          (Set[str])
      graph_calls (Dict[str, Dict[str, int]]): record all model calls
          e.g
          {
              "pipeline": {
                  "__main__": 1, # "pipeline" is called once
                  "model_a": 2,
                  "model_b": 1,
                  "model_c": 1,
              }
          }
  See test_simple_profiler.py for more details.
class_docstr_tok: ["This","simple","profiler","records","the","duration","of","model","prediction","in","seconds",",","and","compute","the","net","percentage","duration","of","each","sub","models","via","'model_dependencies","'",".","Usage",":","model","=","modelkit.load_model","(","...",")","profiler","=","SimpleProfiler","(","model",")","res","=","model","(","item",")","profiler.summary","(",")","#","return","profiling","result","(","Dict",")","or","str","Attributes",":","recording_hook","(","Dict","[","str",",","float","]",")",":","record","start\/end","time","of","each","model","call","durations","(","List","[","float","]",")",":","record","duration","of","each","model","call","net_durations","(","List","[","float","]",")",":","record","net","duration","of","each","model","call",".","Net","duration","is","the","duration","minus","all","the","other","sub","models","'","duration",".","graph","(","Dict","[","str",",","Set","]",")",":","model","dependencies","graph",",","get","all","direct","children","names","(","Set","[","str","]",")","graph_calls","(","Dict","[","str",",","Dict","[","str",",","int","]","]",")",":","record","all","model","calls","e.g","{","``","pipeline","''",":","{","``","__main__","''",":","1",",","#","``","pipeline","''","is","called","once","``","model_a","''",":","2",",","``","model_b","''",":","1",",","``","model_c","''",":","1",",","}","}","See","test_simple_profiler.py","for","more","details","."]
docstr: Usage
  
      stat: Dict[str, List] = profiler.summary()
  or
      print(profiler.summary(print_table=True, tablefmt="fancy_grid"))
  
  See: https://pypi.org/project/tabulate/ for all available table formats.
docstr_tok: ["Usage","stat",":","Dict","[","str",",","List","]","=","profiler.summary","(",")","or","print","(","profiler.summary","(","print_table=True",",","tablefmt=","''","fancy_grid","''",")",")","See",":","https",":","\/\/pypi.org\/project\/tabulate\/","for","all","available","table","formats","."]
code: def summary(  # type: ignore
      self, *args, print_table: bool = False, **kwargs  # type: ignore
  ) -> Union[Dict[str, List], str]:  # type: ignore
      """Usage
  
          stat: Dict[str, List] = profiler.summary()
      or
          print(profiler.summary(print_table=True, tablefmt="fancy_grid"))
  
      See: https://pypi.org/project/tabulate/ for all available table formats.
  
      """
      result = defaultdict(list)
      total = self.total_duration
      for model_name in self.durations:
          durations = self.durations[model_name]
          result["Name"].append(model_name)
          result["Duration per call (s)"].append(
              sum(durations) / len(durations) if durations else 0
          )
          result["Num call"].append(len(durations))
          result["Total duration (s)"].append(sum(durations))
          result["Total percentage %"].append(
              100 * sum(durations) / total
          )
          net_durations = self.net_durations[model_name]
          result["Net duration per call (s)"].append(
              sum(net_durations) / len(net_durations)
              if net_durations
              else 0
          )
      result["Net percentage %"] = [
          100 * net * num / total
          for net, num in zip(
              result["Net duration per call (s)"], result["Num call"]
          )
      ]
      # re-order columns names & sort by "Total percentage %"
      arg_index = sorted(
          range(len(result["Name"])),
          key=result["Total percentage %"].__getitem__,
          reverse=True,
      )
      result_sorted = OrderedDict()
      for col in [
          "Name",
          "Net duration per call (s)",
          "Net percentage %",
          "Num call",
          "Duration per call (s)",
          "Total duration (s)",
          "Total percentage %",
      ]:
          result_sorted[col] = [
              *map(lambda x: result[col][x], arg_index)
          ]
  
      if print_table:
          return tabulate(result_sorted, headers="keys", **kwargs)
      return result_sorted
  
file_path: modelkit/modelkit/core/profilers/simple.py
imports: import time
  from collections import OrderedDict, defaultdict
  from contextlib import contextmanager
  from typing import Dict, Generator, List, Set, Union
  from tabulate import tabulate
  from modelkit.core.model import Model
  from modelkit.core.profilers.base import BaseProfiler
label_desc: Use image node_id 5 for calling the SimpleProfiler obj's underlying member method code with example usage: obj.summary() and returns: result_sorted, tabulate