21 OBSERVATION_FREQUENCY_HZ = .5
22 OBSERVATION_DURATION_SEC = 60
23 PSEN_SCAN_PROCESS_NAME =
"psen_scan_node" 25 THRESHOLD_PRECENT = 80
26 RETURN_CODE_SUCCESS = 0
27 RETURN_CODE_FAILURE = 10
38 """Return the handle of the psen_scan process if it is currently running, 40 for proc
in psutil.process_iter([NAME]):
41 if proc.info[NAME] == PSEN_SCAN_PROCESS_NAME:
43 raise RuntimeError(
"Process %s not found." % PSEN_SCAN_PROCESS_NAME)
46 if __name__ ==
"__main__":
48 while process
is None:
52 print(
"Waiting for %s process to be running." %
53 PSEN_SCAN_PROCESS_NAME)
54 time.sleep(1. / OBSERVATION_FREQUENCY_HZ)
56 "Process is running. Will observe its CPU usage now for %d seconds" %
57 OBSERVATION_DURATION_SEC + NC)
58 start_time = time.time()
59 while time.time() - start_time < OBSERVATION_DURATION_SEC:
63 print(RED +
"Process not running any more. Aborting Test" + NC)
64 sys.exit(RETURN_CODE_FAILURE)
65 utilization = process.cpu_percent()
66 if utilization < THRESHOLD_PRECENT:
67 print(
"CPU utilization of >%s<: %.1f%%" %
68 (PSEN_SCAN_PROCESS_NAME, utilization))
71 "CPU utilization of >%s<: %.1f%% " %
72 (PSEN_SCAN_PROCESS_NAME, utilization) +
73 "exceeds threshold of %d%%" %
74 THRESHOLD_PRECENT + NC)
75 sys.exit(RETURN_CODE_ERROR)
76 time.sleep(1. / OBSERVATION_FREQUENCY_HZ)
77 print(GREEN +
"CPU usage was below %d%% for %d seconds. " %
78 (THRESHOLD_PRECENT, OBSERVATION_DURATION_SEC) +
79 "Test successful." + NC)
80 sys.exit(RETURN_CODE_SUCCESS)
def get_psen_scan_process()