$request_time has millisecond precision

This commit is contained in:
Igor Sysoev 2007-04-21 07:50:19 +00:00
parent 6047281208
commit b4ccb9f5bd
5 changed files with 16 additions and 9 deletions

View 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();
return ngx_sprintf(buf, "%T", elapsed);
ms = (tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec);
ms = (ms >= 0) ? ms : 0;
return ngx_sprintf(buf, "%T.%03M", ms / 1000, ms % 1000);
}

View 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);

View 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;

View 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;

View 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;