code: def profile_command(args):
      callback.update_status(args)
  
      configure_progress(os.path.join(args.outdir, "progress.txt"))
  
      class TrainConfig:
          pass
  
      config = TrainConfig()
      info = load.load(args.config)
  
      config.global_config = info.global_config
      config.training_config = info.training_config
  
      class OptConfig:
          pass
  
      config.optimizers = OrderedDict()
      for name, opt in info.optimizers.items():
          o = OptConfig()
          o.optimizer = opt
          o.data_iterators = []
          config.optimizers[name] = o
  
      class MonConfig:
          pass
  
      config.monitors = OrderedDict()
      for name, mon in info.monitors.items():
          m = MonConfig()
          m.monitor = mon
          m.data_iterators = []
          config.monitors[name] = m
  
      try:
          ext_module = import_extension_module(
              config.global_config.default_context.backend[0].split(
                  ":"
              )[0]
          )
  
          def synchronize():
              return ext_module.synchronize(
                  device_id=config.global_config.default_context.device_id
              )
  
      except (ImportError, ModuleNotFoundError):
  
          def synchronize():
              return None
  
      result_array = [["time in ms"]]
  
      callback.update_status("processing", True)
  
      # Profile Optimizer
      with ExitStack() as stack:
          # Create data_iterator instance only once for each dataset in optimizers
          optimizer_data_iterators = {}
          for name, o in config.optimizers.items():
              for di in o.optimizer.data_iterators.values():
                  if di not in optimizer_data_iterators:
                      di_instance = stack.enter_context(di())
                      optimizer_data_iterators[di] = di_instance
                  else:
                      di_instance = optimizer_data_iterators[di]
                  o.data_iterators.append(di_instance)
          result_array = profile_optimizer(
              config, result_array, synchronize
          )
  
      # Write profiling result
      import csv
  
      with open(args.outdir + os.sep + "profile.csv", "w") as f:
          writer = csv.writer(f, lineterminator="\n")
          writer.writerows(result_array)
  
      logger.log(99, "Profile Completed.")
      progress(None)
      callback.update_status("finished")
      return True
  
file_path: nnabla/python/src/nnabla/utils/cli/profile.py
imports: from __future__ import print_function
  import os
  import time
  from collections import OrderedDict
  from functools import partial
  import nnabla.utils.callback
  import nnabla.utils.load
  import numpy
  from contextlib2 import ExitStack
  from nnabla.ext_utils import import_extension_module
  from nnabla.logger import logger
  from nnabla.utils.cli.utility import let_data_to_variable
  from nnabla.utils.progress import configure_progress, progress
label_desc: Use image node_id 4 for calling a global function with example usage: profile_command(args) and returns: True, ext_module, None