code: def benchmarked(
      pid=None, benchmark_record=None, interval=BENCHMARK_INTERVAL
  ):
      """Measure benchmark parameters while within the context manager
  
      Yields a ``BenchmarkRecord`` with the results (values are set after
      leaving context).
  
      If ``pid`` is ``None`` then the PID of the current process will be used.
      If ``benchmark_record`` is ``None`` then a new ``BenchmarkRecord`` is
      created and returned, otherwise, the object passed as this parameter is
      returned.
  
      Usage::
  
          with benchmarked() as bench_result:
              pass
      """
      result = benchmark_record or BenchmarkRecord()
      if pid is False:
          yield result
      else:
          start_time = time.time()
          bench_thread = BenchmarkTimer(
              int(pid or os.getpid()), result, interval
          )
          bench_thread.start()
          yield result
          bench_thread.cancel()
          result.running_time = time.time() - start_time
  
imports: import contextlib
  import datetime
  from itertools import chain
  import os
  import time
  import threading
  from snakemake.logging import logger
label_desc: Use image node_id 1 for calling a global function with example usage: benchmarked(pid, benchmark_record, interval) without return types