How to use add_profiler method in autotest

Best Python code snippet using autotest_python Github


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 = 074 = "baz"75 self.got_setup = False76 self.got_shutdown = False77 def get_name(self):78 return "test"79 def parse_config(self, cfg):80 = cfg.foo81 = cfg.bar82 return True83 def set_data(self, data_dict):84 = data_dict.foo85 = data_dict.bar86 def get_data(self):87 return {"foo":, "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'",, 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 == 42107 assert == "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 == 0119 assert == "baz"120 = 42121 = "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 == 42130 assert == "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 == 0143 assert == "baz"144 = 42145 = "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 Github


Full Screen

...32. Line-by-line memory usage4"""5import os67def add_profiler(file_path):8 new_path = file_path.rsplit('.', 1)[0]+""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 = ''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:


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?