tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rj...@apache.org
Subject svn commit: r559264 - in /tomcat/connectors/trunk/jk/native/common: jk_logger.h jk_util.c jk_util.h
Date Wed, 25 Jul 2007 00:05:07 GMT
Author: rjung
Date: Tue Jul 24 17:05:02 2007
New Revision: 559264

URL: http://svn.apache.org/viewvc?view=rev&rev=559264
Log:
Minor optimization of new millisecond/microsecond
logging. Timestamps restricted to 64 Bytes, less
copying.

Modified:
    tomcat/connectors/trunk/jk/native/common/jk_logger.h
    tomcat/connectors/trunk/jk/native/common/jk_util.c
    tomcat/connectors/trunk/jk/native/common/jk_util.h

Modified: tomcat/connectors/trunk/jk/native/common/jk_logger.h
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_logger.h?view=diff&rev=559264&r1=559263&r2=559264
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_logger.h (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_logger.h Tue Jul 24 17:05:02 2007
@@ -36,12 +36,11 @@
 {
     void *logger_private;
     int level;
-    const char *log_fmt; /* the configured timestamp format for logging */
-    const char *log_fmt_subsec; /* like log_fmt, but milli/micro seconds
-                                   marker replaced, because strftie() doesn't handle those
*/
-    int log_fmt_type; /* do we want milli or microseconds */
-    int log_fmt_offset; /* at which position shoukd they occur */
-    int log_fmt_size; /* how long is this format string */
+    char *log_fmt;        /* the configured timestamp format for logging */
+    char *log_fmt_subsec; /* like log_fmt, but milli/micro seconds
+                             marker replaced, because strftime() doesn't handle those */
+    char *log_fmt_offset; /* at which position should we insert */
+    int log_fmt_type;     /* do we want milli or microseconds */
 
     int (JK_METHOD * log) (jk_logger_t *l, int level, int used, char *what);
 

Modified: tomcat/connectors/trunk/jk/native/common/jk_util.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_util.c?view=diff&rev=559264&r1=559263&r2=559264
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_util.c (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_util.c Tue Jul 24 17:05:02 2007
@@ -113,7 +113,6 @@
 #define TOMCAT50_BRIDGE_NAME        ("tomcat5")
 
 #define HUGE_BUFFER_SIZE (8*1024)
-#define LOG_LINE_SIZE    (1024)
 
 #define MAKE_WORKER_PARAM(P)     \
         strcpy(buf, "worker.");  \
@@ -127,16 +126,17 @@
  * [Mon Mar 26 19:44:48 2001] [jk_uri_worker_map.c (155)]: Into jk_uri_worker_map_t::uri_worker_map_alloc
  * log format used by apache in error.log
  */
-#define JK_STRFTIME_MILLI "%Q"
-#define JK_STRFTIME_MICRO "%q"
-#define JK_PATTERN_MILLI "XXX"
-#define JK_PATTERN_MICRO "XXXXXX"
-#define JK_TIME_FORMAT_NONE  "[%a %b %d %H:%M:%S %Y] "
-#define JK_TIME_FORMAT_MILLI "[%a %b %d %H:%M:%S." JK_STRFTIME_MILLI " %Y] "
-#define JK_TIME_FORMAT_MICRO "[%a %b %d %H:%M:%S." JK_STRFTIME_MICRO " %Y] "
-#define JK_TIME_SUBSEC_NONE  (0)
-#define JK_TIME_SUBSEC_MILLI (1)
-#define JK_TIME_SUBSEC_MICRO (2)
+#define JK_TIME_CONV_MILLI    "%Q"
+#define JK_TIME_CONV_MICRO    "%q"
+#define JK_TIME_PATTERN_MILLI "000"
+#define JK_TIME_PATTERN_MICRO "000000"
+#define JK_TIME_FORMAT_NONE   "[%a %b %d %H:%M:%S %Y] "
+#define JK_TIME_FORMAT_MILLI  "[%a %b %d %H:%M:%S." JK_TIME_CONV_MILLI " %Y] "
+#define JK_TIME_FORMAT_MICRO  "[%a %b %d %H:%M:%S." JK_TIME_CONV_MICRO " %Y] "
+#define JK_TIME_SUBSEC_NONE   (0)
+#define JK_TIME_SUBSEC_MILLI  (1)
+#define JK_TIME_SUBSEC_MICRO  (2)
+#define JK_TIME_MAX_SIZE      (64)
 
 /* Visual C++ Toolkit 2003 support */
 #if defined (_MSC_VER) && (_MSC_VER == 1310)
@@ -350,11 +350,11 @@
 #endif
 }
 
-void jk_set_time_fmt(jk_logger_t *l, const char *jk_log_fmt)
+void jk_set_time_fmt(jk_logger_t *l, char *jk_log_fmt)
 {
     if (l) {
         char *s;
-        char log_fmt_safe[LOG_LINE_SIZE];
+        char log_fmt_safe[JK_TIME_MAX_SIZE];
         char *fmt;
 
         if (!jk_log_fmt) {
@@ -365,43 +365,40 @@
 #endif
         }
         l->log_fmt_type = JK_TIME_SUBSEC_NONE;
-        l->log_fmt_offset = 0;
-        l->log_fmt_size = 0;
+        l->log_fmt_offset = NULL;
         l->log_fmt_subsec = jk_log_fmt;
         l->log_fmt = jk_log_fmt;
 
-        fmt = (char *)malloc(LOG_LINE_SIZE + strlen(JK_PATTERN_MICRO));
+        fmt = (char *)malloc(JK_TIME_MAX_SIZE + strlen(JK_TIME_PATTERN_MICRO));
         if ( fmt ) {
-            strncpy(log_fmt_safe, jk_log_fmt, LOG_LINE_SIZE);
-            if ( (s = strstr(log_fmt_safe, JK_STRFTIME_MILLI)) ) {
+            strncpy(log_fmt_safe, jk_log_fmt, JK_TIME_MAX_SIZE);
+            if ( (s = strstr(log_fmt_safe, JK_TIME_CONV_MILLI)) ) {
                 int offset = s - log_fmt_safe;
-                int len = strlen(JK_PATTERN_MILLI);
+                int len = strlen(JK_TIME_PATTERN_MILLI);
 
                 l->log_fmt_type = JK_TIME_SUBSEC_MILLI;
-                l->log_fmt_offset = offset;
+                l->log_fmt_offset = fmt + offset;
                 strncpy(fmt, log_fmt_safe, offset);
-                strncpy(fmt + offset, JK_PATTERN_MILLI, len);
+                strncpy(fmt + offset, JK_TIME_PATTERN_MILLI, len);
                 strncpy(fmt + offset + len,
-                        s + strlen(JK_STRFTIME_MILLI),
-                        LOG_LINE_SIZE - offset - len);
-                fmt[LOG_LINE_SIZE-1] = '\0';
+                        s + strlen(JK_TIME_CONV_MILLI),
+                        JK_TIME_MAX_SIZE - offset - len);
+                fmt[JK_TIME_MAX_SIZE-1] = '\0';
                 l->log_fmt_subsec = fmt;
-                l->log_fmt_size = strlen(fmt);
             }
-            else if ( (s = strstr(log_fmt_safe, JK_STRFTIME_MICRO)) ) {
+            else if ( (s = strstr(log_fmt_safe, JK_TIME_CONV_MICRO)) ) {
                 int offset = s - log_fmt_safe;
-                int len = strlen(JK_PATTERN_MICRO);
+                int len = strlen(JK_TIME_PATTERN_MICRO);
 
                 l->log_fmt_type = JK_TIME_SUBSEC_MICRO;
-                l->log_fmt_offset = offset;
+                l->log_fmt_offset = fmt + offset;
                 strncpy(fmt, log_fmt_safe, offset);
-                strncpy(fmt + offset, JK_PATTERN_MICRO, len);
+                strncpy(fmt + offset, JK_TIME_PATTERN_MICRO, len);
                 strncpy(fmt + offset + len,
-                        s + strlen(JK_STRFTIME_MICRO),
-                        LOG_LINE_SIZE - offset - len);
-                fmt[LOG_LINE_SIZE-1] = '\0';
+                        s + strlen(JK_TIME_CONV_MICRO),
+                        JK_TIME_MAX_SIZE - offset - len);
+                fmt[JK_TIME_MAX_SIZE-1] = '\0';
                 l->log_fmt_subsec = fmt;
-                l->log_fmt_size = strlen(fmt);
             }
         }
     }
@@ -412,14 +409,11 @@
     time_t t;
     struct tm *tms;
     int done;
-    char log_fmt[LOG_LINE_SIZE];
 
     if ( !l || !l->log_fmt ) {
         return 0;
     }
 
-    log_fmt[0] = '\0';
-
 #ifndef NO_GETTIMEOFDAY
     if ( l->log_fmt_type != JK_TIME_SUBSEC_NONE ) {
         struct timeval tv;
@@ -427,14 +421,13 @@
         if ( rc == 0 ) {
             char subsec[7];
             t = tv.tv_sec;
-            strncpy(log_fmt, l->log_fmt_subsec, l->log_fmt_size + 1);
             if ( l->log_fmt_type == JK_TIME_SUBSEC_MILLI ) {
                 sprintf(subsec, "%03d", (int)(tv.tv_usec/1000));
-                strncpy(log_fmt + l->log_fmt_offset, subsec, 3);
+                strncpy(l->log_fmt_offset, subsec, 3);
             }
             else if ( l->log_fmt_type == JK_TIME_SUBSEC_MICRO ) {
                 sprintf(subsec, "%06d", (int)(tv.tv_usec));
-                strncpy(log_fmt + l->log_fmt_offset, subsec, 6);
+                strncpy(l->log_fmt_offset, subsec, 6);
             }
         }
         else {
@@ -448,10 +441,15 @@
     t = time(NULL);
 #endif
     tms = localtime(&t);
-    if (log_fmt[0])
-        done = (int)strftime(str, len, log_fmt, tms);
-    else
-        done = (int)strftime(str, len, l->log_fmt, tms);
+    done = (int)strftime(str, len, l->log_fmt_subsec, tms);
+#ifndef NO_GETTIMEOFDAY
+    if ( l->log_fmt_type == JK_TIME_SUBSEC_MILLI ) {
+        strncpy(l->log_fmt_offset, JK_TIME_PATTERN_MILLI, 3);
+    }
+    else if ( l->log_fmt_type == JK_TIME_SUBSEC_MICRO ) {
+        strncpy(l->log_fmt_offset, JK_TIME_PATTERN_MICRO, 6);
+    }
+#endif
     return done;
 
 }

Modified: tomcat/connectors/trunk/jk/native/common/jk_util.h
URL: http://svn.apache.org/viewvc/tomcat/connectors/trunk/jk/native/common/jk_util.h?view=diff&rev=559264&r1=559263&r2=559264
==============================================================================
--- tomcat/connectors/trunk/jk/native/common/jk_util.h (original)
+++ tomcat/connectors/trunk/jk/native/common/jk_util.h Tue Jul 24 17:05:02 2007
@@ -39,7 +39,7 @@
 
 void jk_sleep(int ms);
 
-void jk_set_time_fmt(jk_logger_t *l, const char *jk_log_fmt);
+void jk_set_time_fmt(jk_logger_t *l, char *jk_log_fmt);
 
 int jk_parse_log_level(const char *level);
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message