class_docstr: Context-based general purpose meter.
  
  Usage
  -----
  1. In high level code, call :meth:`add_callback` to install a hook that defines an
     activity
  2. In low level code, typically many stack levels below, log quantitative events
     (e.g. elapsed time, transferred bytes, etc.) so that they will be attributed to
     the high-level code calling it, either with :meth:`meter`,
     :meth:`meter_function`, or :meth:`digest_metric`.
  
  Examples
  --------
  In the code that e.g. sends a Python object from A to B over the network:
  >>> from distributed.metrics import context_meter
  >>> with context_meter.add_callback(partial(print, "A->B comms:")):
  ...     await send_over_the_network(obj)
  
  In the serialization utilities, called many stack levels below:
  >>> with context_meter.meter("dumps"):
  ...     pik = pickle.dumps(obj)
  >>> with context_meter.meter("compress"):
  ...     pik = lz4.compress(pik)
  
  And finally, elsewhere, deep into the TCP stack:
  >>> with context_meter.meter("network-write"):
  ...     await comm.write(frames)
  
  When you call the top-level code, you'll get::
    A->B comms: dumps 0.012 seconds
    A->B comms: compress 0.034 seconds
    A->B comms: network-write 0.567 seconds
class_docstr_tok: ["Context-based","general","purpose","meter",".","Usage","--","--","-","1",".","In","high","level","code",",","call",":","meth",":","`","add_callback","`","to","install","a","hook","that","defines","an","activity","2",".","In","low","level","code",",","typically","many","stack","levels","below",",","log","quantitative","events","(","e.g",".","elapsed","time",",","transferred","bytes",",","etc",".",")","so","that","they","will","be","attributed","to","the","high-level","code","calling","it",",","either","with",":","meth",":","`","meter","`",",",":","meth",":","`","meter_function","`",",","or",":","meth",":","`","digest_metric","`",".","Examples","--","--","--","--","In","the","code","that","e.g",".","sends","a","Python","object","from","A","to","B","over","the","network",":",">",">",">","from","distributed.metrics","import","context_meter",">",">",">","with","context_meter.add_callback","(","partial","(","print",",","``","A-",">","B","comms",":","''",")",")",":","...","await","send_over_the_network","(","obj",")","In","the","serialization","utilities",",","called","many","stack","levels","below",":",">",">",">","with","context_meter.meter","(","``","dumps","''",")",":","...","pik","=","pickle.dumps","(","obj",")",">",">",">","with","context_meter.meter","(","``","compress","''",")",":","...","pik","=","lz4.compress","(","pik",")","And","finally",",","elsewhere",",","deep","into","the","TCP","stack",":",">",">",">","with","context_meter.meter","(","``","network-write","''",")",":","...","await","comm.write","(","frames",")","When","you","call","the","top-level","code",",","you","'ll","get",":",":","A-",">","B","comms",":","dumps","0.012","seconds","A-",">","B","comms",":","compress","0.034","seconds","A-",">","B","comms",":","network-write","0.567","seconds"]
code: def __init__(self):
      self._callbacks = ContextVar(
          f"MetricHook<{id(self)}>._callbacks", default={}
      )
  
imports: from __future__ import annotations
  import asyncio
  import collections
  import threading
  import time
  from collections.abc import Callable, Hashable, Iterator
  from contextlib import contextmanager
  from contextvars import ContextVar
  from dataclasses import dataclass
  from functools import wraps
  from math import nan
  from typing import Literal
  import psutil
  from distributed.compatibility import WINDOWS
label_desc: Use image node_id 1 to create a new ContextMeter object  with example: obj = ContextMeter()