How to use process_mpstat method in autotest

Best Python code snippet using autotest_python

net_utils.py

Source:net_utils.py Github

copy

Full Screen

...39 utils.system("echo '0' > /proc/sys/net/ipv4/route/no_local_loopback",40 ignore_status=ignore_status)41 utils.system('echo 1 > /proc/sys/net/ipv4/route/flush',42 ignore_status=ignore_status)43 def process_mpstat(self, mpstat_out, sample_count, loud=True):44 """Parses mpstat output of the following two forms:45 02:10:17 0 0.00 0.00 0.00 0.00 0.00 0.00 \46 0.00 100.00 1012.8747 02:10:13 PM 0 0.00 0.00 0.00 0.00 0.00 0.00 \48 0.00 100.00 1019.0049 """50 mpstat_keys = ['time', 'CPU', 'user', 'nice', 'sys', 'iowait', 'irq',51 'soft', 'steal', 'idle', 'intr/s']52 if loud:53 print mpstat_out54 # Remove the optional AM/PM appearing in time format55 mpstat_out = mpstat_out.replace('AM', '')56 mpstat_out = mpstat_out.replace('PM', '')57 regex = re.compile('(\S+)')...

Full Screen

Full Screen

process_mpstat.py

Source:process_mpstat.py Github

copy

Full Screen

...16 bmark = bmark_apps[0]17 else:18 bmark = bmark_apps[0] + bmark_apps[1]19 return (bmark, coloc)20def process_mpstat(f,metric):21 # metric = usr | sys | iowait | (1 - idle) 22 #print f23 allLines = []24 #We should skip first 3 lines25 f.readline()26 f.readline()27 f.readline()28 for l in f.readlines():29 l = l.strip()30 allLines.append(l)31 numLines = len(allLines)32 utilization_dict = {}33 utilization_dict['usr'] = {}34 utilization_dict['sys'] = {}35 utilization_dict['iowait'] = {}36 utilization_dict['total'] = {}37 for line in allLines: 38 fields = line.split()39 timestamp = fields[0]40 cpu = int(fields[1])41 usr = float(fields[2])42 sys = float(fields[4])43 iowait = float(fields[5])44 total = 100.0 - float(fields[10]) # this is 1 - idle field45 if(cpu not in utilization_dict['usr'].keys()):46 utilization_dict['usr'][cpu] = []47 utilization_dict['sys'][cpu] = []48 utilization_dict['iowait'][cpu] = []49 utilization_dict['total'][cpu] = []50 else:51 utilization_dict['usr'][cpu].append(usr)52 utilization_dict['sys'][cpu].append(usr)53 utilization_dict['iowait'][cpu].append(usr)54 utilization_dict['total'][cpu].append(usr)55 #end for56 cpu_dict = {}57 for cpu in utilization_dict[metric].keys():58 mean_total = np.mean(utilization_dict[metric][cpu])59 median_total = np.mean(utilization_dict[metric][cpu])60 #p95_total = np.mean(utilization_dict[metric][cpu])61 #p99_total = np.mean(utilization_dict[metric][cpu])62 print cpu, " : " , mean_total, median_total63 cpu_dict[cpu] = (mean_total, median_total)64 #end for65 return cpu_dict66if __name__ == '__main__':67 #print "process_perf.py called"68 if sys.argv[1] == '--help':69 print('process_mpstat.py experiement mpstat_file metric( = usr | sys | iowait | (1 - idle))') 70 sys.exit(0)71 if len(sys.argv) < 3:72 print('Error: Incorrect argument count')73 sys.exit(1)74 experiment = sys.argv[1]75 perf_filename = sys.argv[2]76 metric = sys.argv[3]77 fileList = getFileList("data_mpistat")78 performance_dict = {}79 for fileName in fileList:80 (bmark, coloc) = get_colocation_and_bench(fileName)81 with open(fileName, 'r') as f:82 cpu_dict = process_mpstat(f,metric)83 (mean_total_utilization, median_total) = cpu_dict[2]84 if(bmark not in performance_dict.keys()):85 performance_dict[bmark] = {}86 if(coloc not in performance_dict[bmark].keys()):87 performance_dict[bmark][coloc] = []88 performance_dict[bmark][coloc].append(mean_total_utilization)89 #end for90 for bmark in performance_dict.keys():91 for coloc in performance_dict[bmark].keys():92 mean_of_all_app_utilization = np.mean(performance_dict[bmark][coloc])93 print "Benchmark: ", bmark, " num of coloc: " , str(coloc), " mean utilization/performance: ", mean_of_all_app_utilization 94 '''95 with open(experiment + ".ipc", 'w') as ipc_f, open(experiment + ".ips", 'w') as ips_f:96 times = sorted(ipc.keys())...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful