List:Commits« Previous MessageNext Message »
From:Marc Alff Date:October 15 2009 3:10am
Subject:bzr push into mysql-trunk-perfschema branch (marc.alff:2910 to 2911) WL#2360
View as plain text  
 2911 Marc Alff	2009-10-14
      WL#2360 Performance schema
      
      Port from 6.0 continued:
      - added more file io instrumentation
      - fixed broken mutex instrumentation for THR_LOCK_open, THR_LOCK_malloc
      - fixed broken windows build
      - added missing mysql_thread_set_psi_id
      - misc cleanup

    modified:
      mysql-test/suite/perfschema/include/setup_helper.inc
      mysql-test/suite/perfschema/r/one_thread_per_con.result
      mysql-test/suite/perfschema/t/disabled.def
      mysys/charset.c
      mysys/default.c
      mysys/my_init.c
      mysys/my_largepage.c
      mysys/my_lib.c
      mysys/my_lockmem.c
      mysys/my_winfile.c
      mysys/mysys_priv.h
      sql/event_scheduler.cc
      sql/ha_ndbcluster_binlog.cc
      sql/mysql_priv.h
      sql/mysqld.cc
      sql/sql_connect.cc
      sql/sql_insert.cc
      sql/sql_parse.cc
      sql/tztime.cc
 2910 Marc Alff	2009-10-14
      Implementing review comments:
      - tests for tampered performance schema tables
      - cleanup in Buffered_log
      Misc cleanup of the mysql_mutex_lock macro

    added:
      mysql-test/suite/perfschema/r/tampered_perfschema_table1.result
      mysql-test/suite/perfschema/r/tampered_perfschema_table2.result
      mysql-test/suite/perfschema/t/tampered_perfschema_table1-master.opt
      mysql-test/suite/perfschema/t/tampered_perfschema_table1.test
      mysql-test/suite/perfschema/t/tampered_perfschema_table2-master.opt
      mysql-test/suite/perfschema/t/tampered_perfschema_table2.test
    modified:
      include/mysql/psi/mysql_thread.h
      sql/mysqld.cc
      storage/perfschema/pfs_engine_table.cc
=== modified file 'mysql-test/suite/perfschema/include/setup_helper.inc'
--- a/mysql-test/suite/perfschema/include/setup_helper.inc	2009-09-23 08:41:25 +0000
+++ b/mysql-test/suite/perfschema/include/setup_helper.inc	2009-10-15 03:10:24 +0000
@@ -42,7 +42,9 @@ connection default;
 
 --disable_query_log
 prepare stmt_dump_events from
-  "select event_name, source, operation, number_of_bytes
+  "select event_name,
+     left(source, locate(\":\", source)) as short_source,
+     operation, number_of_bytes
   from performance_schema.EVENTS_WAITS_HISTORY_LONG
   where thread_id=? order by event_id;";
 

=== modified file 'mysql-test/suite/perfschema/r/one_thread_per_con.result'
--- a/mysql-test/suite/perfschema/r/one_thread_per_con.result	2009-09-25 15:01:11 +0000
+++ b/mysql-test/suite/perfschema/r/one_thread_per_con.result	2009-10-15 03:10:24 +0000
@@ -15,23 +15,23 @@ create table test.t2(a int) engine=MYISA
 create table test.t3(a int) engine=MYISAM;
 "----------------- Connection default"
 execute stmt_dump_events using @tid;
-event_name	source	operation	number_of_bytes
-wait/synch/mutex/mysys/THR_LOCK_myisam	mi_create.c:581	lock	NULL
+event_name	short_source	operation	number_of_bytes
+wait/synch/mutex/mysys/THR_LOCK_myisam	mi_create.c:	lock	NULL
 execute stmt_dump_thread using @tid;
 name
-thread/sql/OneConnection
+thread/sql/one_connection
 execute stmt_dump_events using @tid;
-event_name	source	operation	number_of_bytes
-wait/synch/mutex/mysys/THR_LOCK_myisam	mi_create.c:581	lock	NULL
+event_name	short_source	operation	number_of_bytes
+wait/synch/mutex/mysys/THR_LOCK_myisam	mi_create.c:	lock	NULL
 execute stmt_dump_thread using @tid;
 name
-thread/sql/OneConnection
+thread/sql/one_connection
 execute stmt_dump_events using @tid;
-event_name	source	operation	number_of_bytes
-wait/synch/mutex/mysys/THR_LOCK_myisam	mi_create.c:581	lock	NULL
+event_name	short_source	operation	number_of_bytes
+wait/synch/mutex/mysys/THR_LOCK_myisam	mi_create.c:	lock	NULL
 execute stmt_dump_thread using @tid;
 name
-thread/sql/OneConnection
+thread/sql/one_connection
 drop table test.t1;
 drop table test.t2;
 drop table test.t3;

=== modified file 'mysql-test/suite/perfschema/t/disabled.def'
--- a/mysql-test/suite/perfschema/t/disabled.def	2009-10-02 07:24:31 +0000
+++ b/mysql-test/suite/perfschema/t/disabled.def	2009-10-15 03:10:24 +0000
@@ -14,8 +14,6 @@ binlog_mix                             :
 binlog_row                             : WL#2360 Port in progress
 binlog_stmt                            : WL#2360 Port in progress
 dml_setup_instruments                  : WL#2360 Port in progress
-no_threads                             : WL#2360 Port in progress
-one_thread_per_con                     : WL#2360 Port in progress
 privilege                              : WL#2360 Port in progress
 server_init                            : WL#2360 Port in progress
 

=== modified file 'mysys/charset.c'
--- a/mysys/charset.c	2009-10-13 00:48:16 +0000
+++ b/mysys/charset.c	2009-10-15 03:10:24 +0000
@@ -339,10 +339,10 @@ static my_bool my_read_charset_file(cons
        !(buf= (uchar*) my_malloc(len,myflags)))
     return TRUE;
   
-  if ((fd=my_open(filename,O_RDONLY,myflags)) < 0)
+  if ((fd= mysql_file_open(key_file_charset, filename, O_RDONLY, myflags)) < 0)
     goto error;
-  tmp_len=my_read(fd, buf, len, myflags);
-  my_close(fd,myflags);
+  tmp_len= mysql_file_read(fd, buf, len, myflags);
+  mysql_file_close(fd, myflags);
   if (tmp_len != len)
     goto error;
   

=== modified file 'mysys/default.c'
--- a/mysys/default.c	2009-03-24 13:58:52 +0000
+++ b/mysys/default.c	2009-10-15 03:10:24 +0000
@@ -654,7 +654,7 @@ static int search_default_file_with_ext(
   static const char includedir_keyword[]= "includedir";
   static const char include_keyword[]= "include";
   const int max_recursion_level= 10;
-  FILE *fp;
+  MYSQL_FILE *fp;
   uint line=0;
   my_bool found_group=0;
   uint i;
@@ -694,10 +694,10 @@ static int search_default_file_with_ext(
     }
   }
 #endif
-  if (!(fp= my_fopen(name, O_RDONLY, MYF(0))))
+  if (!(fp= mysql_file_fopen(key_file_cnf, name, O_RDONLY, MYF(0))))
     return 1;					/* Ignore wrong files */
 
-  while (fgets(buff, sizeof(buff) - 1, fp))
+  while (mysql_file_fgets(buff, sizeof(buff) - 1, fp))
   {
     line++;
     /* Ignore comment and empty lines */
@@ -887,11 +887,11 @@ static int search_default_file_with_ext(
         goto err;
     }
   }
-  my_fclose(fp,MYF(0));
+  mysql_file_fclose(fp,MYF(0));
   return(0);
 
  err:
-  my_fclose(fp,MYF(0));
+  mysql_file_fclose(fp,MYF(0));
   return -1;					/* Fatal error */
 }
 

=== modified file 'mysys/my_init.c'
--- a/mysys/my_init.c	2009-10-13 00:48:16 +0000
+++ b/mysys/my_init.c	2009-10-15 03:10:24 +0000
@@ -656,6 +656,20 @@ static PSI_thread_info all_mysys_threads
 };
 #endif /* USE_ALARM_THREAD */
 
+#ifdef HUGETLB_USE_PROC_MEMINFO
+PSI_file_key key_file_proc_meminfo;
+#endif /* HUGETLB_USE_PROC_MEMINFO */
+PSI_file_key key_file_charset, key_file_cnf;
+
+static PSI_file_info all_mysys_files[]=
+{
+#ifdef HUGETLB_USE_PROC_MEMINFO
+  { &key_file_proc_meminfo, "proc_meminfo", 0},
+#endif /* HUGETLB_USE_PROC_MEMINFO */
+  { &key_file_charset, "charset", 0},
+  { &key_file_cnf, "cnf", 0}
+};
+
 void my_init_mysys_psi_keys()
 {
   const char* category= "mysys";
@@ -674,6 +688,9 @@ void my_init_mysys_psi_keys()
   count= sizeof(all_mysys_threads)/sizeof(all_mysys_threads[0]);
   PSI_server->register_thread(category, all_mysys_threads, count);
 #endif /* USE_ALARM_THREAD */
+
+  count= sizeof(all_mysys_files)/sizeof(all_mysys_files[0]);
+  PSI_server->register_file(category, all_mysys_files, count);
 }
 #endif /* HAVE_PSI_INTERFACE */
 

