How to use set_hugepages method in avocado

Best Python code snippet using avocado_python Github


Full Screen

...36 '''Read number of reserved pages'''37 with open(path + '/nr_hugepages') as nr_hugepages:38 return int( return 040def set_hugepages(path, pages):41 '''Write the number of reserved huge pages'''42 filename = path + '/nr_hugepages'43 try:44 with open(filename, 'w') as nr_hugepages:45 nr_hugepages.write('{}\n'.format(pages))46 except PermissionError:47 sys.exit('Permission denied: need to be root!')48 except FileNotFoundError:49 filename = os.path.basename(path)50 size = filename[10:]51 sys.exit('{} is not a valid system huge page size'.format(size))52def show_numa_pages():53 '''Show huge page reservations on Numa system'''54 print('Node Pages Size Total')55 for numa_path in glob.glob('/sys/devices/system/node/node*'):56 node = numa_path[29:] # slice after /sys/devices/system/node/node57 path = numa_path + '/hugepages'58 for hdir in os.listdir(path):59 pages = get_hugepages(path + '/' + hdir)60 if pages > 0:61 kb = int(hdir[10:-2]) # slice out of hugepages-NNNkB62 print('{:<4} {:<5} {:<6} {}'.format(node, pages,63 fmt_memsize(kb),64 fmt_memsize(pages * kb)))65def show_non_numa_pages():66 '''Show huge page reservations on non Numa system'''67 print('Pages Size Total')68 path = '/sys/kernel/mm/hugepages'69 for hdir in os.listdir(path):70 pages = get_hugepages(path + '/' + hdir)71 if pages > 0:72 kb = int(hdir[10:-2])73 print('{:<5} {:<6} {}'.format(pages, fmt_memsize(kb),74 fmt_memsize(pages * kb)))75def show_pages():76 '''Show existing huge page settings'''77 if is_numa():78 show_numa_pages()79 else:80 show_non_numa_pages()81def clear_pages():82 '''Clear all existing huge page mappings'''83 if is_numa():84 dirs = glob.glob(85 '/sys/devices/system/node/node*/hugepages/hugepages-*')86 else:87 dirs = glob.glob('/sys/kernel/mm/hugepages/hugepages-*')88 for path in dirs:89 set_hugepages(path, 0)90def default_pagesize():91 '''Get default huge page size from /proc/meminfo'''92 with open('/proc/meminfo') as meminfo:93 for line in meminfo:94 if line.startswith('Hugepagesize:'):95 return int(line.split()[1])96 return None97def set_numa_pages(pages, hugepgsz, node=None):98 '''Set huge page reservation on Numa system'''99 if node:100 nodes = ['/sys/devices/system/node/node{}/hugepages'.format(node)]101 else:102 nodes = glob.glob('/sys/devices/system/node/node*/hugepages')103 for node_path in nodes:104 huge_path = '{}/hugepages-{}kB'.format(node_path, hugepgsz)105 set_hugepages(huge_path, pages)106def set_non_numa_pages(pages, hugepgsz):107 '''Set huge page reservation on non Numa system'''108 path = '/sys/kernel/mm/hugepages/hugepages-{}kB'.format(hugepgsz)109 set_hugepages(path, pages)110def reserve_pages(pages, hugepgsz, node=None):111 '''Set the number of huge pages to be reserved'''112 if node or is_numa():113 set_numa_pages(pages, hugepgsz, node=node)114 else:115 set_non_numa_pages(pages, hugepgsz)116def get_mountpoints():117 '''Get list of where hugepage filesystem is mounted'''118 mounted = []119 with open('/proc/mounts') as mounts:120 for line in mounts:121 fields = line.split()122 if fields[2] != 'hugetlbfs':123 continue...

Full Screen

Full Screen


Source:startvm Github


Full Screen

...3import libvirt4import sys,os5import dbus6from subprocess import call,Popen7def set_hugepages(hugepages=8600):8 with open('/proc/sys/vm/nr_hugepages','w') as f:9 f.write(str(hugepages))10 time.sleep(1)11 with open('/proc/sys/vm/nr_hugepages','r') as f:12 return hugepages<=int(f.readline(1).rstrip())13def demote():14 os.setgid(1000)15 os.setuid(1000)16def startvm():17'qemu:///system')18 if (not 'default' in conn.listNetworks()):19 conn.networkLookupByName('default').create()20 if (not 'win10' in [conn.lookupByID(id).name() for id in conn.listDomainsID()]):21 conn.lookupByName('win10').create()22 call("systemctl stop usbserver.socket usbserver.service".split())23 time.sleep(0.5)24 call("systemctl start usbserver.socket usbserver.service".split())25 call("systemctl start sshd".split())26 #demote to user27 os.environ["LIBASOUND_DEBUG"]="1"28 os.environ["HOME"]="/home/jknedlik"29 os.chdir("/home/jknedlik/")30 #close_fds detaches the subprocess31 Popen("scream -o pulseaudio -i virbr0 -v -u -p 4011".split(),close_fds=True,preexec_fn=demote)32 lg=input("Do you want to open a looking class client? [y/N]")33 #if(lg=="y" or lg=="Y"):34 #Popen("scream -o pulseaudio -i virbr0 -v -u -p 4011".split(),close_fds=True,preexec_fn=()35set_hugepages()36os.chown("/dev/nvme0n1",0,992)#root:kvm...

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:


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

Run avocado 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?