code: def monitor_with_ptera(
      interval=1, db_backend_type=PickledDB, runner_type=Runner
  ):
      """Monitor DB I/O and number of trials during optimization."""
      # NOTE: Need to have these classes imported for them to be resolved by ptera by name.
      db_backend = db_backend_type.__name__
      runner_name = runner_type.__name__
      with contextlib.ExitStack() as stack:
          selectors = dict(
              write=f"{db_backend}.write(query) > data",
              read=f"{db_backend}.read(query) > #value",
              read_and_write=f"{db_backend}.read_and_write(data, query) > #value",
              count=f"{db_backend}.count(query) > #value",
              n_trials=f"{runner_name}.gather(trials) > #value",
          )
          probes = dict()
          profiling = dict()
          for key, selector in selectors.items():
              probes[key] = stack.enter_context(probing(selector))
  
              if key == "n_trials":
                  probes[key] = (
                      probes["n_trials"]
                      .buffer_with_time(interval)
                      .map(max_trials)
                      .accum()
                  )
              else:
                  measure_stream = probes[key].map(
                      globals()[f"measure_size_{key}"]
                  )
                  profiling[key] = measure_stream.map(
                      save_caller
                  ).accum()
                  probes[key] = (
                      measure_stream.buffer_with_time(interval)
                      .map(sum_stats)
                      .accum()
                  )
  
          data = ([], [], [])
          yield data
  
      n_trials = probes.pop("n_trials")
      for interval_trials, row in zip(n_trials, zip(*probes.values())):
          if interval_trials == 0 and len(data[0]) > 0:
              interval_trials = data[2][-1]
          net_in = 0
          net_out = 0
          for probe in row:
              net_in += probe["net_in"]
              net_out += probe["net_out"]
  
          data[0].append(net_in)
          data[1].append(net_out)
          data[2].append(interval_trials)
  
      net_in_profiling = defaultdict(float)
      net_out_profiling = defaultdict(float)
      calls_profiling = defaultdict(int)
      for key, profiler in profiling.items():
          for element in profiler:
              net_in_profiling[element["stack"]] += element["net_in"]
              net_out_profiling[element["stack"]] += element["net_out"]
              calls_profiling[element["stack"]] += 1
  
      # TODO: Make this print optional
      return
      net_in_profiling = sorted(
          net_in_profiling.items(),
          key=lambda item: item[1],
          reverse=True,
      )
      total = numpy.zeros(2)
      for item in net_in_profiling:
          print("net_in", calls_profiling[item[0]], item[1])
          print(item[0])
          total += numpy.array([calls_profiling[item[0]], item[1]])
      print("total", total)
  
      net_out_profiling = sorted(
          net_out_profiling.items(),
          key=lambda item: item[1],
          reverse=True,
      )
      total = numpy.zeros(2)
      for item in net_out_profiling:
          print("net_out", calls_profiling[item[0]], item[1])
          print(item[0])
          total += numpy.array([calls_profiling[item[0]], item[1]])
      print("total", total)
  
imports: import argparse
  import contextlib
  import multiprocessing
  import subprocess
  import sys
  import time
  from collections import defaultdict, namedtuple
  import bson
  import numpy
  from ptera import probing
  from orion.client import build_experiment
  from orion.client.runner import Runner
  from orion.core.io.database.pickleddb import PickledDB
  from orion.testing import OrionState
label_desc: Use image node_id 15 for calling a global function with example usage: monitor_with_ptera(interval, db_backend_type, runner_type) without return types