=== modified file 'mysys/my_largepage.c'
--- a/mysys/my_largepage.c	2007-10-02 07:32:33 +0000
+++ b/mysys/my_largepage.c	2009-10-15 03:10:24 +0000
@@ -91,19 +91,20 @@ void my_large_free(uchar* ptr, myf my_fl
 
 uint my_get_large_page_size_int(void)
 {
-  FILE *f;
+  MYSQL_FILE *f;
   uint size = 0;
   char buf[256];
   DBUG_ENTER("my_get_large_page_size_int");
 
-  if (!(f = my_fopen("/proc/meminfo", O_RDONLY, MYF(MY_WME))))
+  if (!(f= mysql_file_fopen(key_file_proc_meminfo, "/proc/meminfo",
+                            O_RDONLY, MYF(MY_WME))))
     goto finish;
 
-  while (fgets(buf, sizeof(buf), f))
+  while (mysql_file_fgets(buf, sizeof(buf), f))
     if (sscanf(buf, "Hugepagesize: %u kB", &size))
       break;
 
-  my_fclose(f, MYF(MY_WME));
+  mysql_file_fclose(f, MYF(MY_WME));
   
 finish:
   DBUG_RETURN(size * 1024);
@@ -128,7 +129,7 @@ uchar* my_large_malloc_int(size_t size,
   {
     if (my_flags & MY_WME)
       fprintf(stderr,
-              "Warning: Failed to allocate %lu bytesx from HugeTLB memory."
+              "Warning: Failed to allocate %lu bytes from HugeTLB memory."
               " errno %d\n", (ulong) size, errno);
 
     DBUG_RETURN(NULL);

=== modified file 'mysys/my_lib.c'
--- a/mysys/my_lib.c	2009-09-11 20:26:35 +0000
+++ b/mysys/my_lib.c	2009-10-15 03:10:24 +0000
@@ -110,7 +110,7 @@ MY_DIR	*my_dir(const char *path, myf MyF
   DBUG_PRINT("my",("path: '%s' MyFlags: %d",path,MyFlags));
 
 #if defined(THREAD) && !defined(HAVE_READDIR_R)
-  pthread_mutex_lock(&THR_LOCK_open);
+  mysql_mutex_lock(&THR_LOCK_open);
 #endif
 
   dirp = opendir(directory_file_name(tmp_path,(char *) path));
@@ -173,7 +173,7 @@ MY_DIR	*my_dir(const char *path, myf MyF
 
   (void) closedir(dirp);
 #if defined(THREAD) && !defined(HAVE_READDIR_R)
-  pthread_mutex_unlock(&THR_LOCK_open);
+  mysql_mutex_unlock(&THR_LOCK_open);
 #endif
   result->dir_entry= (FILEINFO *)dir_entries_storage->buffer;
   result->number_off_files= dir_entries_storage->elements;
@@ -185,7 +185,7 @@ MY_DIR	*my_dir(const char *path, myf MyF
 
  error:
 #if defined(THREAD) && !defined(HAVE_READDIR_R)
-  pthread_mutex_unlock(&THR_LOCK_open);
+  mysql_mutex_unlock(&THR_LOCK_open);
 #endif
   my_errno=errno;
   if (dirp)

=== modified file 'mysys/my_lockmem.c'
--- a/mysys/my_lockmem.c	2007-05-10 09:59:39 +0000
+++ b/mysys/my_lockmem.c	2009-10-15 03:10:24 +0000
@@ -66,9 +66,9 @@ uchar *my_malloc_lock(uint size,myf MyFl
     element->list.data=(uchar*) element;
     element->page=ptr;
     element->size=size;
-    pthread_mutex_lock(&THR_LOCK_malloc);
+    mysql_mutex_lock(&THR_LOCK_malloc);
     mem_list=list_add(mem_list,&element->list);
-    pthread_mutex_unlock(&THR_LOCK_malloc);
+    mysql_mutex_unlock(&THR_LOCK_malloc);
   }
   DBUG_RETURN(ptr);
 }
@@ -79,7 +79,7 @@ void my_free_lock(uchar *ptr,myf Myflags
   LIST *list;
   struct st_mem_list *element=0;
 
-  pthread_mutex_lock(&THR_LOCK_malloc);
+  mysql_mutex_lock(&THR_LOCK_malloc);
   for (list=mem_list ; list ; list=list->next)
   {
     element=(struct st_mem_list*) list->data;
@@ -90,7 +90,7 @@ void my_free_lock(uchar *ptr,myf Myflags
       break;
     }
   }
-  pthread_mutex_unlock(&THR_LOCK_malloc);
+  mysql_mutex_unlock(&THR_LOCK_malloc);
   if (element)
     my_free((uchar*) element,MYF(0));
   free(ptr);					/* Free even if not locked */

=== modified file 'mysys/my_winfile.c'
--- a/mysys/my_winfile.c	2009-09-30 20:10:22 +0000
+++ b/mysys/my_winfile.c	2009-10-15 03:10:24 +0000
@@ -57,7 +57,7 @@ File my_open_osfhandle(HANDLE handle, in
   uint i;
   DBUG_ENTER("my_open_osfhandle");
 
-  pthread_mutex_lock(&THR_LOCK_open);
+  mysql_mutex_lock(&THR_LOCK_open);
   for(i= MY_FILE_MIN; i < my_file_limit;i++)
   {
     if(my_file_info[i].fhandle == 0)
@@ -70,7 +70,7 @@ File my_open_osfhandle(HANDLE handle, in
       break;
     }
   }
-  pthread_mutex_unlock(&THR_LOCK_open);
+  mysql_mutex_unlock(&THR_LOCK_open);
   if(offset == -1)
     errno= EMFILE; /* to many file handles open */
   DBUG_RETURN(offset);

=== modified file 'mysys/mysys_priv.h'
--- a/mysys/mysys_priv.h	2009-09-30 07:43:17 +0000
+++ b/mysys/mysys_priv.h	2009-10-15 03:10:24 +0000
@@ -68,6 +68,13 @@ extern mysql_mutex_t THR_LOCK_charset, T
 
 #include <mysql/psi/mysql_file.h>
 
+#ifdef HAVE_PSI_INTERFACE
+#ifdef HUGETLB_USE_PROC_MEMINFO
+extern PSI_file_key key_file_proc_meminfo;
+#endif /* HUGETLB_USE_PROC_MEMINFO */
+extern PSI_file_key key_file_charset, key_file_cnf;
+#endif /* HAVE_PSI_INTERFACE */
+
 /*
   EDQUOT is used only in 3 C files only in mysys/. If it does not exist on
   system, we set it to some value which can never happen.

=== modified file 'sql/event_scheduler.cc'
--- a/sql/event_scheduler.cc	2009-09-28 07:12:28 +0000
+++ b/sql/event_scheduler.cc	2009-10-15 03:10:24 +0000
@@ -229,6 +229,9 @@ event_scheduler_thread(void *arg)
   bool res;
 
   thd->thread_stack= (char *)&thd;              // remember where our stack is
+
+  mysql_thread_set_psi_id(thd->thread_id);
+
   res= post_init_event_thread(thd);
 
   DBUG_ENTER("event_scheduler_thread");
@@ -261,6 +264,8 @@ event_worker_thread(void *arg)
 
   thd= event->thd;
 
+  mysql_thread_set_psi_id(thd->thread_id);
+
   Event_worker_thread worker_thread;
   worker_thread.run(thd, event);
 

=== modified file 'sql/ha_ndbcluster_binlog.cc'
--- a/sql/ha_ndbcluster_binlog.cc	2009-10-01 15:44:07 +0000
+++ b/sql/ha_ndbcluster_binlog.cc	2009-10-15 03:10:24 +0000
@@ -3657,6 +3657,8 @@ pthread_handler_t ndb_binlog_thread_func
   thd->thread_id= thread_id++;
   pthread_mutex_unlock(&LOCK_thread_count);
 
+  mysql_thread_set_psi_id(thd->thread_id);
+
   thd->thread_stack= (char*) &thd; /* remember where our stack is */
   if (thd->store_globals())
   {

=== modified file 'sql/mysql_priv.h'
--- a/sql/mysql_priv.h	2009-10-13 00:48:16 +0000
+++ b/sql/mysql_priv.h	2009-10-15 03:10:24 +0000
@@ -1053,6 +1053,7 @@ int check_user(THD *thd, enum enum_serve
 	       const char *passwd, uint passwd_len, const char *db,
 	       bool check_count);
 pthread_handler_t handle_one_connection(void *arg);
+void do_handle_one_connection(THD *thd_arg);
 bool init_new_connection_handler_thread();
 void reset_mqh(LEX_USER *lu, bool get_them);
 bool check_mqh(THD *thd, uint check_command);
@@ -1105,6 +1106,7 @@ void init_max_user_conn(void);
 void init_update_queries(void);
 void free_max_user_conn(void);
 pthread_handler_t handle_bootstrap(void *arg);
+void do_handle_bootstrap(THD *thd);
 int mysql_execute_command(THD *thd);
 bool do_command(THD *thd);
 bool dispatch_command(enum enum_server_command command, THD *thd,
@@ -2040,7 +2042,7 @@ extern const char *log_output_str;
 extern MYSQL_PLUGIN_IMPORT MYSQL_BIN_LOG mysql_bin_log;
 extern LOGGER logger;
 extern TABLE_LIST general_log, slow_log;
-extern FILE *bootstrap_file;
+extern MYSQL_FILE *bootstrap_file;
 extern int bootstrap_error;
 extern FILE *stderror_file;
 extern pthread_key(MEM_ROOT**,THR_MALLOC);
@@ -2611,22 +2613,6 @@ extern PSI_cond_key key_BINLOG_COND_prep
   key_relay_log_info_start_cond, key_relay_log_info_stop_cond,
   key_TABLE_SHARE_cond, key_user_level_lock_cond;
 
-#ifdef __NT__
-extern PSI_thread_key key_thread_handle_con_namedpipes;
-#endif /* __NT__ */
-
-#ifdef HAVE_SMEM
-extern PSI_thread_key key_thread_handle_con_sharedmem;
-#endif /* HAVE_SMEM */
-
-#if (defined(__NT__) || defined(HAVE_SMEM))
-extern PSI_thread_key key_thread_handle_con_sockets;
-#endif /* __NT__ || HAVE_SMEM */
-
-#ifdef __WIN__
-extern PSI_thread_key key_thread_handle_shutdown;
-#endif /* __WIN__ */
-
 extern PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert,
   key_thread_handle_manager, key_thread_kill_server, key_thread_main,
   key_thread_one_connection, key_thread_signal_hand;
@@ -2641,7 +2627,7 @@ extern PSI_file_key key_file_binlog, key
   key_file_loadfile, key_file_log_event_data, key_file_log_event_info,
   key_file_master_info, key_file_misc, key_file_MYSQL_LOG, key_file_partition,
   key_file_pid, key_file_relay_log_info, key_file_send_file, key_file_tclog,
-  key_file_trg, key_file_trn;
+  key_file_trg, key_file_trn, key_file_init;
 
 void init_server_psi_keys();
 #endif /* HAVE_PSI_INTERFACE */

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2009-10-14 23:27:21 +0000
+++ b/sql/mysqld.cc	2009-10-15 03:10:24 +0000
@@ -614,7 +614,7 @@ Lt_creator lt_creator;
 Ge_creator ge_creator;
 Le_creator le_creator;
 
-FILE *bootstrap_file;
+MYSQL_FILE *bootstrap_file;
 int bootstrap_error;
 FILE *stderror_file=0;
 
@@ -986,7 +986,7 @@ void handle_connections_sockets();
 pthread_handler_t handle_connections_sockets_thread(void *arg);
 #endif
 pthread_handler_t kill_server_thread(void *arg);
-static void bootstrap(FILE *file);
+static void bootstrap(MYSQL_FILE *file);
 static bool read_init_file(char *file_name);
 #ifdef _WIN32
 pthread_handler_t handle_connections_namedpipes(void *arg);
@@ -4768,7 +4768,7 @@ we force server id to 2, but this MySQL
   if (opt_bootstrap)
   {
     select_thread_in_use= 0;                    // Allow 'kill' to work
-    bootstrap(stdin);
+    bootstrap(mysql_stdin);
     unireg_abort(bootstrap_error ? 1 : 0);
   }
   if (opt_init_file)
@@ -5069,7 +5069,7 @@ int main(int argc, char **argv)
   create MySQL privilege tables without having to start a full MySQL server.
 */
 
-static void bootstrap(FILE *file)
+static void bootstrap(MYSQL_FILE *file)
 {
   DBUG_ENTER("bootstrap");
 
@@ -5093,16 +5093,16 @@ static void bootstrap(FILE *file)
     DBUG_VOID_RETURN;
   }
   /* Wait for thread to die */
-  (void) pthread_mutex_lock(&LOCK_thread_count);
+  pthread_mutex_lock(&LOCK_thread_count);
   while (in_bootstrap)
   {
-    (void) pthread_cond_wait(&COND_thread_count,&LOCK_thread_count);
+    pthread_cond_wait(&COND_thread_count, &LOCK_thread_count);
     DBUG_PRINT("quit",("One thread died (count=%u)",thread_count));
   }
-  (void) pthread_mutex_unlock(&LOCK_thread_count);
+  pthread_mutex_unlock(&LOCK_thread_count);
 #else
   thd->mysql= 0;
-  handle_bootstrap((void *)thd);
+  do_handle_bootstrap(thd);
 #endif
 
   DBUG_VOID_RETURN;
@@ -5111,13 +5111,14 @@ static void bootstrap(FILE *file)
 
 static bool read_init_file(char *file_name)
 {
-  FILE *file;
+  MYSQL_FILE *file;
   DBUG_ENTER("read_init_file");
   DBUG_PRINT("enter",("name: %s",file_name));
-  if (!(file=my_fopen(file_name,O_RDONLY,MYF(MY_WME))))
+  if (!(file= mysql_file_fopen(key_file_init, file_name,
+                               O_RDONLY, MYF(MY_WME))))
     DBUG_RETURN(TRUE);
   bootstrap(file);
-  (void) my_fclose(file,MYF(MY_WME));
+  mysql_file_fclose(file, MYF(MY_WME));
   DBUG_RETURN(FALSE);
 }
 
@@ -5141,7 +5142,7 @@ void handle_connection_in_main_thread(TH
   threads.append(thd);
   pthread_mutex_unlock(&LOCK_thread_count);
   thd->start_utime= my_micro_time();
-  handle_one_connection(thd);
+  do_handle_one_connection(thd);
 }
 
 
@@ -9463,20 +9464,20 @@ static PSI_cond_info all_server_conds[]=
   { &key_user_level_lock_cond, "User_level_lock::cond", 0}
 };
 
-#ifdef __NT__
-PSI_thread_key key_thread_handle_con_namedpipes;
-#endif /* __NT__ */
+#if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY)
+static PSI_thread_key key_thread_handle_con_namedpipes;
+#endif /* _WIN32 || HAVE_SMEM && !EMBEDDED_LIBRARY */
 
-#ifdef HAVE_SMEM
-PSI_thread_key key_thread_handle_con_sharedmem;
-#endif /* HAVE_SMEM */
+#ifdef defined(HAVE_SMEM) && !defined(EMBEDDED_LIBRARY)
+static PSI_thread_key key_thread_handle_con_sharedmem;
+#endif /* HAVE_SMEM && !EMBEDDED_LIBRARY */
 
-#if (defined(__NT__) || defined(HAVE_SMEM))
-PSI_thread_key key_thread_handle_con_sockets;
-#endif /* __NT__ || HAVE_SMEM */
+#if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY)
+static PSI_thread_key key_thread_handle_con_sockets;
+#endif /* _WIN32 || HAVE_SMEM && !EMBEDDED_LIBRARY */
 
 #ifdef __WIN__
-PSI_thread_key key_thread_handle_shutdown;
+static PSI_thread_key key_thread_handle_shutdown;
 #endif /* __WIN__ */
 
 PSI_thread_key key_thread_bootstrap, key_thread_delayed_insert,
@@ -9485,17 +9486,17 @@ PSI_thread_key key_thread_bootstrap, key
 
 static PSI_thread_info all_server_threads[]=
 {
-#ifdef __NT__
+#if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY)
   { &key_thread_handle_con_namedpipes, "con_named_pipes", PSI_FLAG_GLOBAL},
-#endif /* __NT__ */
+#endif /* _WIN32 || HAVE_SMEM && !EMBEDDED_LIBRARY */
 
-#ifdef HAVE_SMEM
+#ifdef defined(HAVE_SMEM) && !defined(EMBEDDED_LIBRARY)
   { &key_thread_handle_con_sharedmem, "con_shared_mem", PSI_FLAG_GLOBAL},
-#endif /* HAVE_SMEM */
+#endif /* HAVE_SMEM && !EMBEDDED_LIBRARY */
 
-#if (defined(__NT__) || defined(HAVE_SMEM))
+#if (defined(_WIN32) || defined(HAVE_SMEM)) && !defined(EMBEDDED_LIBRARY)
   { &key_thread_handle_con_sockets, "con_sockets", PSI_FLAG_GLOBAL},
-#endif /* __NT__ || HAVE_SMEM */
+#endif /* _WIN32 || HAVE_SMEM && !EMBEDDED_LIBRARY */
 
 #ifdef __WIN__
   { &key_thread_handle_shutdown, "shutdown", PSI_FLAG_GLOBAL},
@@ -9520,7 +9521,7 @@ PSI_file_key key_file_binlog, key_file_b
   key_file_loadfile, key_file_log_event_data, key_file_log_event_info,
   key_file_master_info, key_file_misc, key_file_MYSQL_LOG, key_file_partition,
   key_file_pid, key_file_relay_log_info, key_file_send_file, key_file_tclog,
-  key_file_trg, key_file_trn;
+  key_file_trg, key_file_trn, key_file_init;
 
 static PSI_file_info all_server_files[]=
 {
@@ -9532,7 +9533,7 @@ static PSI_file_info all_server_files[]=
   { &key_file_casetest, "casetest", 0},
   { &key_file_dbopt, "dbopt", 0},
   { &key_file_des_key_file, "des_key_file", 0},
-  { &key_file_ERRMSG, "ERRMSG", PSI_FLAG_GLOBAL},
+  { &key_file_ERRMSG, "ERRMSG", 0},
   { &key_file_exchange, "exchange", 0},
   { &key_file_fileparser, "file_parser", 0},
   { &key_file_frm, "FRM", 0},
@@ -9550,7 +9551,8 @@ static PSI_file_info all_server_files[]=
   { &key_file_send_file, "send_file", 0},
   { &key_file_tclog, "tclog", 0},
   { &key_file_trg, "trigger_name", 0},
-  { &key_file_trn, "trigger", 0}
+  { &key_file_trn, "trigger", 0},
+  { &key_file_init, "init", 0}
 };
 
 /**

=== modified file 'sql/sql_connect.cc'
--- a/sql/sql_connect.cc	2009-10-13 00:48:16 +0000
+++ b/sql/sql_connect.cc	2009-10-15 03:10:24 +0000
@@ -1067,6 +1067,16 @@ pthread_handler_t handle_one_connection(
 {
   THD *thd= (THD*) arg;
 
+  mysql_thread_set_psi_id(thd->thread_id);
+
+  do_handle_one_connection(thd);
+  return 0;
+}
+
+void do_handle_one_connection(THD *thd_arg)
+{
+  THD *thd= thd_arg;
+
   thd->thr_create_utime= my_micro_time();
 
   if (thread_scheduler.init_new_connection_thread())
@@ -1074,7 +1084,7 @@ pthread_handler_t handle_one_connection(
     close_connection(thd, ER_OUT_OF_RESOURCES, 1);
     statistic_increment(aborted_connects,&LOCK_status);
     thread_scheduler.end_thread(thd,0);
-    return 0;
+    return;
   }
 
   /*
@@ -1101,7 +1111,7 @@ pthread_handler_t handle_one_connection(
   */
   thd->thread_stack= (char*) &thd;
   if (setup_connection_thread_globals(thd))
-    return 0;
+    return;
 
   for (;;)
   {
@@ -1127,7 +1137,7 @@ pthread_handler_t handle_one_connection(
 end_thread:
     close_connection(thd, 0, 1);
     if (thread_scheduler.end_thread(thd,1))
-      return 0;                                 // Probably no-threads
+      return;                                 // Probably no-threads
 
     /*
       If end_thread() returns, we are either running with

=== modified file 'sql/sql_insert.cc'
--- a/sql/sql_insert.cc	2009-10-13 00:48:16 +0000
+++ b/sql/sql_insert.cc	2009-10-15 03:10:24 +0000
@@ -2490,6 +2490,8 @@ pthread_handler_t handle_delayed_insert(
   thd->killed=abort_loop ? THD::KILL_CONNECTION : THD::NOT_KILLED;
   pthread_mutex_unlock(&LOCK_thread_count);
 
+  mysql_thread_set_psi_id(thd->thread_id);
+
   /*
     Wait until the client runs into pthread_cond_wait(),
     where we free it after the table is opened and di linked in the list.

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2009-09-28 07:12:28 +0000
+++ b/sql/sql_parse.cc	2009-10-15 03:10:24 +0000
@@ -409,19 +409,14 @@ void execute_init_command(THD *thd, sys_
 }
 
 
-static void handle_bootstrap_impl(THD *thd)
+void do_handle_bootstrap(THD *thd)
 {
-  FILE *file=bootstrap_file;
+  MYSQL_FILE *file= bootstrap_file;
   char *buff;
   const char* found_semicolon= NULL;
 
   DBUG_ENTER("handle_bootstrap");
 
-#ifndef EMBEDDED_LIBRARY
-  pthread_detach_this_thread();
-  thd->thread_stack= (char*) &thd;
-#endif /* EMBEDDED_LIBRARY */
-
   if (thd->variables.max_join_size == HA_POS_ERROR)
     thd->options |= OPTION_BIG_SELECTS;
 
@@ -439,12 +434,12 @@ static void handle_bootstrap_impl(THD *t
 
   buff= (char*) thd->net.buff;
   thd->init_for_queries();
-  while (fgets(buff, thd->net.max_packet, file))
+  while (mysql_file_fgets(buff, thd->net.max_packet, file))
   {
-    char *query, *res;
-    /* strlen() can't be deleted because fgets() doesn't return length */
+    char *query;
+    /* strlen() can't be deleted because mysql_file_fgets() doesn't return length */
     ulong length= (ulong) strlen(buff);
-    while (buff[length-1] != '\n' && !feof(file))
+    while (buff[length-1] != '\n' && !mysql_file_feof(file))
     {
       /*
         We got only a part of the current string. Will try to increase
@@ -458,7 +453,7 @@ static void handle_bootstrap_impl(THD *t
         break;
       }
       buff= (char*) thd->net.buff;
-      res= fgets(buff + length, thd->net.max_packet - length, file);
+      mysql_file_fgets(buff + length, thd->net.max_packet - length, file);
       length+= (ulong) strlen(buff + length);
       /* purecov: end */
     }
@@ -523,6 +518,8 @@ pthread_handler_t handle_bootstrap(void
 {
   THD *thd=(THD*) arg;
 
+  mysql_thread_set_psi_id(thd->thread_id);
+
   /* The following must be called before DBUG_ENTER */
   thd->thread_stack= (char*) &thd;
   if (my_thread_init() || thd->store_globals())
@@ -534,7 +531,11 @@ pthread_handler_t handle_bootstrap(void
     goto end;
   }
 
-  handle_bootstrap_impl(thd);
+#ifndef EMBEDDED_LIBRARY
+  pthread_detach_this_thread();
+#endif /* EMBEDDED_LIBRARY */
+
+  do_handle_bootstrap(thd);
 
 end:
   net_end(&thd->net);

=== modified file 'sql/tztime.cc'
--- a/sql/tztime.cc	2009-09-10 09:18:29 +0000
+++ b/sql/tztime.cc	2009-10-15 03:10:24 +0000
@@ -40,6 +40,7 @@
 #include "tzfile.h"
 #include <m_string.h>
 #include <my_dir.h>
+#include <mysql/psi/mysql_file.h>
 
 /*
   Now we don't use abbreviations in server but we will do this in future.
@@ -156,9 +157,9 @@ tz_load(const char *name, TIME_ZONE_INFO
   uchar *p;
   int read_from_file;
   uint i;
-  FILE *file;
+  MYSQL_FILE *file;
 
-  if (!(file= my_fopen(name, O_RDONLY|O_BINARY, MYF(MY_WME))))
+  if (!(file= mysql_file_fopen(0, name, O_RDONLY|O_BINARY, MYF(MY_WME))))
     return 1;
   {
     union
@@ -175,9 +176,9 @@ tz_load(const char *name, TIME_ZONE_INFO
     uint ttisgmtcnt;
     char *tzinfo_buf;
 
-    read_from_file= my_fread(file, u.buf, sizeof(u.buf), MYF(MY_WME));
+    read_from_file= mysql_file_fread(file, u.buf, sizeof(u.buf), MYF(MY_WME));
 
-    if (my_fclose(file, MYF(MY_WME)) != 0)
+    if (mysql_file_fclose(file, MYF(MY_WME)) != 0)
       return 1;
 
     if (read_from_file < (int)sizeof(struct tzhead))
@@ -1432,7 +1433,7 @@ static MEM_ROOT tz_storage;
   time zone in offset_tzs or creating if it didn't existed before in
   tz_storage. So contention is low.
 */
-static pthread_mutex_t tz_LOCK;
+static mysql_mutex_t tz_LOCK;
 static bool tz_inited= 0;
 
 /*
@@ -1532,6 +1533,27 @@ tz_init_table_list(TABLE_LIST *tz_tabs)
   }
 }
 
+#ifdef HAVE_PSI_INTERFACE
+static PSI_mutex_key key_tz_LOCK;
+
+static PSI_mutex_info all_tz_mutexes[]=
+{
+  { & key_tz_LOCK, "tz_LOCK", PSI_FLAG_GLOBAL}
+};
+
+static void init_tz_psi_keys(void)
+{
+  const char* category= "sql";
+  int count;
+
+  if (PSI_server == NULL)
+    return;
+
+  count= array_elements(all_tz_mutexes);
+  PSI_server->register_mutex(category, all_tz_mutexes, count);
+}
+#endif /* HAVE_PSI_INTERFACE */
+
 
 /*
   Initialize time zone support infrastructure.
@@ -1571,6 +1593,10 @@ my_tz_init(THD *org_thd, const char *def
   int res;
   DBUG_ENTER("my_tz_init");
 
+#ifdef HAVE_PSI_INTERFACE
+  init_tz_psi_keys();
+#endif
+
   /*
     To be able to run this from boot, we allocate a temporary THD
   */
@@ -1595,7 +1621,7 @@ my_tz_init(THD *org_thd, const char *def
     goto end;
   }
   init_alloc_root(&tz_storage, 32 * 1024, 0);
-  VOID(pthread_mutex_init(&tz_LOCK, MY_MUTEX_INIT_FAST));
+  mysql_mutex_init(key_tz_LOCK, &tz_LOCK, MY_MUTEX_INIT_FAST);
   tz_inited= 1;
 
   /* Add 'SYSTEM' time zone to tz_names hash */
@@ -1773,7 +1799,7 @@ void my_tz_free()
   if (tz_inited)
   {
     tz_inited= 0;
-    VOID(pthread_mutex_destroy(&tz_LOCK));
+    mysql_mutex_destroy(&tz_LOCK);
     hash_free(&offset_tzs);
     hash_free(&tz_names);
     free_root(&tz_storage, MYF(0));
@@ -2262,7 +2288,7 @@ my_tz_find(THD *thd, const String *name)
   if (!name)
     DBUG_RETURN(0);
 
-  VOID(pthread_mutex_lock(&tz_LOCK));
+  mysql_mutex_lock(&tz_LOCK);
 
   if (!str_to_offset(name->ptr(), name->length(), &offset))
   {
@@ -2304,7 +2330,7 @@ my_tz_find(THD *thd, const String *name)
     }
   }
 
-  VOID(pthread_mutex_unlock(&tz_LOCK));
+  mysql_mutex_unlock(&tz_LOCK);
 
   DBUG_RETURN(result_tz);
 }


Attachment: [text/bzr-bundle] bzr/marc.alff@sun.com-20091015031024-i90pqcv5y0t6q2rl.bundle
Thread
bzr push into mysql-trunk-perfschema branch (marc.alff:2910 to 2911) WL#2360Marc Alff15 Oct