You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by br...@apache.org on 2002/01/06 09:01:34 UTC

cvs commit: httpd-2.0/modules/loggers mod_log_config.c

brianp      02/01/06 00:01:34

  Modified:    modules/loggers mod_log_config.c
  Log:
  Bypass a strdup and an 8KB local variable in the common case where
  the logger is using the default time format
  
  Revision  Changes    Path
  1.73      +4 -5      httpd-2.0/modules/loggers/mod_log_config.c
  
  Index: mod_log_config.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/loggers/mod_log_config.c,v
  retrieving revision 1.72
  retrieving revision 1.73
  diff -u -r1.72 -r1.73
  --- mod_log_config.c	16 Dec 2001 09:54:14 -0000	1.72
  +++ mod_log_config.c	6 Jan 2002 08:01:34 -0000	1.73
  @@ -450,7 +450,6 @@
   {
       apr_exploded_time_t xt;
       apr_size_t retcode;
  -    char tstr[MAX_STRING_LEN];
   
       /*
   	hi.  i think getting the time again at the end of the request
  @@ -469,7 +468,9 @@
       ap_explode_recent_localtime(&xt, r->request_time);
   #endif
       if (a && *a) {              /* Custom format */
  -        apr_strftime(tstr, &retcode, MAX_STRING_LEN, a, &xt);
  +        char tstr[MAX_STRING_LEN];
  +        apr_strftime(tstr, &retcode, sizeof(tstr), a, &xt);
  +        return apr_pstrdup(r->pool, tstr);
       }
       else {                      /* CLF format */
   	char sign;
  @@ -484,13 +485,11 @@
   	    sign = '+';
   	}
   
  -        apr_snprintf(tstr, sizeof(tstr), "[%02d/%s/%d:%02d:%02d:%02d %c%.2d%.2d]",
  +        return apr_psprintf(r->pool, "[%02d/%s/%d:%02d:%02d:%02d %c%.2d%.2d]",
                   xt.tm_mday, apr_month_snames[xt.tm_mon], xt.tm_year+1900,
                   xt.tm_hour, xt.tm_min, xt.tm_sec,
                   sign, timz / (60*60), timz % (60*60));
       }
  -
  -    return apr_pstrdup(r->pool, tstr);
   }
   
   static const char *log_request_duration(request_rec *r, char *a)
  
  
  

RE: cvs commit: httpd-2.0/modules/loggers mod_log_config.c

