Created
April 8, 2011 20:14
-
-
Save kpumuk/910611 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/ngx_http_lua_hook.c b/src/ngx_http_lua_hook.c | |
index b36d751..2d8a017 100644 | |
--- a/src/ngx_http_lua_hook.c | |
+++ b/src/ngx_http_lua_hook.c | |
@@ -1671,6 +1671,37 @@ ngx_http_lua_ngx_time(lua_State *L) | |
int | |
+ngx_http_lua_ngx_response_time(lua_State *L) | |
+{ | |
+ ngx_http_request_t *r; | |
+ ngx_time_t *tp; | |
+ ngx_msec_int_t ms; | |
+ | |
+ lua_getglobal(L, GLOBALS_SYMBOL_REQUEST); | |
+ r = lua_touserdata(L, -1); | |
+ lua_pop(L, 1); | |
+ | |
+ if (r == NULL) { | |
+ return luaL_error(L, "no request object found"); | |
+ } | |
+ | |
+ if (lua_gettop(L) > 0) { | |
+ return luaL_error(L, "shouldn't have argument"); | |
+ } | |
+ | |
+ tp = ngx_timeofday(); | |
+ | |
+ ms = (ngx_msec_int_t) | |
+ ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec)); | |
+ ms = (ms >= 0) ? ms : 0; | |
+ | |
+ lua_pushnumber(L, (lua_Number) ms); | |
+ | |
+ return 1; | |
+} | |
+ | |
+ | |
+int | |
ngx_http_lua_ngx_utctime(lua_State *L) | |
{ | |
ngx_http_request_t *r; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment