code: def _atexit_print_fn():
      """Print `ProfileStat` objects in `_atexit_print_list` to `_atexit_print_file`."""
      if config.profile:
          to_sum = []
  
          if config.profiling__destination == "stderr":
              destination_file = "<stderr>"
          elif config.profiling__destination == "stdout":
              destination_file = "<stdout>"
          else:
              destination_file = config.profiling__destination
  
          with extended_open(destination_file, mode="w"):
              # Reverse sort in the order of compile+exec time
              for ps in sorted(
                  _atexit_print_list,
                  key=lambda a: a.compile_time + a.fct_call_time,
              )[::-1]:
                  if (
                      ps.fct_callcount >= 1
                      or ps.compile_time > 1
                      or getattr(ps, "callcount", 0) > 1
                  ):
                      ps.summary(
                          file=destination_file,
                          n_ops_to_print=config.profiling__n_ops,
                          n_apply_to_print=config.profiling__n_apply,
                      )
  
                      if ps.show_sum:
                          to_sum.append(ps)
                  else:
                      # TODO print the name if there is one!
                      print("Skipping empty Profile")
              if len(to_sum) > 1:
                  # Make a global profile
                  cum = copy.copy(to_sum[0])
                  msg = f"Sum of all({len(to_sum)}) printed profiles at exit."
                  cum.message = msg
                  for ps in to_sum[1:]:
                      for attr in [
                          "compile_time",
                          "fct_call_time",
                          "fct_callcount",
                          "vm_call_time",
                          "rewriter_time",
                          "linker_time",
                          "validate_time",
                          "import_time",
                          "linker_node_make_thunks",
                      ]:
                          setattr(
                              cum,
                              attr,
                              getattr(cum, attr) + getattr(ps, attr),
                          )
  
                      # merge dictionary
                      for attr in [
                          "apply_time",
                          "apply_callcount",
                          "apply_cimpl",
                          "variable_shape",
                          "variable_strides",
                          "variable_offset",
                          "linker_make_thunk_time",
                      ]:
                          cum_attr = getattr(cum, attr)
                          for key, val in getattr(ps, attr.items()):
                              assert key not in cum_attr, (
                                  key,
                                  cum_attr,
                              )
                              cum_attr[key] = val
  
                      if cum.rewriter_profile and ps.rewriter_profile:
                          try:
                              merge = cum.rewriter_profile[
                                  0
                              ].merge_profile(
                                  cum.rewriter_profile[1],
                                  ps.rewriter_profile[1],
                              )
                              assert len(merge) == len(
                                  cum.rewriter_profile[1]
                              )
                              cum.rewriter_profile = (
                                  cum.rewriter_profile[0],
                                  merge,
                              )
                          except Exception as e:
                              print(e)
                              cum.rewriter_profile = None
                      else:
                          cum.rewriter_profile = None
  
                  cum.summary(
                      file=destination_file,
                      n_ops_to_print=config.profiling__n_ops,
                      n_apply_to_print=config.profiling__n_apply,
                  )
  
      if config.print_global_stats:
          print_global_stats()
  
imports: import atexit
  import copy
  import logging
  import operator
  import sys
  import time
  from collections import defaultdict
  from contextlib import contextmanager
  from typing import TYPE_CHECKING, Any, Optional, Union
  import numpy
  import pytensor
  from pytensor.configdefaults import config
  from pytensor.graph.basic import Apply, Constant, Variable
  from pytensor.link.utils import get_destroy_dependencies
label_desc: Use image node_id 2 for calling a global function with example usage: _atexit_print_fn() without return types