code: def test_use_c_group_stats(cgroup_ver):
      from mars import resource
  
      def write_tmp_text_file(prefix, content):
          fd, file_name = tempfile.mkstemp(prefix)
          with os.fdopen(fd, "w") as f:
              f.write(content)
          return file_name
  
      v1_cpu_acct_path = write_tmp_text_file(
          "test-mars-res-cgroup-v1-cpu-", _v1_cpu_stat_first
      )
      v1_mem_stat_path = write_tmp_text_file(
          "test-mars-res-cgroup-v1-mem-", _v1_memory_stat_content
      )
      v2_cpu_stat_path = write_tmp_text_file(
          "test-mars-res-cgroup-v2-cpu-", _v2_cpu_stat_first
      )
      v2_mem_cur_path = write_tmp_text_file(
          "test-mars-res-cgroup-v2-cpu-", _v2_memory_current_content
      )
      v2_mem_max_path = write_tmp_text_file(
          "test-mars-res-cgroup-v2-cpu-", _v2_memory_max_content
      )
  
      old_is_cgroup_v2 = resource._is_cgroup_v2
      old_v1_cpu_acct_file = resource.CGROUP_V1_CPU_ACCT_FILE
      old_v1_mem_stat_file = resource.CGROUP_V1_MEM_STAT_FILE
      old_v2_cpu_stat_file = resource.CGROUP_V2_CPU_STAT_FILE
      old_v2_mem_current_file = resource.CGROUP_V2_MEM_CURRENT_FILE
      old_v2_mem_max_file = resource.CGROUP_V2_MEM_MAX_FILE
      old_shm_path = resource._shm_path
      try:
          os.environ["MARS_USE_CGROUP_STAT"] = "1"
  
          resource = importlib.reload(resource)
          if cgroup_ver == "v1":
              resource.CGROUP_V1_CPU_ACCT_FILE = v1_cpu_acct_path
              resource.CGROUP_V1_MEM_STAT_FILE = v1_mem_stat_path
              resource._is_cgroup_v2 = False
          else:
              resource.CGROUP_V2_CPU_STAT_FILE = v2_cpu_stat_path
              resource.CGROUP_V2_MEM_CURRENT_FILE = v2_mem_cur_path
              resource.CGROUP_V2_MEM_MAX_FILE = v2_mem_max_path
              resource._is_cgroup_v2 = True
          resource._shm_path = None
  
          assert resource.cpu_percent() is None
          time.sleep(0.5)
          with open(v1_cpu_acct_path, "w") as f:
              f.write(_v1_cpu_stat_last)
          with open(v2_cpu_stat_path, "w") as f:
              f.write(_v2_cpu_stat_last)
          assert resource.cpu_percent() > 50
          assert resource.cpu_percent() < 150
  
          mem_stats = resource.virtual_memory()
          assert mem_stats.total == 1073741824
          assert mem_stats.used == 218181632
      finally:
          resource._is_cgroup_v2 = old_is_cgroup_v2
          resource._shm_path = old_shm_path
          resource.CGROUP_V1_CPU_ACCT_FILE = old_v1_cpu_acct_file
          resource.CGROUP_V1_MEM_STAT_FILE = old_v1_mem_stat_file
          resource.CGROUP_V2_CPU_STAT_FILE = old_v2_cpu_stat_file
          resource.CGROUP_V2_MEM_CURRENT_FILE = old_v2_mem_current_file
          resource.CGROUP_V2_MEM_MAX_FILE = old_v2_mem_max_file
  
          del os.environ["MARS_USE_CGROUP_STAT"]
  
          os.unlink(v1_cpu_acct_path)
          os.unlink(v1_mem_stat_path)
          os.unlink(v2_cpu_stat_path)
          os.unlink(v2_mem_cur_path)
          os.unlink(v2_mem_max_path)
  
          importlib.reload(resource)
  
file_path: mars/mars/tests/test_resource.py
imports: import importlib
  import os
  import tempfile
  import time
  import pytest
  from ..resource import Resource, ZeroResource
label_desc: Use image node_id 3 for calling a global function with example usage: test_use_c_group_stats(cgroup_ver) and returns: file_name