class_docstr: Runtime metrics for a PhysicalOperator.
  
  Metrics are updated dynamically during the execution of the Dataset.
  This class can be used for either observablity or scheduling purposes.
  
  DO NOT modify the fields of this class directly. Instead, use the provided
  callback methods.
class_docstr_tok: ["Runtime","metrics","for","a","PhysicalOperator",".","Metrics","are","updated","dynamically","during","the","execution","of","the","Dataset",".","This","class","can","be","used","for","either","observablity","or","scheduling","purposes",".","DO","NOT","modify","the","fields","of","this","class","directly",".","Instead",",","use","the","provided","callback","methods","."]
docstr: Return a dict representation of the metrics.
docstr_tok: ["Return","a","dict","representation","of","the","metrics","."]
code: def as_dict(self, metrics_only: bool = False):
      """Return a dict representation of the metrics."""
      result = []
      for f in fields(self):
          if f.metadata.get("export", True):
              if (
                  not self._is_map and f.metadata.get("map_only", False)
              ) or (
                  metrics_only
                  and not f.metadata.get("export_metric", False)
              ):
                  continue
              value = getattr(self, f.name)
              result.append((f.name, value))
  
      # TODO: record resource usage in OpRuntimeMetrics,
      # avoid calling self._op.current_resource_usage()
      resource_usage = self._op.current_resource_usage()
      result.extend(
          [
              ("cpu_usage", resource_usage.cpu or 0),
              ("gpu_usage", resource_usage.gpu or 0),
          ]
      )
      result.extend(self._extra_metrics.items())
      return dict(result)
  
imports: from dataclasses import dataclass, field, fields
  from typing import TYPE_CHECKING, Any, Dict, Optional
  import ray
  from ray.data._internal.execution.interfaces.ref_bundle import RefBundle
  from ray.data._internal.memory_tracing import trace_allocation
label_desc: Use image node_id 3 for calling the OpRuntimeMetrics obj's underlying member method code with example usage: obj.as_dict(metrics_only) and returns: dict