def test_cpu_memory_usage(duthosts, enum_rand_one_per_hwsku_hostname, setup_thresholds):
    'Check DUT memory usage and process cpu usage are within threshold.'
    duthost = duthosts[enum_rand_one_per_hwsku_hostname]
    MonitResult = namedtuple('MonitResult', ['processes', 'memory'])
    monit_results = duthost.monit_process(iterations=24)['monit_results']
    (memory_threshold, normal_cpu_threshold, high_cpu_consume_procs) = setup_thresholds
    persist_threshold = 8
    outstanding_mem_polls = {}
    outstanding_procs = {}
    outstanding_procs_counter = Counter()
    for (i, monit_result) in enumerate((MonitResult(*_) for _ in monit_results)):
        logging.debug('------ Iteration %d ------', i)
        check_memory(i, memory_threshold, monit_result, outstanding_mem_polls)
        for proc in monit_result.processes:
            cpu_threshold = normal_cpu_threshold
            if (proc['name'] in high_cpu_consume_procs):
                cpu_threshold = high_cpu_consume_procs[proc['name']]
            check_cpu_usage(cpu_threshold, outstanding_procs, outstanding_procs_counter, proc)
    analyse_monitoring_results(cpu_threshold, memory_threshold, outstanding_mem_polls, outstanding_procs, outstanding_procs_counter, persist_threshold)
Check DUT memory usage and process cpu usage are within threshold.
def test_cpu_memory_usage(duthosts, enum_rand_one_per_hwsku_hostname, setup_thresholds):
    
    duthost = duthosts[enum_rand_one_per_hwsku_hostname]
    MonitResult = namedtuple('MonitResult', ['processes', 'memory'])
    monit_results = duthost.monit_process(iterations=24)['monit_results']
    (memory_threshold, normal_cpu_threshold, high_cpu_consume_procs) = setup_thresholds
    persist_threshold = 8
    outstanding_mem_polls = {}
    outstanding_procs = {}
    outstanding_procs_counter = Counter()
    for (i, monit_result) in enumerate((MonitResult(*_) for _ in monit_results)):
        logging.debug('------ Iteration %d ------', i)
        check_memory(i, memory_threshold, monit_result, outstanding_mem_polls)
        for proc in monit_result.processes:
            cpu_threshold = normal_cpu_threshold
            if (proc['name'] in high_cpu_consume_procs):
                cpu_threshold = high_cpu_consume_procs[proc['name']]
            check_cpu_usage(cpu_threshold, outstanding_procs, outstanding_procs_counter, proc)
    analyse_monitoring_results(cpu_threshold, memory_threshold, outstanding_mem_polls, outstanding_procs, outstanding_procs_counter, persist_threshold)