Skip to content

Commit 57fd117

Browse files
author
Marc Alff
committed
WL#2360 Performance schema
Part II, engines instrumentation
1 parent 34436ed commit 57fd117

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1033
-576
lines changed

include/heap.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2000,2004 MySQL AB
1+
/* Copyright (C) 2000-2004 MySQL AB, 2009 Sun Microsystems, Inc
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -148,7 +148,7 @@ typedef struct st_heap_share
148148
char * name; /* Name of "memory-file" */
149149
#ifdef THREAD
150150
THR_LOCK lock;
151-
pthread_mutex_t intern_lock; /* Locking for use with _locking */
151+
mysql_mutex_t intern_lock; /* Locking for use with _locking */
152152
#endif
153153
my_bool delete_on_close;
154154
LIST open_list;

include/myisam.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2000 MySQL AB
1+
/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -433,7 +433,7 @@ typedef struct st_mi_check_param
433433
const char *op_name;
434434
enum_mi_stats_method stats_method;
435435
#ifdef THREAD
436-
pthread_mutex_t print_msg_mutex;
436+
mysql_mutex_t print_msg_mutex;
437437
my_bool need_print_msg_lock;
438438
#endif
439439
} MI_CHECK;
@@ -460,8 +460,8 @@ typedef struct st_sort_info
460460
/* sync things */
461461
uint got_error, threads_running;
462462
#ifdef THREAD
463-
pthread_mutex_t mutex;
464-
pthread_cond_t cond;
463+
mysql_mutex_t mutex;
464+
mysql_cond_t cond;
465465
#endif
466466
} SORT_INFO;
467467

include/myisammrg.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2000 MySQL AB
1+
/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -75,7 +75,7 @@ typedef struct st_myrg_info
7575
LIST open_list;
7676
QUEUE by_key;
7777
ulong *rec_per_key_part; /* for sql optimizing */
78-
pthread_mutex_t mutex;
78+
mysql_mutex_t mutex;
7979
} MYRG_INFO;
8080

8181

mysys/mysys_priv.h

+45-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2000 MySQL AB
1+
/* Copyright (C) 2000 MySQL AB, 2008-2009 Sun Microsystems, Inc
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -26,12 +26,54 @@
2626

2727
#ifdef THREAD
2828
#include <my_pthread.h>
29+
30+
#ifdef HAVE_PSI_INTERFACE
31+
32+
#if !defined(HAVE_PREAD) && !defined(_WIN32)
33+
extern PSI_mutex_key key_my_file_info_mutex;
34+
#endif /* !defined(HAVE_PREAD) && !defined(_WIN32) */
35+
36+
#if !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R)
37+
extern PSI_mutex_key key_LOCK_localtime_r;
38+
#endif /* !defined(HAVE_LOCALTIME_R) || !defined(HAVE_GMTIME_R) */
39+
40+
#ifndef HAVE_GETHOSTBYNAME_R
41+
extern PSI_mutex_key key_LOCK_gethostbyname_r;
42+
#endif /* HAVE_GETHOSTBYNAME_R */
43+
44+
extern PSI_mutex_key key_BITMAP_mutex, key_IO_CACHE_append_buffer_lock,
45+
key_IO_CACHE_SHARE_mutex, key_KEY_CACHE_cache_lock, key_LOCK_alarm,
46+
key_my_thread_var_mutex, key_THR_LOCK_charset, key_THR_LOCK_heap,
47+
key_THR_LOCK_isam, key_THR_LOCK_lock, key_THR_LOCK_malloc,
48+
key_THR_LOCK_mutex, key_THR_LOCK_myisam, key_THR_LOCK_net,
49+
key_THR_LOCK_open, key_THR_LOCK_threads, key_THR_LOCK_time,
50+
key_TMPDIR_mutex;
51+
52+
extern PSI_cond_key key_COND_alarm, key_IO_CACHE_SHARE_cond,
53+
key_IO_CACHE_SHARE_cond_writer, key_my_thread_var_suspend,
54+
key_THR_COND_threads;
55+
56+
#ifdef USE_ALARM_THREAD
57+
extern PSI_thread_key key_thread_alarm;
58+
#endif /* USE_ALARM_THREAD */
59+
60+
#endif /* HAVE_PSI_INTERFACE */
61+
2962
extern pthread_mutex_t THR_LOCK_malloc, THR_LOCK_open, THR_LOCK_keycache;
3063
extern pthread_mutex_t THR_LOCK_lock, THR_LOCK_isam, THR_LOCK_net;
3164
extern pthread_mutex_t THR_LOCK_charset, THR_LOCK_time;
32-
#else
65+
#else /* THREAD */
3366
#include <my_no_pthread.h>
34-
#endif
67+
#endif /* THREAD */
68+
69+
#include <mysql/psi/mysql_file.h>
70+
71+
#ifdef HAVE_PSI_INTERFACE
72+
#ifdef HUGETLB_USE_PROC_MEMINFO
73+
extern PSI_file_key key_file_proc_meminfo;
74+
#endif /* HUGETLB_USE_PROC_MEMINFO */
75+
extern PSI_file_key key_file_charset, key_file_cnf;
76+
#endif /* HAVE_PSI_INTERFACE */
3577

