]> git.kaiwu.me - nginx.git/commitdiff
$request_time has millisecond precision
authorIgor Sysoev <igor@sysoev.ru>
Sat, 21 Apr 2007 07:50:19 +0000 (07:50 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Sat, 21 Apr 2007 07:50:19 +0000 (07:50 +0000)
src/http/modules/ngx_http_log_module.c
src/http/ngx_http_core_module.c
src/http/ngx_http_request.c
src/http/ngx_http_request.h
src/http/ngx_http_write_filter_module.c

index e4b861bf070167549ac52c4a6f9a8601729de817..d3ebca4f1677e2aa06e69ade61f496e42dfcbc47 100644 (file)
@@ -170,7 +170,8 @@ static ngx_http_log_var_t  ngx_http_log_vars[] = {
     { ngx_string("time_local"), sizeof("28/Sep/1970:12:00:00 +0600") - 1,
                           ngx_http_log_time },
     { ngx_string("msec"), NGX_TIME_T_LEN + 4, ngx_http_log_msec },
-    { ngx_string("request_time"), NGX_TIME_T_LEN, ngx_http_log_request_time },
+    { ngx_string("request_time"), NGX_TIME_T_LEN + 4,
+                          ngx_http_log_request_time },
     { ngx_string("status"), 3, ngx_http_log_status },
     { ngx_string("bytes_sent"), NGX_OFF_T_LEN, ngx_http_log_bytes_sent },
     { ngx_string("body_bytes_sent"), NGX_OFF_T_LEN,
@@ -394,11 +395,15 @@ static u_char *
 ngx_http_log_request_time(ngx_http_request_t *r, u_char *buf,
     ngx_http_log_op_t *op)
 {
-    time_t  elapsed;
+    ngx_time_t      *tp;
+    ngx_msec_int_t   ms;
 
-    elapsed = ngx_time() - r->start_time;
+    tp = ngx_timeofday();
+
+    ms = (tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec);
+    ms = (ms >= 0) ? ms : 0;
 
-    return ngx_sprintf(buf, "%T", elapsed);
+    return ngx_sprintf(buf, "%T.%03M", ms / 1000, ms % 1000);
 }
 
 
index 7fa0ba3470d5fa4dd5b4008df71a86caf7516263..76f5e9831c81a7ca725e118e1b076e2dde04c9d4 100644 (file)
@@ -1353,8 +1353,6 @@ ngx_http_subrequest(ngx_http_request_t *r,
 
     sr->headers_in = r->headers_in;
 
-    sr->start_time = ngx_time();
-
     ngx_http_clear_content_length(sr);
     ngx_http_clear_accept_ranges(sr);
     ngx_http_clear_last_modified(sr);
index 1a2e1bc27488698c079c45a757e9a9229c71e3b5..9b5d02f94644e34b677fb4689dde5d1297c7c96e 100644 (file)
@@ -212,6 +212,7 @@ ngx_http_init_connection(ngx_connection_t *c)
 static void
 ngx_http_init_request(ngx_event_t *rev)
 {
+    ngx_time_t                 *tp;
     socklen_t                   len;
     ngx_uint_t                  i;
     struct sockaddr_in          sin;
@@ -421,7 +422,9 @@ ngx_http_init_request(ngx_event_t *rev)
 
     r->main = r;
 
-    r->start_time = ngx_time();
+    tp = ngx_timeofday();
+    r->start_sec = tp->sec;
+    r->start_msec = tp->msec;
 
     r->method = NGX_HTTP_UNKNOWN;
 
index 414efd7a2d4f70412b7c310df5f3b55a516e7c3c..a380ac0f0db03d81b6044a1dac8c45e16648a301 100644 (file)
@@ -342,7 +342,8 @@ struct ngx_http_request_s {
     ngx_http_request_body_t          *request_body;
 
     time_t                            lingering_time;
-    time_t                            start_time;
+    time_t                            start_sec;
+    ngx_msec_t                        start_msec;
 
     ngx_uint_t                        method;
     ngx_uint_t                        http_version;
index b25d07e81915aeb68dee0ee1b93d29222f367a78..2015c43ba87c901a8412046c95e20062afae8e98 100644 (file)
@@ -210,7 +210,7 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
     }
 
     if (r->limit_rate) {
-        to_send = r->limit_rate * (ngx_time() - r->start_time + 1) - c->sent;
+        to_send = r->limit_rate * (ngx_time() - r->start_sec + 1) - c->sent;
 
         if (to_send <= 0) {
             c->write->delayed = 1;