List:Commits« Previous MessageNext Message »
From:Stewart Smith Date:October 30 2008 1:53pm
Subject:bzr push into mysql-5.1 branch (stewart:3020 to 3021)
View as plain text  
 3021 vvaintroub@stripped	2008-10-23
      backport DBUG performance fix on Windows from 6.0
      
      ChangeSet@stripped, 2008-02-05 16:23:57+01:00, vvaintroub@wva. +5 -0
        Preparation for DBUG_PRINT cleanup
        - implement formatted output for pointer, size_t and longlong in
          my_vsnprint
        - use my_vsnprint in DBUG_PRINT (_db_doprnt)
        - change fopen() not to use "a+c" or "w+c" on Windows, but "a+" or "w"
        as on other platforms. Syncing to disk after each write is not really
        needed and slows down tracing considerably.
      
        dbug/dbug.c@stripped, 2008-02-05 16:23:54+01:00, vvaintroub@wva. +4 -9
          -Use my_vsnprintf for formatted output in _db_doprnt ,
          as my_vsnprintf now has possibility to output pointers, longlongs and
          size_t's in uniform C99-compatible fashion on every platform
          - Windows : fopen() trace file with "a+" or "w",
          instead of "a+c" or "w+c".  The later caused FlushFileBuffer() after each
          write, which significantly slowed down  the trace.
      
        include/m_string.h@stripped, 2008-02-05 16:23:54+01:00, vvaintroub@wva. +3 -1
          New function ll2str - convert longlong to string and optionally specify
          case used for by conversion routine (i.e whether hexadecimal letters
          should be uppercase or lowercase)
      
        mysys/my_fopen.c@stripped, 2008-02-05 16:23:55+01:00, vvaintroub@wva. +1 -1
          Replace 0x%lx with %p and remove (long) cast in DBUG_PRINT
      
        strings/longlong2str.c@stripped, 2008-02-05 16:23:55+01:00, vvaintroub@wva. +5 -4
          New function ll2str - convert longlong to string and optionally specify
          case used for by conversion routine (i.e whether hexadecimal letters
          should be uppercase or lowercase)
       strings/my_vsnprintf.c@stripped, 2008-02-05 16:23:55+01:00, vvaintroub@wva. +68 -13
          Additional format specifier support in my_vsnprintf
          %lld,%llx,%p,%zd,%zx - to output longlongs, pointers and size_t's
          %f,%e,%g %F,%E,%G - to output doubles (relies on standard C library)
modified:
  dbug/dbug.c
  include/m_string.h
  mysys/my_fopen.c
  strings/longlong2str.c
  strings/my_vsnprintf.c

 3020 Stewart Smith	2008-10-22
       consistently initialize AlterTabOperation (without this, VS2005 issues warning of new behaviour on initialization - so explicitly initialize to zero)
modified:
  storage/ndb/src/kernel/blocks/dbtup/Dbtup.hpp

