code: def test_gc_diagnosis_cpu_time():
      diag = GCDiagnosis(warn_over_frac=0.75)
      diag.N_SAMPLES = 3  # shorten tests
  
      with enable_gc_diagnosis_and_log(diag, level="WARN") as sio:
          # Spend some CPU time doing only full GCs
          for _ in range(diag.N_SAMPLES):
              gc.collect()
          assert not sio.getvalue()
          gc.collect()
          lines = sio.getvalue().splitlines()
          assert len(lines) == 1
          # Between 80% and 100%
          assert re.match(
              r"full garbage collections took (100|[89][0-9])% "
              r"CPU time recently",
              lines[0],
          )
  
      with enable_gc_diagnosis_and_log(diag, level="WARN") as sio:
          # Spend half the CPU time doing full GCs
          for _ in range(diag.N_SAMPLES + 1):
              t1 = thread_time()
              gc.collect()
              dt = thread_time() - t1
              run_for(dt, timer=thread_time)
          # Less than 75% so nothing printed
          assert not sio.getvalue()
  
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 3 for calling a global function with example usage: test_gc_diagnosis_cpu_time() without return types