code: def enable_gc_diagnosis_and_log(diag, level="INFO"):
      disable_gc_diagnosis(force=True)  # just in case
      if gc.callbacks:
          print("Unexpected gc.callbacks", gc.callbacks)
  
      with captured_logger(
          "distributed.utils_perf", level=level, propagate=False
      ) as sio:
          gc.disable()
          gc.collect()  # drain any leftover from previous tests
          diag.enable()
          try:
              yield sio
          finally:
              diag.disable()
              gc.enable()
  
file_path: distributed/distributed/tests/test_utils_perf.py
imports: from __future__ import annotations
  import contextlib
  import gc
  import itertools
  import random
  import re
  import pytest
  from distributed.metrics import thread_time
  from distributed.utils_perf import FractionalTimer, GCDiagnosis, disable_gc_diagnosis
  from distributed.utils_test import captured_logger, run_for
label_desc: Use image node_id 2 for calling a global function with example usage: enable_gc_diagnosis_and_log(diag, level) without return types