3678
/*
3779
EDQUOT is used only in 3 C files only in mysys/. If it does not exist on

sql/mysql_priv.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
1+
/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -53,6 +53,7 @@
5353
#include "sql_array.h"
5454
#include "sql_plugin.h"
5555
#include "scheduler.h"
56+
#include <mysql/psi/mysql_file.h>
5657
#ifndef __WIN__
5758
#include <netdb.h>
5859
#endif

sql/sql_class.h

+6
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,12 @@ class THD :public Statement,
18841884
proc_info = msg;
18851885
return old_msg;
18861886
}
1887+
inline const char* enter_cond(mysql_cond_t *cond, mysql_mutex_t *mutex,
1888+
const char *msg)
1889+
{
1890+
/* TO BE REMOVED: temporary helper, to help with merges */
1891+
return enter_cond(&cond->m_cond, &mutex->m_mutex, msg);
1892+
}
18871893
inline void exit_cond(const char* old_msg)
18881894
{
18891895
/*

storage/archive/ha_archive.cc

+50-22
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2003 MySQL AB
1+
/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -95,7 +95,7 @@
9595
*/
9696

9797
/* Variables for archive share methods */
98-
pthread_mutex_t archive_mutex;
98+
mysql_mutex_t archive_mutex;
9999
static HASH archive_open_tables;
100100

101101
/* The file extension */
@@ -145,6 +145,28 @@ static uchar* archive_get_key(ARCHIVE_SHARE *share, size_t *length,
145145
return (uchar*) share->table_name;
146146
}
147147

148+
#ifdef HAVE_PSI_INTERFACE
149+
PSI_mutex_key az_key_mutex_archive_mutex, az_key_mutex_ARCHIVE_SHARE_mutex;
150+
151+
static PSI_mutex_info all_archive_mutexes[]=
152+
{
153+
{ &az_key_mutex_archive_mutex, "archive_mutex", PSI_FLAG_GLOBAL},
154+
{ &az_key_mutex_ARCHIVE_SHARE_mutex, "ARCHIVE_SHARE::mutex", 0}
155+
};
156+
157+
static void init_archive_psi_keys(void)
158+
{
159+
const char* category= "archive";
160+
int count;
161+
162+
if (PSI_server == NULL)
163+
return;
164+
165+
count= array_elements(all_archive_mutexes);
166+
PSI_server->register_mutex(category, all_archive_mutexes, count);
167+
}
168+
169+
#endif /* HAVE_PSI_INTERFACE */
148170

149171
/*
150172
Initialize the archive handler.
@@ -163,19 +185,24 @@ int archive_db_init(void *p)
163185
DBUG_ENTER("archive_db_init");
164186
handlerton *archive_hton;
165187

188+
#ifdef HAVE_PSI_INTERFACE
189+
init_archive_psi_keys();
190+
#endif
191+
166192
archive_hton= (handlerton *)p;
167193
archive_hton->state= SHOW_OPTION_YES;
168194
archive_hton->db_type= DB_TYPE_ARCHIVE_DB;
169195
archive_hton->create= archive_create_handler;
170196
archive_hton->flags= HTON_NO_FLAGS;
171197
archive_hton->discover= archive_discover;
172198

173-
if (pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST))
199+
if (mysql_mutex_init(az_key_mutex_archive_mutex,
200+
&archive_mutex, MY_MUTEX_INIT_FAST))
174201
goto error;
175202
if (my_hash_init(&archive_open_tables, table_alias_charset, 32, 0, 0,
176203
(my_hash_get_key) archive_get_key, 0, 0))
177204
{
178-
pthread_mutex_destroy(&archive_mutex);
205+
mysql_mutex_destroy(&archive_mutex);
179206
}
180207
else
181208
{
@@ -199,7 +226,7 @@ int archive_db_init(void *p)
199226
int archive_db_done(void *p)
200227
{
201228
my_hash_free(&archive_open_tables);
202-
pthread_mutex_destroy(&archive_mutex);
229+
mysql_mutex_destroy(&archive_mutex);
203230

204231
return 0;
205232
}
@@ -313,7 +340,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
313340
uint length;
314341
DBUG_ENTER("ha_archive::get_share");
315342

316-
pthread_mutex_lock(&archive_mutex);
343+
mysql_mutex_lock(&archive_mutex);
317344
length=(uint) strlen(table_name);
318345

319346
if (!(share=(ARCHIVE_SHARE*) my_hash_search(&archive_open_tables,
@@ -328,7 +355,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
328355
&tmp_name, length+1,
329356
NullS))
330357
{
331-
pthread_mutex_unlock(&archive_mutex);
358+
mysql_mutex_unlock(&archive_mutex);
332359
*rc= HA_ERR_OUT_OF_MEM;
333360
DBUG_RETURN(NULL);
334361
}
@@ -346,7 +373,8 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
346373
/*
347374
We will use this lock for rows.
348375
*/
349-
pthread_mutex_init(&share->mutex,MY_MUTEX_INIT_FAST);
376+
mysql_mutex_init(az_key_mutex_ARCHIVE_SHARE_mutex,
377+
&share->mutex, MY_MUTEX_INIT_FAST);
350378

351379
/*
352380
We read the meta file, but do not mark it dirty. Since we are not
@@ -372,7 +400,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
372400
share->use_count));
373401
if (share->crashed)
374402
*rc= HA_ERR_CRASHED_ON_USAGE;
375-
pthread_mutex_unlock(&archive_mutex);
403+
mysql_mutex_unlock(&archive_mutex);
376404

377405
DBUG_RETURN(share);
378406
}
@@ -391,12 +419,12 @@ int ha_archive::free_share()
391419
share->table_name_length, share->table_name,
392420
share->use_count));
393421

394-
pthread_mutex_lock(&archive_mutex);
422+
mysql_mutex_lock(&archive_mutex);
395423
if (!--share->use_count)
396424
{
397425
my_hash_delete(&archive_open_tables, (uchar*) share);
398426
thr_lock_delete(&share->lock);
399-
pthread_mutex_destroy(&share->mutex);
427+
mysql_mutex_destroy(&share->mutex);
400428
/*
401429
We need to make sure we don't reset the crashed state.
402430
If we open a crashed file, wee need to close it as crashed unless
@@ -411,7 +439,7 @@ int ha_archive::free_share()
411439
}
412440
my_free((uchar*) share, MYF(0));
413441
}
414-
pthread_mutex_unlock(&archive_mutex);
442+
mysql_mutex_unlock(&archive_mutex);
415443

416444
DBUG_RETURN(rc);
417445
}
@@ -651,7 +679,7 @@ int ha_archive::create(const char *name, TABLE *table_arg,
651679
*/
652680
if ((frm_file= my_open(name_buff, O_RDONLY, MYF(0))) > 0)
653681
{
654-
if (!my_fstat(frm_file, &file_stat, MYF(MY_WME)))
682+
if (!mysql_file_fstat(frm_file, &file_stat, MYF(MY_WME)))
655683
{
656684
frm_ptr= (uchar *)my_malloc(sizeof(uchar) * file_stat.st_size, MYF(0));
657685
if (frm_ptr)
@@ -800,7 +828,7 @@ int ha_archive::write_row(uchar *buf)
800828
ha_statistic_increment(&SSV::ha_write_count);
801829
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
802830
table->timestamp_field->set_time();
803-
pthread_mutex_lock(&share->mutex);
831+
mysql_mutex_lock(&share->mutex);
804832

805833
if (!share->archive_write_open)
806834
if (init_archive_writer())
@@ -883,7 +911,7 @@ int ha_archive::write_row(uchar *buf)
883911
share->rows_recorded++;
884912
rc= real_write_row(buf, &(share->archive_write));
885913
error:
886-
pthread_mutex_unlock(&share->mutex);
914+
mysql_mutex_unlock(&share->mutex);
887915
if (read_buf)
888916
my_free((uchar*) read_buf, MYF(0));
889917

@@ -1383,7 +1411,7 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt)
13831411
azclose(&archive);
13841412

13851413
// make the file we just wrote be our data file
1386-
rc = my_rename(writer_filename,share->data_file_name,MYF(0));
1414+
rc= my_rename(writer_filename, share->data_file_name, MYF(0));
13871415

13881416

13891417
DBUG_RETURN(rc);
@@ -1467,7 +1495,7 @@ int ha_archive::info(uint flag)
14671495
If dirty, we lock, and then reset/flush the data.
14681496
I found that just calling azflush() doesn't always work.
14691497
*/
1470-
pthread_mutex_lock(&share->mutex);
1498+
mysql_mutex_lock(&share->mutex);
14711499
if (share->dirty == TRUE)
14721500
{
14731501
if (share->dirty == TRUE)
@@ -1483,7 +1511,7 @@ int ha_archive::info(uint flag)
14831511
cause the number to be inaccurate.
14841512
*/
14851513
stats.records= share->rows_recorded;
1486-
pthread_mutex_unlock(&share->mutex);
1514+
mysql_mutex_unlock(&share->mutex);
14871515

14881516
stats.deleted= 0;
14891517

@@ -1508,9 +1536,9 @@ int ha_archive::info(uint flag)
15081536
if (flag & HA_STATUS_AUTO)
15091537
{
15101538
init_archive_reader();
1511-
pthread_mutex_lock(&share->mutex);
1539+
mysql_mutex_lock(&share->mutex);
15121540
azflush(&archive, Z_SYNC_FLUSH);
1513-
pthread_mutex_unlock(&share->mutex);
1541+
mysql_mutex_unlock(&share->mutex);
15141542
stats.auto_increment_value= archive.auto_increment + 1;
15151543
}
15161544

@@ -1578,9 +1606,9 @@ int ha_archive::check(THD* thd, HA_CHECK_OPT* check_opt)
15781606

15791607
old_proc_info= thd_proc_info(thd, "Checking table");
15801608
/* Flush any waiting data */
1581-
pthread_mutex_lock(&share->mutex);
1609+
mysql_mutex_lock(&share->mutex);
15821610
azflush(&(share->archive_write), Z_SYNC_FLUSH);
1583-
pthread_mutex_unlock(&share->mutex);
1611+
mysql_mutex_unlock(&share->mutex);
15841612

15851613
/*
15861614
Now we will rewind the archive file so that we are positioned at the

storage/archive/ha_archive.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2003 MySQL AB
1+
/* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -36,7 +36,7 @@ typedef struct st_archive_share {
3636
char *table_name;
3737
char data_file_name[FN_REFLEN];
3838
uint table_name_length,use_count;
39-
pthread_mutex_t mutex;
39+
mysql_mutex_t mutex;
4040
THR_LOCK lock;
4141
azio_stream archive_write; /* Archive file we are working with */
4242
bool archive_write_open;

0 commit comments

Comments
 (0)