=== modified file 'dbug/dbug.c'
--- a/dbug/dbug.c	2008-05-02 17:42:34 +0000
+++ b/dbug/dbug.c	2008-10-23 12:15:16 +0000
@@ -238,6 +238,7 @@ typedef struct _db_code_state_ {
   uint u_line;                  /* User source code line number */
   int  locked;                  /* If locked with _db_lock_file_ */
   const char *u_keyword;        /* Keyword for current macro */
+  char cvtbuf[1024];            /* Conversion buffer */
 } CODE_STATE;
 
 /*
@@ -1158,8 +1159,8 @@ void _db_doprnt_(const char *format,...)
     else
       (void) fprintf(cs->stack->out_file, "%s: ", cs->func);
     (void) fprintf(cs->stack->out_file, "%s: ", cs->u_keyword);
-    (void) vfprintf(cs->stack->out_file, format, args);
-    (void) fputc('\n',cs->stack->out_file);
+    (void) my_vsnprintf(cs->cvtbuf, sizeof(cs->cvtbuf), format, args);
+    (void) fprintf(cs->stack->out_file,"%s\n",cs->cvtbuf);
     dbug_flush(cs);
     errno=save_errno;
   }
@@ -1851,13 +1852,7 @@ static void DBUGOpenFile(CODE_STATE *cs,
       else
       {
         newfile= !EXISTS(name);
-        if (!(fp= fopen(name,
-#if defined(MSDOS) || defined(__WIN__)
-		append ? "a+c" : "wc"
-#else
-                append ? "a+" : "w"
-#endif
-		)))
+        if (!(fp= fopen(name, append ? "a+" : "w")))
         {
           (void) fprintf(stderr, ERR_OPEN, cs->process, name);
           perror("");

=== modified file 'include/m_string.h'
--- a/include/m_string.h	2008-02-08 11:13:33 +0000
+++ b/include/m_string.h	2008-10-23 12:15:16 +0000
@@ -215,6 +215,7 @@ extern char *str2int(const char *src,int
 			 long *val);
 longlong my_strtoll10(const char *nptr, char **endptr, int *error);
 #if SIZEOF_LONG == SIZEOF_LONG_LONG
+#define ll2str(A,B,C,D) int2str((A),(B),(C),(D))
 #define longlong2str(A,B,C) int2str((A),(B),(C),1)
 #define longlong10_to_str(A,B,C) int10_to_str((A),(B),(C))
 #undef strtoll
@@ -228,7 +229,8 @@ longlong my_strtoll10(const char *nptr, 
 #endif
 #else
 #ifdef HAVE_LONG_LONG
-extern char *longlong2str(longlong val,char *dst,int radix);
+extern char *ll2str(longlong val,char *dst,int radix, int upcase);
+#define longlong2str(A,B,C) ll2str((A),(B),(C),1)
 extern char *longlong10_to_str(longlong val,char *dst,int radix);
 #if (!defined(HAVE_STRTOULL) || defined(NO_STRTOLL_PROTO))
 extern longlong strtoll(const char *str, char **ptr, int base);

=== modified file 'mysys/my_fopen.c'
--- a/mysys/my_fopen.c	2007-08-13 13:11:25 +0000
+++ b/mysys/my_fopen.c	2008-10-23 12:15:16 +0000
@@ -79,7 +79,7 @@ FILE *my_fopen(const char *filename, int
       my_file_total_opened++;
       my_file_info[fileno(fd)].type = STREAM_BY_FOPEN;
       pthread_mutex_unlock(&THR_LOCK_open);
-      DBUG_PRINT("exit",("stream: 0x%lx", (long) fd));
+      DBUG_PRINT("exit",("stream: %p", fd));
       DBUG_RETURN(fd);
     }
     pthread_mutex_unlock(&THR_LOCK_open);

=== modified file 'strings/longlong2str.c'
--- a/strings/longlong2str.c	2007-10-31 09:34:26 +0000
+++ b/strings/longlong2str.c	2008-10-23 12:15:16 +0000
@@ -40,17 +40,18 @@
 #include <my_global.h>
 #include "m_string.h"
 
-#if defined(HAVE_LONG_LONG) && !defined(longlong2str) && !defined(HAVE_LONGLONG2STR)
+#if defined(HAVE_LONG_LONG) && (SIZEOF_LONG != SIZEOF_LONG_LONG) && !defined(HAVE_LONGLONG2STR)
 
 /*
   This assumes that longlong multiplication is faster than longlong division.
 */
 
