def profiler_main_test_prof_cfg_test(): p = MyProfiler() mp = MainProfiler(enabled=True) cfg = ConfigDict( { "enabled": True, "output": {"dump": True, "file": None, "append": True}, "test": {"foo": 42, "bar": "hello"}, } ) assert mp.parse_config(cfg) assert mp.add_profiler(p) assert p.foo == 42 assert p.bar == "hello"
def profiler_main_test_prof_dump_test(caplog): caplog.set_level(logging.INFO) cfg = ConfigDict({ "enabled": True, "output": { "dump": True, "file": None, "append": True } }) p = MyProfiler() mp = MainProfiler(enabled=True) assert mp.parse_config(cfg) assert mp.add_profiler(p) mp.setup() assert p.foo == 0 assert p.bar == "baz" p.foo = 42 p.bar = "hello" mp.shutdown() assert caplog.record_tuples == [ ("prof", logging.INFO, "---------- Profiling Results ----------"), ("prof", logging.INFO, "----- profiler 'test' -----"), ("prof", logging.INFO, "foo=42, bar='hello'"), ]
def libcore_profiler_main_profiler_test(): name = 'dos.library' fd = read_lib_fd(name) cfg = ConfigDict({ "enabled": True, "libs": { "names": [name], "calls": True }, "output": { "file": None, "append": False, "dump": True } }) mp = MainProfiler() prof = LibProfiler() assert mp.parse_config(cfg) assert mp.add_profiler(prof) mp.setup() assert prof.names == [name] assert prof.add_calls p = prof.create_profile(name, fd) assert p mp.shutdown()
def profiler_main_test_prof_dump_test(caplog): caplog.set_level(logging.INFO) cfg = ConfigDict({ 'enabled': True, 'output': { 'dump': True, 'file': None, 'append': True } }) p = MyProfiler() mp = MainProfiler(enabled=True) assert mp.parse_config(cfg) assert mp.add_profiler(p) mp.setup() assert p.foo == 0 assert p.bar == 'baz' p.foo = 42 p.bar = 'hello' mp.shutdown() assert caplog.record_tuples == [ ('prof', logging.INFO, '---------- Profiling Results ----------'), ('prof', logging.INFO, "----- profiler 'test' -----"), ('prof', logging.INFO, "foo=42, bar='hello'") ]
def profiler_main_disabled_test(caplog): mp = MainProfiler() assert mp.parse_config(None) assert not mp.add_profiler(Profiler()) mp.setup() mp.shutdown() assert caplog.record_tuples == []
def profiler_main_test_prof_cfg_test(): p = MyProfiler() mp = MainProfiler(enabled=True) cfg = ConfigDict({ 'enabled': True, 'output': { 'dump': True, 'file': None, 'append': True }, 'test': { 'foo': 42, 'bar': 'hello' } }) assert mp.parse_config(cfg) assert mp.add_profiler(p) assert p.foo == 42 assert p.bar == 'hello'
def profiler_main_def_profiler_test(caplog): caplog.set_level(logging.INFO, "prof") p = Profiler() mp = MainProfiler(enabled=True) cfg = ConfigDict( {"enabled": True, "output": {"dump": True, "file": None, "append": True}} ) assert mp.parse_config(cfg) assert mp.add_profiler(p) mp.setup() mp.shutdown() assert caplog.record_tuples == [ ("prof", logging.INFO, "---------- Profiling Results ----------"), ("prof", logging.INFO, "----- profiler 'foo' -----"), ]
def profiler_main_config_test(caplog, tmpdir): caplog.set_level(logging.INFO, "prof") path = str(tmpdir.join("prof.json")) mp = MainProfiler() cfg = ConfigDict( {"enabled": True, "output": {"dump": True, "file": path, "append": True}} ) assert mp.parse_config(cfg) assert mp.enabled assert mp.file == path assert mp.append mp.setup() mp.shutdown() assert caplog.record_tuples == [ ("prof", logging.INFO, "---------- Profiling Results ----------"), ]
def profiler_main_def_profiler_test(caplog): caplog.set_level(logging.INFO) p = Profiler() mp = MainProfiler(enabled=True) cfg = ConfigDict({ 'enabled': True, 'output': { 'dump': True, 'file': None, 'append': True } }) assert mp.parse_config(cfg) assert mp.add_profiler(p) mp.setup() mp.shutdown() assert caplog.record_tuples == [ ('prof', logging.INFO, '---------- Profiling Results ----------'), ('prof', logging.INFO, "----- profiler 'foo' -----") ]
def profiler_main_config_test(caplog, tmpdir): path = str(tmpdir.join("prof.json")) mp = MainProfiler() cfg = ConfigDict({ "enabled": True, "output": { "dump": True, "file": path, "append": True } }) assert mp.parse_config(cfg) assert mp.enabled assert mp.file == path assert mp.append mp.setup() mp.shutdown() assert caplog.record_tuples == []
def profiler_main_config_test(caplog, tmpdir): path = str(tmpdir.join("prof.json")) mp = MainProfiler() cfg = ConfigDict({ 'enabled': True, 'output': { 'dump': True, 'file': path, 'append': True } }) assert mp.parse_config(cfg) assert mp.enabled assert mp.file == path assert mp.append mp.setup() mp.shutdown() assert caplog.record_tuples == []
def profiler_main_file_test(caplog, tmpdir): caplog.set_level(logging.DEBUG) path = str(tmpdir.join("prof.json")) p = Profiler() mp = MainProfiler(enabled=True) cfg = ConfigDict({ 'enabled': True, 'output': { 'dump': False, 'file': path, 'append': True } }) assert mp.parse_config(cfg) assert mp.add_profiler(p) mp.setup() mp.shutdown() assert caplog.record_tuples == [ ('prof', logging.DEBUG, "added profiler 'foo'"), ('prof', logging.DEBUG, "saving profile data to '%s'" % path), ('prof', logging.DEBUG, "done saving.") ] caplog.clear() # now repeat setup to test appending p = Profiler() mp = MainProfiler(enabled=True) assert mp.parse_config(cfg) assert mp.add_profiler(p) mp.setup() mp.shutdown() assert caplog.record_tuples == [ ('prof', logging.DEBUG, "added profiler 'foo'"), ('prof', logging.DEBUG, "loading profile data from '%s'" % path), ('prof', logging.DEBUG, "done loading."), ('prof', logging.DEBUG, "saving profile data to '%s'" % path), ('prof', logging.DEBUG, "done saving.") ]
def profiler_main_file_test(caplog, tmpdir): caplog.set_level(logging.DEBUG) path = str(tmpdir.join("prof.json")) p = Profiler() mp = MainProfiler(enabled=True) cfg = ConfigDict({ "enabled": True, "output": { "dump": False, "file": path, "append": True } }) assert mp.parse_config(cfg) assert mp.add_profiler(p) mp.setup() mp.shutdown() assert caplog.record_tuples == [ ("prof", logging.DEBUG, "added profiler 'foo'"), ("prof", logging.DEBUG, "saving profile data to '%s'" % path), ("prof", logging.DEBUG, "done saving."), ] caplog.clear() # now repeat setup to test appending p = Profiler() mp = MainProfiler(enabled=True) assert mp.parse_config(cfg) assert mp.add_profiler(p) mp.setup() mp.shutdown() assert caplog.record_tuples == [ ("prof", logging.DEBUG, "added profiler 'foo'"), ("prof", logging.DEBUG, "loading profile data from '%s'" % path), ("prof", logging.DEBUG, "done loading."), ("prof", logging.DEBUG, "saving profile data to '%s'" % path), ("prof", logging.DEBUG, "done saving."), ]
def profiler_main_test_prof_load_test(tmpdir): path = str(tmpdir.join("prof.json")) cfg = ConfigDict({ 'enabled': True, 'output': { 'dump': True, 'file': path, 'append': True } }) p = MyProfiler() mp = MainProfiler(enabled=True) assert mp.parse_config(cfg) assert mp.add_profiler(p) mp.setup() assert p.foo == 0 assert p.bar == 'baz' p.foo = 42 p.bar = 'hello' mp.shutdown() # load again p = MyProfiler() mp = MainProfiler(enabled=True) assert mp.parse_config(cfg) assert mp.add_profiler(p) mp.setup() assert p.foo == 42 assert p.bar == 'hello' mp.shutdown()
def profiler_main_test_prof_load_test(tmpdir): path = str(tmpdir.join("prof.json")) cfg = ConfigDict({ "enabled": True, "output": { "dump": True, "file": path, "append": True } }) p = MyProfiler() mp = MainProfiler(enabled=True) assert mp.parse_config(cfg) assert mp.add_profiler(p) mp.setup() assert p.foo == 0 assert p.bar == "baz" p.foo = 42 p.bar = "hello" mp.shutdown() # load again p = MyProfiler() mp = MainProfiler(enabled=True) assert mp.parse_config(cfg) assert mp.add_profiler(p) mp.setup() assert p.foo == 42 assert p.bar == "hello" mp.shutdown()