diff --git a/src/script.c b/src/script.c index 68a5d081..dae0e95e 100644 --- a/src/script.c +++ b/src/script.c @@ -164,7 +164,7 @@ void script_request(lua_State *L, char **buf, size_t *len) { lua_pop(L, pop); } -void script_response(lua_State *L, int status, buffer *headers, buffer *body) { +void script_response(lua_State *L, int status, buffer *headers, buffer *body, uint64_t req_latency) { lua_getglobal(L, "response"); lua_pushinteger(L, status); lua_newtable(L); @@ -176,7 +176,8 @@ void script_response(lua_State *L, int status, buffer *headers, buffer *body) { } lua_pushlstring(L, body->buffer, body->cursor - body->buffer); - lua_call(L, 3, 0); + lua_pushnumber(L, req_latency); + lua_call(L, 4, 0); buffer_reset(headers); buffer_reset(body); diff --git a/src/script.h b/src/script.h index 1bf820da..3dc64ead 100644 --- a/src/script.h +++ b/src/script.h @@ -18,7 +18,7 @@ void script_done(lua_State *, stats *, stats *); void script_init(lua_State *, thread *, int, char **); uint64_t script_delay(lua_State *); void script_request(lua_State *, char **, size_t *); -void script_response(lua_State *, int, buffer *, buffer *); +void script_response(lua_State *, int, buffer *, buffer *, uint64_t); size_t script_verify_request(lua_State *L); bool script_is_static(lua_State *); diff --git a/src/wrk.c b/src/wrk.c index 51f46f72..7e56e486 100644 --- a/src/wrk.c +++ b/src/wrk.c @@ -336,7 +336,7 @@ static int response_complete(http_parser *parser) { if (c->headers.buffer) { *c->headers.cursor++ = '\0'; - script_response(thread->L, status, &c->headers, &c->body); + script_response(thread->L, status, &c->headers, &c->body, now - c->start); c->state = FIELD; }