code: def get_resource_usage_report(
      main_kineto_events: List[_KinetoEvent],
      main_function_events: List[profiler_util.FunctionEvent],
      memory_events: List[List[Union[_KinetoEvent, bool]]],
      out_of_memory_events: List[List[Union[_KinetoEvent, bool]]],
      info: Dict[str, Any],
  ) -> Dict[str, List[TorchProfilerMetrics]]:
      """Get relevant information from Kineto events and function events exported by the profiler.
  
      :param main_kineto_events: list of main Kineto events.
      :param main_function_events: list of main function events.
      :param memory_events: list of memory events.
      :param out_of_memory_events: list of out of memory events.
      :param info: dictionary used to record resource usage metrics.
      """
      main_kineto_events = sorted(
          (
              evt
              for evt in main_kineto_events
              if LUDWIG_TAG in evt.name()
          ),
          key=lambda x: x.correlation_id(),
      )
      main_function_events = sorted(
          (
              evt
              for evt in main_function_events
              if LUDWIG_TAG in evt.name
          ),
          key=lambda x: x.id,
      )
  
      for kineto_event, function_event in zip(
          main_kineto_events, main_function_events
      ):
          # Two different instances of `function_event` can have the same name if a the same
          # tagged code block/function was executed more than once.
          memory_info_per_device = get_device_memory_usage(
              kineto_event, memory_events
          )
          torch_cpu_time, torch_cuda_time = get_device_run_durations(
              function_event
          )
          num_oom_events = get_num_oom_events(
              kineto_event, out_of_memory_events
          )
          torch_profiler_metrics = TorchProfilerMetrics(
              torch_cpu_time=torch_cpu_time,
              torch_cuda_time=torch_cuda_time,
              num_oom_events=num_oom_events,
              device_usage=memory_info_per_device,
          )
          info[function_event.name].append(torch_profiler_metrics)
      return info
  
file_path: ludwig/ludwig/benchmarking/reporting.py
imports: from collections import Counter, defaultdict
  from statistics import mean
  from typing import Any, Dict, List, Tuple, Union
  import torch
  from torch._C._autograd import _KinetoEvent
  from torch.autograd import DeviceType, profiler_util
  from ludwig.benchmarking.profiler_dataclasses import DeviceUsageMetrics, SystemResourceMetrics, TorchProfilerMetrics
  from ludwig.constants import LUDWIG_TAG
label_desc: Use image node_id 7 for calling a global function with example usage: get_resource_usage_report(main_kineto_events, main_function_events, memory_events, out_of_memory_events, info) and returns: info