Esempio n. 1
0
def test_clock_running(fake_time):
    c = util.Clock()
    c.start("total")
    fake_time.value += 3
    c.start("read")
    fake_time.value += 4
    c.stop("read")
    assert str(c) == "[total=7.000000/1, read=4.000000/1]"
Esempio n. 2
0
def test_clock_run(fake_time):
    c = util.Clock()
    with c.run("total"):
        with c.run("a"):
            fake_time.value += 4
        with c.run("b"):
            fake_time.value += 3
    assert str(c) == "[total=7.000000/1, a=4.000000/1, b=3.000000/1]"
Esempio n. 3
0
def test_clock_stop_returns_elapsed_time(fake_time):
    c = util.Clock()

    c.start("read")
    fake_time.value += 1
    assert c.stop("read") == 1

    c.start("read")
    fake_time.value += 2
    assert c.stop("read") == 2
Esempio n. 4
0
def test_benchmark():
    c = util.Clock()
    c.start("connection")
    # We have seen 66,000 requests per single upload with virt-v2v.
    for i in range(50000):
        c.start("request")
        c.start("read")
        c.stop("read")
        c.start("write")
        c.stop("write")
        c.stop("request")
    c.stop("connection")
    print(c)
Esempio n. 5
0
def test_clock_measure(fake_time):
    c = util.Clock()
    c.start("total")
    c.start("read")
    fake_time.value += 1
    c.stop("read")
    c.start("write")
    fake_time.value += 1
    c.stop("write")
    c.start("sync")
    fake_time.value += 1
    c.stop("sync")
    c.stop("total")
    assert str(c) == (
        "[total=3.000000, read=1.000000, write=1.000000, sync=1.000000]")
Esempio n. 6
0
 def __call__(self, env, start_response):
     clock = util.Clock()
     clock.start("request")
     request = webob.Request(env)
     req = RequestInfo(request)
     log.debug("START %s", req)
     try:
         resp = self.dispatch(request, clock)
     except Exception as e:
         if not isinstance(e, HTTPException):
             # Don't expose internal errors to client.
             e = HTTPInternalServerError(detail="Internal server error")
         resp = error_response(e)
         self.log_error(req, resp, e, clock)
         return resp(env, start_response)
     else:
         app_iter = resp(env, start_response)
         res = ResponseInfo(resp)
         return LoggingAppIter(app_iter, req, res, clock)
Esempio n. 7
0
def test_clock_measure_multiple(fake_time):
    c = util.Clock()
    c.start("total")
    c.start("read")
    fake_time.value += 1
    c.stop("read")
    c.start("write")
    fake_time.value += 1
    c.stop("write")
    c.start("read")
    fake_time.value += 1
    c.stop("read")
    c.start("write")
    fake_time.value += 1
    c.stop("write")
    c.start("sync")
    fake_time.value += 1
    c.stop("sync")
    c.stop("total")
    assert str(c) == (
        "[total=5.000000/1, read=2.000000/2, write=2.000000/2, "
        "sync=1.000000/1]")
Esempio n. 8
0
def test_clock_run_recursive():
    c = util.Clock()
    with c.run("started"):
        with pytest.raises(RuntimeError):
            with c.run("started"):
                pass
Esempio n. 9
0
def test_clock_stop_missing():
    c = util.Clock()
    with pytest.raises(RuntimeError):
        c.stop("missing")
Esempio n. 10
0
def test_clock_stop_twice():
    c = util.Clock()
    c.start("stopped")
    c.stop("stopped")
    with pytest.raises(RuntimeError):
        c.stop("stopped")
Esempio n. 11
0
def test_clock_empty():
    c = util.Clock()
    assert str(c) == "[]"