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","(",")"]
docstr: Plot data series collected so far
  
  Parameters
  ==========
  align : bool (optional)
      See :meth:`~distributed.diagnostics.MemorySampler.to_pandas`
  kwargs
      Passed verbatim to :meth:`pandas.DataFrame.plot`
  
  Returns
  =======
  Output of :meth:`pandas.DataFrame.plot`
docstr_tok: ["Plot","data","series","collected","so","far","Parameters","==========","align",":","bool","(","optional",")","See",":","meth",":","`","~distributed.diagnostics.MemorySampler.to_pandas","`","kwargs","Passed","verbatim","to",":","meth",":","`","pandas.DataFrame.plot","`","Returns","=======","Output","of",":","meth",":","`","pandas.DataFrame.plot","`"]
code: def plot(self, *, align: bool = False, **kwargs: Any) -> Any:
      """Plot data series collected so far
  
      Parameters
      ==========
      align : bool (optional)
          See :meth:`~distributed.diagnostics.MemorySampler.to_pandas`
      kwargs
          Passed verbatim to :meth:`pandas.DataFrame.plot`
  
      Returns
      =======
      Output of :meth:`pandas.DataFrame.plot`
      """
      df = (
          self.to_pandas(align=align).resample("1s").nearest() / 2**30
      )
      return df.plot(
          xlabel="time",
          ylabel="Cluster memory (GiB)",
          **kwargs,
      )
  
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 5 for calling the MemorySampler obj's underlying member method code with example usage: obj.plot() and returns: df