How to use get_total_memory method in lisa

Best Python code snippet using lisa_python

test_pgtune.py

Source:test_pgtune.py Github

copy

Full Screen

1# coding: utf-82"""3Test suite for PgTune.4"""5from unittest.mock import MagicMock, patch6import pytest7import smdba.postgresqlgate8class TestPgTune:9 """10 Test PgTune class.11 """12 def test_estimate(self):13 """14 Test estimation with 10 connection and 8GB RAM15 :return:16 """17 popen = MagicMock()18 popen().read = MagicMock(return_value="11.2")19 with patch("smdba.postgresqlgate.os.popen", popen):20 pgtune = smdba.postgresqlgate.PgTune(10)21 pgtune.get_total_memory = MagicMock(return_value=0x1e0384000)22 pgtune.estimate()23 assert pgtune.config['shared_buffers'] == '1920MB'24 assert pgtune.config['effective_cache_size'] == '5632MB'25 assert pgtune.config['work_mem'] == '192MB'26 assert pgtune.config['maintenance_work_mem'] == '480MB'27 assert pgtune.config['max_wal_size'] == '384MB'28 assert pgtune.config['checkpoint_completion_target'] == '0.7'29 assert pgtune.config['wal_buffers'] == '4MB'30 assert pgtune.config['constraint_exclusion'] == 'off'31 assert pgtune.config['max_connections'] == 1032 def test_estimate_high_values(self):33 """34 Test estimation with 400 connection and 32GB RAM35 :return:36 """37 popen = MagicMock()38 popen().read = MagicMock(return_value="11.2")39 with patch("smdba.postgresqlgate.os.popen", popen):40 pgtune = smdba.postgresqlgate.PgTune(400)41 pgtune.get_total_memory = MagicMock(return_value=0x773594000)42 pgtune.estimate()43 assert pgtune.config['shared_buffers'] == '7168MB'44 assert pgtune.config['effective_cache_size'] == '22528MB'45 assert pgtune.config['work_mem'] == '18MB'46 assert pgtune.config['maintenance_work_mem'] == '1024MB'47 assert pgtune.config['max_wal_size'] == '384MB'48 assert pgtune.config['checkpoint_completion_target'] == '0.7'49 assert pgtune.config['wal_buffers'] == '4MB'50 assert pgtune.config['constraint_exclusion'] == 'off'51 assert pgtune.config['max_connections'] == 40052 def test_estimate_low_memory(self):53 """54 Estimation should abort unsupported low memory systems.55 :return:56 """57 popen = MagicMock()58 popen().read = MagicMock(return_value="11.2")59 with patch("smdba.postgresqlgate.os.popen", popen):60 pgtune = smdba.postgresqlgate.PgTune(10)61 pgtune.get_total_memory = MagicMock(return_value=0xfefffff) # One byte less to 0xff00000 memory segment62 with pytest.raises(Exception) as exc:63 pgtune.estimate()...

Full Screen

Full Screen

get_concurrent_jobs.py

Source:get_concurrent_jobs.py Github

copy

Full Screen

...23 for value in values:24 (k, v) = value.split('=', 1)25 sizes.append((k, parse_size(v)))26 setattr(args, self.dest, sizes)27def get_total_memory():28 if sys.platform.startswith('linux'):29 if os.path.exists("/​proc/​meminfo"):30 with open("/​proc/​meminfo") as meminfo:31 memtotal_re = re.compile(r'^MemTotal:\s*(\d*)\s*kB')32 for line in meminfo:33 match = memtotal_re.match(line)34 if match:35 return float(match.group(1)) * 2**1036 elif sys.platform == 'darwin':37 try:38 return int(subprocess.check_output(['sysctl', '-n', 'hw.memsize']))39 except Exception:40 return 041 else:42 return 043def main():44 parser = argparse.ArgumentParser()45 parser.add_argument("--memory-per-job", action=ParseSize, default=[], nargs='*')46 parser.add_argument("--reserve-memory", type=parse_size, default=0)47 args = parser.parse_args()48 mem_total_bytes = max(0, get_total_memory() - args.reserve_memory)49 try:50 cpu_cap = multiprocessing.cpu_count()51 except:52 cpu_cap = 153 concurrent_jobs = {}54 for job, memory_per_job in args.memory_per_job:55 num_concurrent_jobs = int(max(1, mem_total_bytes /​ memory_per_job))56 concurrent_jobs[job] = min(num_concurrent_jobs, cpu_cap)57 print json.dumps(concurrent_jobs)58 return 059if __name__ == '__main__':...

Full Screen

Full Screen

UtilsMethod.py

Source:UtilsMethod.py Github

copy

Full Screen

...10 @classmethod11 def get_process_info(cls, pid):12 aa = {}13 mm = psutil.Process(pid)14 aa["process memory"] = round((mm.memory_percent()*cls.get_total_memory())/​1024/​1024/​1024, 2)15 aa["process cpu"] = mm.cpu_percent(interval=1)16 return aa17 @classmethod18 def get_userd_memory(cls):19 used = m.used20 return used21 @classmethod22 def get_total_memory(cls):23 total = m.total24 return total25 @classmethod26 def get_used_memory_percent(cls):27 return round(float(cls.get_userd_memory())/​float(cls.get_total_memory())*100, 2)28 @classmethod29 def get_all(cls):30 m = {}31 m["cpu使用率"] = cls.get_total_cpu_percent()32 m["内存使用率"] = cls.get_used_memory_percent()33 return m34if __name__ == '__main__':35 while True:...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

Why Agile Teams Have to Understand How to Analyze and Make adjustments

How do we acquire knowledge? This is one of the seemingly basic but critical questions you and your team members must ask and consider. We are experts; therefore, we understand why we study and what we should learn. However, many of us do not give enough thought to how we learn.

How To Write End-To-End Tests Using Cypress App Actions

When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.

QA’s and Unit Testing – Can QA Create Effective Unit Tests

Unit testing is typically software testing within the developer domain. As the QA role expands in DevOps, QAOps, DesignOps, or within an Agile team, QA testers often find themselves creating unit tests. QA testers may create unit tests within the code using a specified unit testing tool, or independently using a variety of methods.

Getting Started with SpecFlow Actions [SpecFlow Automation Tutorial]

With the rise of Agile, teams have been trying to minimize the gap between the stakeholders and the development team.

Get A Seamless Digital Experience With #LambdaTestYourBusiness????

The holidays are just around the corner, and with Christmas and New Year celebrations coming up, everyone is busy preparing for the festivities! And during this busy time of year, LambdaTest also prepped something special for our beloved developers and testers – #LambdaTestYourBusiness

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 lisa 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