コード例 #1
0
ファイル: profiler_main.py プロジェクト: ryanm101/amitools
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()
コード例 #2
0
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()
コード例 #3
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."),
    ]
コード例 #4
0
ファイル: profiler_main.py プロジェクト: ryanm101/amitools
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 == []
コード例 #5
0
ファイル: profiler_main.py プロジェクト: ryanm101/amitools
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'"),
    ]
コード例 #6
0
ファイル: libcore_profile.py プロジェクト: jukeks/amitools
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()
コード例 #7
0
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'")
    ]
コード例 #8
0
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"
コード例 #9
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' -----"),
    ]
コード例 #10
0
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 ----------"),
    ]
コード例 #11
0
ファイル: profiler_main.py プロジェクト: ryanm101/amitools
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 == []
コード例 #12
0
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 == []
コード例 #13
0
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'
コード例 #14
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' -----")
    ]