How to use add_profiler method in autotest

Best Python code snippet using autotest_python

profiler_main.py

Source:profiler_main.py Github

copy

Full Screen

...3from amitools.vamos.cfgcore import ConfigDict4def profiler_main_disabled_test(caplog):5 mp = MainProfiler()6 assert mp.parse_config(None)7 assert not mp.add_profiler(Profiler())8 mp.setup()9 mp.shutdown()10 assert caplog.record_tuples == []11def profiler_main_config_test(caplog, tmpdir):12 path = str(tmpdir.join("prof.json"))13 mp = MainProfiler()14 cfg = ConfigDict(15 {"enabled": True, "output": {"dump": True, "file": path, "append": True}}16 )17 assert mp.parse_config(cfg)18 assert mp.enabled19 assert mp.file == path20 assert mp.append21 mp.setup()22 mp.shutdown()23 assert caplog.record_tuples == []24def profiler_main_def_profiler_test(caplog):25 caplog.set_level(logging.INFO)26 p = Profiler()27 mp = MainProfiler(enabled=True)28 cfg = ConfigDict(29 {"enabled": True, "output": {"dump": True, "file": None, "append": True}}30 )31 assert mp.parse_config(cfg)32 assert mp.add_profiler(p)33 mp.setup()34 mp.shutdown()35 assert caplog.record_tuples == [36 ("prof", logging.INFO, "---------- Profiling Results ----------"),37 ("prof", logging.INFO, "----- profiler 'foo' -----"),38 ]39def profiler_main_file_test(caplog, tmpdir):40 caplog.set_level(logging.DEBUG)41 path = str(tmpdir.join("prof.json"))42 p = Profiler()43 mp = MainProfiler(enabled=True)44 cfg = ConfigDict(45 {"enabled": True, "output": {"dump": False, "file": path, "append": True}}46 )47 assert mp.parse_config(cfg)48 assert mp.add_profiler(p)49 mp.setup()50 mp.shutdown()51 assert caplog.record_tuples == [52 ("prof", logging.DEBUG, "added profiler 'foo'"),53 ("prof", logging.DEBUG, "saving profile data to '%s'" % path),54 ("prof", logging.DEBUG, "done saving."),55 ]56 caplog.clear()57 # now repeat setup to test appending58 p = Profiler()59 mp = MainProfiler(enabled=True)60 assert mp.parse_config(cfg)61 assert mp.add_profiler(p)62 mp.setup()63 mp.shutdown()64 assert caplog.record_tuples == [65 ("prof", logging.DEBUG, "added profiler 'foo'"),66 ("prof", logging.DEBUG, "loading profile data from '%s'" % path),67 ("prof", logging.DEBUG, "done loading."),68 ("prof", logging.DEBUG, "saving profile data to '%s'" % path),69 ("prof", logging.DEBUG, "done saving."),70 ]71class MyProfiler(Profiler):72 def __init__(self):73 self.foo = 074 self.bar = "baz"75 self.got_setup = False76 self.got_shutdown = False77 def get_name(self):78 return "test"79 def parse_config(self, cfg):80 self.foo = cfg.foo81 self.bar = cfg.bar82 return True83 def set_data(self, data_dict):84 self.foo = data_dict.foo85 self.bar = data_dict.bar86 def get_data(self):87 return {"foo": self.foo, "bar": self.bar}88 def setup(self):89 self.got_setup = True90 def shutdown(self):91 self.got_shutdown = True92 def dump(self, write):93 write("foo=%d, bar='%s'", self.foo, self.bar)94def profiler_main_test_prof_cfg_test():95 p = MyProfiler()96 mp = MainProfiler(enabled=True)97 cfg = ConfigDict(98 {99 "enabled": True,100 "output": {"dump": True, "file": None, "append": True},101 "test": {"foo": 42, "bar": "hello"},102 }103 )104 assert mp.parse_config(cfg)105 assert mp.add_profiler(p)106 assert p.foo == 42107 assert p.bar == "hello"108def profiler_main_test_prof_load_test(tmpdir):109 path = str(tmpdir.join("prof.json"))110 cfg = ConfigDict(111 {"enabled": True, "output": {"dump": True, "file": path, "append": True}}112 )113 p = MyProfiler()114 mp = MainProfiler(enabled=True)115 assert mp.parse_config(cfg)116 assert mp.add_profiler(p)117 mp.setup()118 assert p.foo == 0119 assert p.bar == "baz"120 p.foo = 42121 p.bar = "hello"122 mp.shutdown()123 # load again124 p = MyProfiler()125 mp = MainProfiler(enabled=True)126 assert mp.parse_config(cfg)127 assert mp.add_profiler(p)128 mp.setup()129 assert p.foo == 42130 assert p.bar == "hello"131 mp.shutdown()132def profiler_main_test_prof_dump_test(caplog):133 caplog.set_level(logging.INFO)134 cfg = ConfigDict(135 {"enabled": True, "output": {"dump": True, "file": None, "append": True}}136 )137 p = MyProfiler()138 mp = MainProfiler(enabled=True)139 assert mp.parse_config(cfg)140 assert mp.add_profiler(p)141 mp.setup()142 assert p.foo == 0143 assert p.bar == "baz"144 p.foo = 42145 p.bar = "hello"146 mp.shutdown()147 assert caplog.record_tuples == [148 ("prof", logging.INFO, "---------- Profiling Results ----------"),149 ("prof", logging.INFO, "----- profiler 'test' -----"),150 ("prof", logging.INFO, "foo=42, bar='hello'"),...

Full Screen

Full Screen

unused_code_checker.py

Source:unused_code_checker.py Github

copy

Full Screen

...32. Line-by-line memory usage4"""5import os67def add_profiler(file_path):8 new_path = file_path.rsplit('.', 1)[0]+"_with_descriptors.py"9 fin = open(file_path, "r")10 fout = open(new_path, "w")1112 for line in fin:13 fout.write(line.replace('def ', '@profile \ndef '))1415 fin.close()16 fout.close()17 return new_path1819if __name__ == "__main__":20 file_path = 'demo.py'2122 # 1. Check unused imports, variables and functions (Used 'vulture' package)23 os.system('vulture ' + file_path)2425 # 2. Line-by-line memory usage26 new_path = add_profiler(file_path)27 os.system('python -m memory_profiler ' + new_path)2829 # 3. Time-based memory usage graph30 os.system('mprof run ' + new_path) ...

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