code: def main(argv):
      metrics_output_dir = os.environ["METRIC_OUTPUT_DIR"]
  
      cmd = "nvidia-smi -q -x".split()
      retry = 0
      while True:
          smi = subprocess.run(
              cmd,
              timeout=20,
              stdout=subprocess.PIPE,
              stderr=subprocess.PIPE,
          )
          if smi.returncode != 0:
              retry += 1
              print(
                  f"gpu_metrics_collector error: nvidia-smi return code is {smi.returncode}",
                  file=sys.stderr,
              )
              print(
                  "=" * 20 + f"\nCaptured stdout: {smi.stdout}",
                  file=sys.stderr,
              )
              print(
                  "=" * 20 + f"\nCaptured stderr: {smi.stderr}",
                  file=sys.stderr,
              )
              gen_empty_gpu_metric(metrics_output_dir)
              if retry >= 5:
                  break
          else:
              parse_nvidia_smi_result(smi.stdout, metrics_output_dir)
          # TODO: change to sleep time configurable via arguments
          time.sleep(5)
  
file_path: nni/nni/tools/gpu_tool/gpu_metrics_collector.py
imports: import json
  import os
  import subprocess
  import sys
  import time
  import traceback
  from xml.dom import minidom
label_desc: Use image node_id 1 for calling a global function with example usage: main(argv) without return types