code: def run_test_with_state_api(
      test_name: str,
      test_args: List[str],
      apis: List[StateAPICallSpec],
      call_interval_s: int = 3,
      print_interval_s: int = 15,
  ) -> Dict:
      start_time = time.perf_counter()
  
      # Stage 1: Run with state APIs
      api_caller = periodic_invoke_state_apis_with_actor(
          apis=apis,
          call_interval_s=call_interval_s,
          print_interval_s=print_interval_s,
      )
  
      stats_with_state_apis = run_test(test_name, test_args)
      ray.get(api_caller.stop.remote())
      print(
          json.dumps(ray.get(api_caller.get_stats.remote()), indent=2)
      )
  
      # Stage 2: Run without API generator
      stats_without_state_apis = run_test(test_name, test_args)
      end_time = time.perf_counter()
  
      # Dumping results
      results = {
          "time": end_time - start_time,
          "success": "1",
          "perf_metrics": [
              {
                  "perf_metric_name": "state_api_extra_latency_sec",
                  "perf_metric_value": stats_with_state_apis["duration"]
                  - stats_without_state_apis["duration"],
                  "perf_metric_type": "LATENCY",
              },
              {
                  "perf_metric_name": "state_api_extra_latency_sec_percentage",
                  "perf_metric_value": (
                      stats_with_state_apis["duration"]
                      / stats_without_state_apis["duration"]
                      - 1
                  )
                  * 100,
                  "perf_metric_type": "LATENCY",
              },
              {
                  "perf_metric_name": "state_api_extra_mem",
                  "perf_metric_value": stats_with_state_apis[
                      "peak_memory"
                  ]
                  - stats_without_state_apis["peak_memory"],
                  "perf_metric_type": "MEMORY",
              },
          ],
      }
  
      return results
  
file_path: ray/release/nightly_tests/stress_tests/test_state_api_with_other_tests.py
imports: import time
  from typing import Dict, List
  import click
  import json
  import os
  import ray
  from ray.util.state import list_actors, list_nodes, list_objects, list_tasks, summarize_actors, summarize_objects, summarize_tasks
  import ray._private.test_utils
  from ray._private.state_api_test_utils import StateAPICallSpec, periodic_invoke_state_apis_with_actor, STATE_LIST_LIMIT
label_desc: Use image node_id 5 for calling a global function with example usage: run_test_with_state_api(test_name, test_args, apis, call_interval_s, print_interval_s) and returns: results