class_docstr: Apple GPU stats available on Arm Macs.
class_docstr_tok: ["Apple","GPU","stats","available","on","Arm","Macs","."]
code: def sample(self) -> None:
      try:
          command = [str(self.binary_path), "--json"]
          output = (
              subprocess.check_output(command, universal_newlines=True)
              .strip()
              .split("\n")
          )[0]
          raw_stats = json.loads(output)
  
          stats: _Stats = {
              "gpu": raw_stats["utilization"],
              "memoryAllocated": raw_stats["mem_used"],
              "temp": raw_stats["temperature"],
              "powerWatts": raw_stats["power"],
              "powerPercent": (
                  raw_stats["power"] / self.MAX_POWER_WATTS
              )
              * 100,
              # TODO: this stat could be useful eventually, it was consistently
              #  0 in my experimentation and requires a frontend change
              #  so leaving it out for now.
              # "cpuWaitMs": raw_stats["cpu_wait_ms"],
          }
  
          self.samples.append(stats)
  
      except (
          OSError,
          ValueError,
          TypeError,
          subprocess.CalledProcessError,
      ) as e:
          logger.exception(f"GPU stats error: {e}")
  
imports: import json
  import logging
  import pathlib
  import platform
  import subprocess
  import sys
  import threading
  from collections import deque
  from typing import TYPE_CHECKING, List
  from wandb.sdk.lib import telemetry
  from .aggregators import aggregate_mean
  from .asset_registry import asset_registry
  from .interfaces import Interface, Metric, MetricsMonitor
label_desc: Use image node_id 2 for calling the GPUAppleStats obj's underlying member method code with example usage: obj.sample() without return types