def get_alloc(vms): alloc = [] for vm in vms: pid = vm.pid if not pid: continue process = psutil.Process(pid) p1 = max(process.threads(), key=lambda x:x[1]) cpu_thread, _, _ = max(process.threads(), key=lambda x:[1]) tidcpu = get_cur_cpu(cpu_thread) alloc.append((vm, tidcpu)) print(vm, tidcpu) print(alloc) import pdb; pdb.set_trace()
def perfstat_sampling(num:int=100, interval:int=100, pause:float=0.1, delay:float=0.002, vms=None): from perf.numa import get_cur_cpu from perfstat import Perf isolated = defaultdict(list) frozen = defaultdict(list) batch_size = 5 assert num % batch_size == 0, \ "number of samples should divide by 10, got %s" % num iterations = num // batch_size perfs = [Perf(cpu=get_cur_cpu(vm.pid)) for vm in vms] for i in range(1, iterations+1): print(i, "out of", iterations) # frozen for j in range(batch_size): for vm, perf in zip(vms, perfs): bmark = vm.bname if pause: sleep(pause) vm.exclusive() sleep(delay) stat = perf.measure(interval) if stat[0] and stat[1]: ipc = stat[0] / stat[1] frozen[bmark].append(ipc) else: print("Perf() missed a datapoint") vm.shared() # isolated for vm, perf in zip(vms, perfs): vm.exclusive() bmark = vm.bname for i in range(batch_size): if pause: sleep(pause) stat = perf.measure(interval) if stat[0] and stat[1]: ipc = stat[0] / stat[1] isolated[bmark].append(ipc) else: print("Perf() missed a datapoint") vm.shared() return Struct(isolated=isolated, frozen=frozen)