class_docstr: Sample cluster-wide memory usage every <interval> seconds.
  
  **Usage**
  
  .. code-block:: python
  
     client = Client()
     ms = MemorySampler()
  
     with ms.sample("run 1"):
         <run first workflow>
     with ms.sample("run 2"):
         <run second workflow>
     ...
     ms.plot()
  
  or with an asynchronous client:
  
  .. code-block:: python
  
     client = await Client(asynchronous=True)
     ms = MemorySampler()
  
     async with ms.sample("run 1"):
         <run first workflow>
     async with ms.sample("run 2"):
         <run second workflow>
     ...
     ms.plot()
class_docstr_tok: ["Sample","cluster-wide","memory","usage","every","<","interval",">","seconds",".","*","*","Usage","*","*","..","code-block",":",":","python","client","=","Client","(",")","ms","=","MemorySampler","(",")","with","ms.sample","(","``","run","1","''",")",":","<","run","first","workflow",">","with","ms.sample","(","``","run","2","''",")",":","<","run","second","workflow",">","...","ms.plot","(",")","or","with","an","asynchronous","client",":","..","code-block",":",":","python","client","=","await","Client","(","asynchronous=True",")","ms","=","MemorySampler","(",")","async","with","ms.sample","(","``","run","1","''",")",":","<","run","first","workflow",">","async","with","ms.sample","(","``","run","2","''",")",":","<","run","second","workflow",">","...","ms.plot","(",")"]
code: def __init__(self):
      self.samples = {}
  
file_path: distributed/distributed/diagnostics/memory_sampler.py
imports: from __future__ import annotations
  import uuid
  from collections.abc import AsyncIterator, Iterator
  from contextlib import asynccontextmanager, contextmanager
  from datetime import datetime
  from typing import TYPE_CHECKING, Any
  from distributed.compatibility import PeriodicCallback
label_desc: Use image node_id 1 to create a new MemorySampler object  with example: obj = MemorySampler()