code: def cpp_profile(func):
      """Decorator for profiling MXNet operation.
      Uses MXNet profiler to collect metrics on memory usage and execution time
      of the operation.
  
      Parameters
      ----------
      func:
          Operation to be executed and timed.
  
      Returns
      -------
      res, profiler output. res being result returned after operator execution.
      profiler output is a dictionary with summary of operation execution.
      Example output : { "add": [{"avg_time_mem_alloc_cpu/0": 207618.0469,
                                  "avg_time_forward_broadcast_add": 4.204,
                                  "avg_time_backward_broadcast_add": 5.6288,
                                  "inputs": {
                                              "lhs": [1024, 1024],
                                              "rhs": [1024,1024]
                                            }]
                       }
      """
  
      @functools.wraps(func)
      def cpp_profile_it(*args, **kwargs):
          # Profile the operation
          profiler.set_config(profile_all=True, aggregate_stats=True)
          profiler.set_state("run")
          res = func(*args, **kwargs)
          profiler.set_state("stop")
  
          # Prepare the results
          profiler_dump = profiler.dumps(reset=True)
  
          # args[0] is assumed to be operator name, if not found check for block name.
          # NOTE: This parameter should be removed when we get away from parsing
          # profiler output and start using new profiler APIs - get_summary(), reset()
          if len(args) > 0:
              operator_name = args[0].__name__
          elif "block" in kwargs:
              operator_name = kwargs["block"]._op_name
          else:
              raise ValueError(
                  "Unable to identify operator name to extract profiler output!"
              )
  
          # Get the MXNet profile output
          profiler_output = parse_profiler_dump(
              operator_name, profiler_dump
          )
          return res, profiler_output
  
      return cpp_profile_it
  
file_path: mxnet/benchmark/opperf/utils/profiler_utils.py
imports: import time
  import functools
  import numpy
  from .common_utils import merge_map_list
  from mxnet import profiler
label_desc: Use image node_id 4 for calling a global function with example usage: cpp_profile(func) and returns: cpp_profile_it, res,  profiler_output