code: def cpu_percent():
      global _last_cgroup_cpu_measure, _last_proc_cpu_measure, _last_cpu_percent, _last_psutil_measure
      if _cpu_use_cgroup_stat:
          if _is_cgroup_v2:
              # see CPU section in https://www.kernel.org/doc/Documentation/cgroup-v2.txt
              cpu_content = _read_cgroup_stat_file(
                  CGROUP_V2_CPU_STAT_FILE
              )
              cpu_acct = cpu_content["usage_usec"] * 1000
          else:
              # see https://www.kernel.org/doc/Documentation/cgroup-v1/cpuacct.txt
              with open(CGROUP_V1_CPU_ACCT_FILE, "r") as cgroup_file:
                  cpu_acct = int(cgroup_file.read())
          sample_time = _timer()
  
          if _last_cgroup_cpu_measure is None:
              _last_cgroup_cpu_measure = (cpu_acct, sample_time)
              return None
  
          last_cpu_acct, last_sample_time = _last_cgroup_cpu_measure
          time_delta = sample_time - last_sample_time
          if time_delta < _cpu_percent_interval:
              return _last_cpu_percent or 0
  
          _last_cgroup_cpu_measure = (cpu_acct, sample_time)
          # nanoseconds / seconds * 100, we shall divide 1e7.
          _last_cpu_percent = round(
              (cpu_acct - last_cpu_acct)
              / (sample_time - last_sample_time)
              / 1e7,
              1,
          )
          return _last_cpu_percent or 0
      elif _cpu_use_process_stat:
          pts, sts = _take_process_cpu_snapshot()
  
          if _last_proc_cpu_measure is None:
              _last_proc_cpu_measure = (pts, sts)
              return None
  
          old_pts, old_sts = _last_proc_cpu_measure
  
          percents = []
          for pid in pts:
              if pid not in old_pts:
                  continue
              pt1 = old_pts[pid]
              pt2 = pts[pid]
              delta_proc = (pt2.user - pt1.user) + (
                  pt2.system - pt1.system
              )
              time_delta = sts[pid] - old_sts[pid]
  
              if time_delta < _cpu_percent_interval:
                  return _last_cpu_percent or 0
              percents.append((delta_proc / time_delta) * 100)
          _last_proc_cpu_measure = (pts, sts)
          _last_cpu_percent = round(sum(percents), 1)
          return _last_cpu_percent or 0
      else:
          measure_time = time.time()
          if (
              _last_psutil_measure is not None
              and measure_time - _last_psutil_measure
              < _cpu_percent_interval
          ):
              return _last_cpu_percent or 0
          _last_psutil_measure = measure_time
          _last_cpu_percent = psutil.cpu_percent() * _cpu_total
          return _last_cpu_percent or 0
  
imports: import logging
  import math
  import os
  import subprocess
  import sys
  import time
  from collections import namedtuple
  from typing import List, Optional
  import psutil
  from .lib import nvutils
  from ._resource import Resource, ZeroResource
  from .utils import get_bool_environ
label_desc: Use image node_id 6 for calling a global function with example usage: cpu_percent() and returns: unknown, None, unknown, unknown, unknown, None, unknown, unknown