Example #1
0
def profiler_main_file_test(caplog, tmpdir):
    caplog.set_level(logging.DEBUG, "prof")
    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."),
    ]
Example #2
0
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 == []
Example #3
0
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' -----"),
    ]
Example #4
0
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' -----")
    ]