Posted by Sander Striker <st...@apache.org>.
> -----Original Message-----
> From: Brian Pane [mailto:bpane@pacbell.net]
> Sent: 06 January 2002 21:49
> To: dev@httpd.apache.org
> Subject: Re: cvs commit: httpd-2.0/modules/loggers mod_log_config.c
> 
> 
> Ben Laurie wrote:
> 
> >brianp@apache.org wrote:
> >
> >>brianp      02/01/06 00:01:34
> >>
> >>  Modified:    modules/loggers mod_log_config.c
> >>  Log:
> >>  Bypass a strdup and an 8KB local variable in the common case where
> >>  the logger is using the default time format
> >>
> >
> >Does that really stop the stack space from being allocated? It seems
> >unlikely to me (I haven't checked).
> >
> 
> You're right.  I just checked, and it didn't stop the space
> from being allocated.  I'll move that branch of the code to
> separate function so that it really works.  (The alternative
> would be to alloc that buffer from a pool, allocating 8KB
> from a pool would cause its own set of problems, because a
> typical pool block doesn't have enough free space to handle
> an alloc that large, so we'd often be allocating a new,
> odd-sized block.)

Not odd-sized.  It would be the next multiple of 4k.  This is a
property of the new pools code.
 
> --Brian

Sander


Re: cvs commit: httpd-2.0/modules/loggers mod_log_config.c

Posted by Brian Pane <bp...@pacbell.net>.
Ben Laurie wrote:

>brianp@apache.org wrote:
>
>>brianp      02/01/06 00:01:34
>>
>>  Modified:    modules/loggers mod_log_config.c
>>  Log:
>>  Bypass a strdup and an 8KB local variable in the common case where
>>  the logger is using the default time format
>>
>
>Does that really stop the stack space from being allocated? It seems
>unlikely to me (I haven't checked).
>

You're right.  I just checked, and it didn't stop the space
from being allocated.  I'll move that branch of the code to
separate function so that it really works.  (The alternative
would be to alloc that buffer from a pool, allocating 8KB
from a pool would cause its own set of problems, because a
typical pool block doesn't have enough free space to handle
an alloc that large, so we'd often be allocating a new,
odd-sized block.)

--Brian




Re: cvs commit: httpd-2.0/modules/loggers mod_log_config.c

Posted by Ben Laurie <be...@algroup.co.uk>.
brianp@apache.org wrote:
> 
> brianp      02/01/06 00:01:34
> 
>   Modified:    modules/loggers mod_log_config.c
>   Log:
>   Bypass a strdup and an 8KB local variable in the common case where
>   the logger is using the default time format

Does that really stop the stack space from being allocated? It seems
unlikely to me (I haven't checked).

Cheers,

Ben.

> 
>   Revision  Changes    Path
>   1.73      +4 -5      httpd-2.0/modules/loggers/mod_log_config.c
> 
>   Index: mod_log_config.c
>   ===================================================================
>   RCS file: /home/cvs/httpd-2.0/modules/loggers/mod_log_config.c,v
>   retrieving revision 1.72
>   retrieving revision 1.73
>   diff -u -r1.72 -r1.73
>   --- mod_log_config.c  16 Dec 2001 09:54:14 -0000      1.72
>   +++ mod_log_config.c  6 Jan 2002 08:01:34 -0000       1.73
>   @@ -450,7 +450,6 @@
>    {
>        apr_exploded_time_t xt;
>        apr_size_t retcode;
>   -    char tstr[MAX_STRING_LEN];
> 
>        /*
>         hi.  i think getting the time again at the end of the request
>   @@ -469,7 +468,9 @@
>        ap_explode_recent_localtime(&xt, r->request_time);
>    #endif
>        if (a && *a) {              /* Custom format */
>   -        apr_strftime(tstr, &retcode, MAX_STRING_LEN, a, &xt);
>   +        char tstr[MAX_STRING_LEN];
>   +        apr_strftime(tstr, &retcode, sizeof(tstr), a, &xt);
>   +        return apr_pstrdup(r->pool, tstr);
>        }
>        else {                      /* CLF format */
>         char sign;
>   @@ -484,13 +485,11 @@
>             sign = '+';
>         }
> 
>   -        apr_snprintf(tstr, sizeof(tstr), "[%02d/%s/%d:%02d:%02d:%02d %c%.2d%.2d]",
>   +        return apr_psprintf(r->pool, "[%02d/%s/%d:%02d:%02d:%02d %c%.2d%.2d]",
>                    xt.tm_mday, apr_month_snames[xt.tm_mon], xt.tm_year+1900,
>                    xt.tm_hour, xt.tm_min, xt.tm_sec,
>                    sign, timz / (60*60), timz % (60*60));
>        }
>   -
>   -    return apr_pstrdup(r->pool, tstr);
>    }
> 
>    static const char *log_request_duration(request_rec *r, char *a)
> 
> 
> 

--
http://www.apache-ssl.org/ben.html

Re: cvs commit: httpd-2.0/modules/loggers mod_log_config.c

Posted by Ben Laurie <be...@algroup.co.uk>.
brianp@apache.org wrote:
> 
> brianp      02/01/06 00:01:34
> 
>   Modified:    modules/loggers mod_log_config.c
>   Log:
>   Bypass a strdup and an 8KB local variable in the common case where
>   the logger is using the default time format

Does that really stop the stack space from being allocated? It seems
unlikely to me (I haven't checked).

Cheers,

Ben.

> 
>   Revision  Changes    Path
>   1.73      +4 -5      httpd-2.0/modules/loggers/mod_log_config.c
> 
>   Index: mod_log_config.c
>   ===================================================================
>   RCS file: /home/cvs/httpd-2.0/modules/loggers/mod_log_config.c,v
>   retrieving revision 1.72
>   retrieving revision 1.73
>   diff -u -r1.72 -r1.73
>   --- mod_log_config.c  16 Dec 2001 09:54:14 -0000      1.72
>   +++ mod_log_config.c  6 Jan 2002 08:01:34 -0000       1.73
>   @@ -450,7 +450,6 @@
>    {
>        apr_exploded_time_t xt;
>        apr_size_t retcode;
>   -    char tstr[MAX_STRING_LEN];
> 
>        /*
>         hi.  i think getting the time again at the end of the request
>   @@ -469,7 +468,9 @@
>        ap_explode_recent_localtime(&xt, r->request_time);
>    #endif
>        if (a && *a) {              /* Custom format */
>   -        apr_strftime(tstr, &retcode, MAX_STRING_LEN, a, &xt);
>   +        char tstr[MAX_STRING_LEN];
>   +        apr_strftime(tstr, &retcode, sizeof(tstr), a, &xt);
>   +        return apr_pstrdup(r->pool, tstr);
>        }
>        else {                      /* CLF format */
>         char sign;
>   @@ -484,13 +485,11 @@
>             sign = '+';
>         }
> 
>   -        apr_snprintf(tstr, sizeof(tstr), "[%02d/%s/%d:%02d:%02d:%02d %c%.2d%.2d]",
>   +        return apr_psprintf(r->pool, "[%02d/%s/%d:%02d:%02d:%02d %c%.2d%.2d]",
>                    xt.tm_mday, apr_month_snames[xt.tm_mon], xt.tm_year+1900,
>                    xt.tm_hour, xt.tm_min, xt.tm_sec,
>                    sign, timz / (60*60), timz % (60*60));
>        }
>   -
>   -    return apr_pstrdup(r->pool, tstr);
>    }
> 
>    static const char *log_request_duration(request_rec *r, char *a)
> 
> 
> 

--
http://www.apache-ssl.org/ben.html