Exemple #1
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"
Exemple #2
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'"),
    ]
Exemple #3
0
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()
Exemple #4
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'")
    ]
Exemple #5
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 == []
Exemple #6
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'")
  ]
Exemple #7
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 == []
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()
Exemple #9
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'
Exemple #10
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'
Exemple #11
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' -----"),
    ]
Exemple #12
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 ----------"),
    ]
Exemple #13
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' -----")
    ]
Exemple #14
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 == []
Exemple #15
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 == []
Exemple #16
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' -----")
  ]
Exemple #17
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 == []
Exemple #18
0
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.")
  ]
Exemple #19
0
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."),
    ]
Exemple #20
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()
Exemple #21
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()
Exemple #22
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()