code: def diagnostics(
      dsk: MutableMapping[Key, Any],
      o: Mapping[Key, int] | None = None,
      dependencies: MutableMapping[Key, set[Key]] | None = None,
  ) -> tuple[dict[Key, OrderInfo], list[int]]:
      """Simulate runtime metrics as though running tasks one at a time in order.
  
      These diagnostics can help reveal behaviors of and issues with ``order``.
  
      Returns a dict of `namedtuple("OrderInfo")` and a list of the number of outputs held over time.
  
      OrderInfo fields:
      - order : the order in which the node is run.
      - age : how long the output of a node is held.
      - num_data_when_run : the number of outputs held in memory when a node is run.
      - num_data_when_released : the number of outputs held in memory when the output is released.
      - num_dependencies_freed : the number of dependencies freed by running the node.
      """
      if dependencies is None:
          dependencies, dependents = get_deps(dsk)
      else:
          dependents = reverse_dict(dependencies)
      assert dependencies is not None
      if o is None:
          o = order(dsk, dependencies=dependencies, return_stats=False)
  
      pressure = []
      num_in_memory = 0
      age = {}
      runpressure = {}
      releasepressure = {}
      freed = {}
      num_needed = {key: len(val) for key, val in dependents.items()}
      for i, key in enumerate(sorted(dsk, key=o.__getitem__)):
          pressure.append(num_in_memory)
          runpressure[key] = num_in_memory
          released = 0
          for dep in dependencies[key]:
              num_needed[dep] -= 1
              if num_needed[dep] == 0:
                  age[dep] = i - o[dep]
                  releasepressure[dep] = num_in_memory
                  released += 1
          freed[key] = released
          if dependents[key]:
              num_in_memory -= released - 1
          else:
              age[key] = 0
              releasepressure[key] = num_in_memory
              num_in_memory -= released
  
      rv = {
          key: OrderInfo(
              val,
              age[key],
              runpressure[key],
              releasepressure[key],
              freed[key],
          )
          for key, val in o.items()
      }
      return rv, pressure
  
file_path: dask/dask/order.py
imports: from __future__ import annotations
  import copy
  from collections import defaultdict, deque, namedtuple
  from collections.abc import Iterable, Mapping, MutableMapping
  from typing import Any, Callable, Literal, NamedTuple, overload
  from dask.core import get_dependencies, get_deps, getcycle, istask, reverse_dict
  from dask.typing import Key
label_desc: Use image node_id 6 for calling a global function with example usage: diagnostics(dsk, o, dependencies) and returns: rv,  pressure