-char *longlong2str(longlong val,char *dst,int radix)
+char *ll2str(longlong val,char *dst,int radix, int upcase)
 {
   char buffer[65];
   register char *p;
   long long_val;
+  char *dig_vec= upcase ? _dig_vec_upper : _dig_vec_lower;
   ulonglong uval= (ulonglong) val;
 
   if (radix < 0)
@@ -80,14 +81,14 @@ char *longlong2str(longlong val,char *ds
   {
     ulonglong quo= uval/(uint) radix;
     uint rem= (uint) (uval- quo* (uint) radix);
-    *--p = _dig_vec_upper[rem];
+    *--p = dig_vec[rem];
     uval= quo;
   }
   long_val= (long) uval;
   while (long_val != 0)
   {
     long quo= long_val/radix;
-    *--p = _dig_vec_upper[(uchar) (long_val - quo*radix)];
+    *--p = dig_vec[(uchar) (long_val - quo*radix)];
     long_val= quo;
   }
   while ((*dst++ = *p++) != 0) ;

=== modified file 'strings/my_vsnprintf.c'
--- a/strings/my_vsnprintf.c	2007-06-01 08:12:06 +0000
+++ b/strings/my_vsnprintf.c	2008-10-23 12:15:16 +0000
@@ -30,9 +30,15 @@
 
   IMPLEMENTION:
     Supports following formats:
-    %#[l]d
-    %#[l]u
-    %#[l]x
+    %#[l][l]d
+    %#[l][l]u
+    %#[l][l]x
+    %p
+    %zd
+    %zx
+    %f
+    %g
+    %e
     %#.#b 	Local format; note first # is ignored and second is REQUIRED
     %#.#s	Note first # is ignored
     
@@ -43,8 +49,9 @@
 size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap)
 {
   char *start=to, *end=to+n-1;
+  const char *percent_pos;
   size_t length, width;
-  uint pre_zero, have_long;
+  uint pre_zero, have_long, have_longlong;
 
   for (; *fmt ; fmt++)
   {
@@ -55,12 +62,13 @@ size_t my_vsnprintf(char *to, size_t n, 
       *to++= *fmt;			/* Copy ordinary char */
       continue;
     }
+    percent_pos = fmt;
     fmt++;					/* skip '%' */
     /* Read max fill size (only used with %d and %u) */
     if (*fmt == '-')
       fmt++;
     length= width= 0;
-    pre_zero= have_long= 0;
+    pre_zero= have_long= have_longlong = 0;
     if (*fmt == '*')
     {
       fmt++;
@@ -90,7 +98,20 @@ size_t my_vsnprintf(char *to, size_t n, 
     if (*fmt == 'l')
     {
       fmt++;
-      have_long= 1;
+      if (fmt[1] != 'l')
+        have_long= 1;
+      else
+      {
+        fmt++;
+        have_longlong= 1;
+      }
+    }
+    else if(*fmt == 'z')
+    {
+      fmt++;
+      have_longlong = (sizeof(size_t) == sizeof(longlong));
+      if(!have_longlong)
+        have_long = 1;
     }
     if (*fmt == 's')				/* String parameter */
     {
@@ -113,29 +134,63 @@ size_t my_vsnprintf(char *to, size_t n, 
       to+= width;
       continue;
     }
-    else if (*fmt == 'd' || *fmt == 'u'|| *fmt== 'x')	/* Integer parameter */
+    else if (*fmt == 'f' || *fmt =='g' || *fmt=='e' ||
+             *fmt == 'F' || *fmt =='G' || *fmt=='E' )
     {
-      register long larg;
+      /* Use standard C library for double to string conversions */
+      char fmtbuf[32];
+      double d= va_arg(ap, double);
+      if(fmt-percent_pos+1 < sizeof(fmtbuf)-1)
+        continue;
+      memmove(fmtbuf, percent_pos, (fmt - percent_pos)+1);
+      fmtbuf[fmt-percent_pos+1]= 0;
+#if (_MSC_VER)
+      /* Microsoft compiler needs _snprintf with underscore*/
+      to+= _snprintf(to, end-to, fmtbuf, d);
+#else
+      to+= snprintf(to, end-to, fmtbuf, d);
+#endif
+      continue;
+    }
+    else if (*fmt == 'd' || *fmt == 'u'|| *fmt== 'x' || *fmt =='p')
+    /* Integer parameter */
+    {
+      register longlong larg;
       size_t res_length, to_length;
       char *store_start= to, *store_end;
       char buff[32];
+      if (*fmt == 'p')
+      {
+       have_longlong= (sizeof(void *) == sizeof(longlong));
+       if(!have_longlong)
+         have_long = 1;
+      }
 
       if ((to_length= (size_t) (end-to)) < 16 || length)
 	store_start= buff;
-      if (have_long)
+      if (have_longlong)
+        larg = va_arg(ap,longlong);
+      else if (have_long)
         larg = va_arg(ap, long);
       else
         if (*fmt == 'd')
           larg = va_arg(ap, int);
         else
-          larg= (long) (uint) va_arg(ap, int);
+          larg= (longlong) (uint) va_arg(ap, int);
       if (*fmt == 'd')
-	store_end= int10_to_str(larg, store_start, -10);
+	store_end= longlong10_to_str(larg, store_start, -10);
       else
         if (*fmt== 'u')
-          store_end= int10_to_str(larg, store_start, 10);
+          store_end= longlong10_to_str(larg, store_start, 10);
+        else if(*fmt == 'p')
+        {
+          store_start[0] = '0';
+          store_start[1] = 'x';
+          store_end= ll2str(larg, store_start + 2, 16, 0);
+        }
         else
-          store_end= int2str(larg, store_start, 16, 0);
+          store_end= ll2str(larg, store_start, 16, 0);
+
       if ((res_length= (size_t) (store_end - store_start)) > to_length)
 	break;					/* num doesn't fit in output */
       /* If %#d syntax was used, we have to pre-zero/pre-space the string */

Thread
bzr push into mysql-5.1 branch (stewart:3020 to 3021) Stewart Smith30 Oct