#At file:///home/malff/BZR_TREE/mysql-trunk-perfschema/ based on revid:marc.alff@stripped
2944 Marc Alff 2009-11-05
WL#2360 Performance Schema
Completed the instrumentation for file STAT and FSTAT.
modified:
include/mysql/psi/mysql_file.h
sql/discover.cc
sql/ha_partition.cc
sql/handler.cc
sql/item_strfunc.cc
sql/log.cc
sql/parse_file.cc
sql/rpl_rli.cc
sql/set_var.cc
sql/sql_db.cc
sql/sql_load.cc
sql/sql_show.cc
sql/sql_table.cc
storage/archive/ha_archive.cc
storage/myisam/mi_info.c
storage/perfschema/pfs.cc
=== modified file 'include/mysql/psi/mysql_file.h'
--- a/include/mysql/psi/mysql_file.h 2009-10-23 00:01:12 +0000
+++ b/include/mysql/psi/mysql_file.h 2009-11-06 03:14:41 +0000
@@ -18,6 +18,8 @@
/* For strlen() */
#include <string.h>
+/* For MY_STAT */
+#include <my_dir.h>
/**
@file mysql/psi/mysql_file.h
@@ -134,18 +136,30 @@
#define mysql_file_feof(F) inline_mysql_file_feof(F)
/**
- @def mysql_file_fstat(K, FN, S, FL)
+ @def mysql_file_fstat(FN, S, FL)
Instrumented fstat.
@c mysql_file_fstat is a replacement for @c my_fstat.
*/
-#define mysql_file_fstat(K, FN, S, FL) my_fstat(FN, S, FL)
+#ifdef HAVE_PSI_INTERFACE
+ #define mysql_file_fstat(FN, S, FL) \
+ inline_mysql_file_fstat(__FILE__, __LINE__, FN, S, FL)
+#else
+ #define mysql_file_fstat(FN, S, FL) \
+ inline_mysql_file_fstat(FN, S, FL)
+#endif
/**
@def mysql_file_stat(K, FN, S, FL)
Instrumented stat.
@c mysql_file_stat is a replacement for @c my_stat.
*/
-#define mysql_file_stat(K, FN, S, FL) my_stat(FN, S, FL)
+#ifdef HAVE_PSI_INTERFACE
+ #define mysql_file_stat(K, FN, S, FL) \
+ inline_mysql_file_stat(K, __FILE__, __LINE__, FN, S, FL)
+#else
+ #define mysql_file_stat(K, FN, S, FL) \
+ inline_mysql_file_stat(FN, S, FL)
+#endif
/**
@def mysql_file_chsize(F, P1, P2, P3)
@@ -675,6 +689,58 @@ static inline int inline_mysql_file_feof
}
static inline int
+inline_mysql_file_fstat(
+#ifdef HAVE_PSI_INTERFACE
+ const char *src_file, uint src_line,
+#endif
+ int filenr, MY_STAT *stat_area, myf flags)
+{
+ int result;
+#ifdef HAVE_PSI_INTERFACE
+ struct PSI_file_locker *locker= NULL;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_descriptor_locker(filenr,
+ PSI_FILE_FSTAT);
+ if (likely(locker != NULL))
+ PSI_server->start_file_wait(locker, (size_t) 0, src_file, src_line);
+ }
+#endif
+ result= my_fstat(filenr, stat_area, flags);
+#ifdef HAVE_PSI_INTERFACE
+ if (likely(locker != NULL))
+ PSI_server->end_file_wait(locker, (size_t) 0);
+#endif
+ return result;
+}
+
+static inline MY_STAT *
+inline_mysql_file_stat(
+#ifdef HAVE_PSI_INTERFACE
+ PSI_file_key key, const char *src_file, uint src_line,
+#endif
+ const char *path, MY_STAT *stat_area, myf flags)
+{
+ MY_STAT *result;
+#ifdef HAVE_PSI_INTERFACE
+ struct PSI_file_locker *locker= NULL;
+ if (likely(PSI_server != NULL))
+ {
+ locker= PSI_server->get_thread_file_name_locker(key, PSI_FILE_STAT,
+ path, &locker);
+ if (likely(locker != NULL))
+ PSI_server->start_file_open_wait(locker, src_file, src_line);
+ }
+#endif
+ result= my_stat(path, stat_area, flags);
+#ifdef HAVE_PSI_INTERFACE
+ if (likely(locker != NULL))
+ PSI_server->end_file_wait(locker, (size_t) 0);
+#endif
+ return result;
+}
+
+static inline int
inline_mysql_file_chsize(
#ifdef HAVE_PSI_INTERFACE
const char *src_file, uint src_line,
=== modified file 'sql/discover.cc'
--- a/sql/discover.cc 2009-10-01 15:44:07 +0000
+++ b/sql/discover.cc 2009-11-06 03:14:41 +0000
@@ -66,7 +66,7 @@ int readfrm(const char *name, uchar **fr
// Get length of file
error= 2;
- if (my_fstat(file, &state, MYF(0)))
+ if (mysql_file_fstat(file, &state, MYF(0)))
goto err;
read_len= state.st_size;
=== modified file 'sql/ha_partition.cc'
--- a/sql/ha_partition.cc 2009-11-03 22:02:10 +0000
+++ b/sql/ha_partition.cc 2009-11-06 03:14:41 +0000
@@ -2389,7 +2389,7 @@ bool ha_partition::get_from_handler_file
DBUG_RETURN(FALSE);
fn_format(buff, name, "", ha_par_ext, MY_APPEND_EXT);
- /* Following could be done with my_stat to read in whole file */
+ /* Following could be done with mysql_file_stat to read in whole file */
if ((file= mysql_file_open(key_file_partition,
buff, O_RDONLY | O_SHARE, MYF(0))) < 0)
DBUG_RETURN(TRUE);
=== modified file 'sql/handler.cc'
--- a/sql/handler.cc 2009-11-03 22:02:10 +0000
+++ b/sql/handler.cc 2009-11-06 03:14:41 +0000
@@ -4871,7 +4871,7 @@ err:
enum log_status fl_get_log_status(char *log)
{
MY_STAT stat_buff;
- if (my_stat(log, &stat_buff, MYF(0)))
+ if (mysql_file_stat(INSTRUMENT_ME, log, &stat_buff, MYF(0)))
return HA_LOG_STATUS_INUSE;
return HA_LOG_STATUS_NOSUCHLOG;
}
=== modified file 'sql/item_strfunc.cc'
--- a/sql/item_strfunc.cc 2009-10-13 00:48:16 +0000
+++ b/sql/item_strfunc.cc 2009-11-06 03:14:41 +0000
@@ -3000,7 +3000,7 @@ String *Item_load_file::val_str(String *
strncmp(opt_secure_file_priv, path, strlen(opt_secure_file_priv)))
goto err;
- if (!my_stat(path, &stat_info, MYF(0)))
+ if (!mysql_file_stat(key_file_loadfile, path, &stat_info, MYF(0)))
goto err;
if (!(stat_info.st_mode & S_IROTH))
=== modified file 'sql/log.cc'
--- a/sql/log.cc 2009-11-03 22:02:10 +0000
+++ b/sql/log.cc 2009-11-06 03:14:41 +0000
@@ -3166,7 +3166,7 @@ int MYSQL_BIN_LOG::update_log_index(LOG_
LOG_INFO_EOF to_log not found
LOG_INFO_EMFILE too many files opened
LOG_INFO_FATAL if any other than ENOENT error from
- my_stat() or mysql_file_delete()
+ mysql_file_stat() or mysql_file_delete()
*/
int MYSQL_BIN_LOG::purge_logs(const char *to_log,
@@ -3280,7 +3280,7 @@ int MYSQL_BIN_LOG::purge_logs(const char
ha_binlog_index_purge_file(current_thd, log_info.log_file_name);
MY_STAT s;
- if (!my_stat(log_info.log_file_name, &s, MYF(0)))
+ if (!mysql_file_stat(key_file_binlog, log_info.log_file_name, &s, MYF(0)))
{
if (my_errno == ENOENT)
{
@@ -3294,7 +3294,7 @@ int MYSQL_BIN_LOG::purge_logs(const char
ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
log_info.log_file_name);
}
- sql_print_information("Failed to execute my_stat on file '%s'",
+ sql_print_information("Failed to execute mysql_file_stat on file '%s'",
log_info.log_file_name);
my_errno= 0;
}
@@ -3404,7 +3404,7 @@ err:
@retval
LOG_INFO_PURGE_NO_ROTATE Binary file that can't be rotated
LOG_INFO_FATAL if any other than ENOENT error from
- my_stat() or mysql_file_delete()
+ mysql_file_stat() or mysql_file_delete()
*/
int MYSQL_BIN_LOG::purge_logs_before_date(time_t purge_time)
@@ -3426,7 +3426,8 @@ int MYSQL_BIN_LOG::purge_logs_before_dat
while (strcmp(log_file_name, log_info.log_file_name) &&
!log_in_use(log_info.log_file_name))
{
- if (!my_stat(log_info.log_file_name, &stat_area, MYF(0)))
+ if (!mysql_file_stat(key_file_binlog,
+ log_info.log_file_name, &stat_area, MYF(0)))
{
if (my_errno == ENOENT)
{
@@ -3439,7 +3440,7 @@ int MYSQL_BIN_LOG::purge_logs_before_dat
ER_LOG_PURGE_NO_FILE, ER(ER_LOG_PURGE_NO_FILE),
log_info.log_file_name);
}
- sql_print_information("Failed to execute my_stat on file '%s'",
+ sql_print_information("Failed to execute mysql_file_stat on file '%s'",
log_info.log_file_name);
my_errno= 0;
}
=== modified file 'sql/parse_file.cc'
--- a/sql/parse_file.cc 2009-10-01 15:44:07 +0000
+++ b/sql/parse_file.cc 2009-11-06 03:14:41 +0000
@@ -366,7 +366,8 @@ sql_parse_prepare(const LEX_STRING *file
File file;
DBUG_ENTER("sql_parse_prepare");
- if (!my_stat(file_name->str, &stat_info, MYF(MY_WME)))
+ if (!mysql_file_stat(key_file_fileparser,
+ file_name->str, &stat_info, MYF(MY_WME)))
{
DBUG_RETURN(0);
}
=== modified file 'sql/rpl_rli.cc'
--- a/sql/rpl_rli.cc 2009-10-28 20:59:30 +0000
+++ b/sql/rpl_rli.cc 2009-11-06 03:14:41 +0000
@@ -326,7 +326,8 @@ static inline int add_relay_log(Relay_lo
{
MY_STAT s;
DBUG_ENTER("add_relay_log");
- if (!my_stat(linfo->log_file_name,&s,MYF(0)))
+ if (!mysql_file_stat(key_file_relay_log_info,
+ linfo->log_file_name, &s, MYF(0)))
{
sql_print_error("log %s listed in the index, but failed to stat",
linfo->log_file_name);
=== modified file 'sql/set_var.cc'
--- a/sql/set_var.cc 2009-11-03 22:02:10 +0000
+++ b/sql/set_var.cc 2009-11-06 03:14:41 +0000
@@ -2646,7 +2646,7 @@ static int sys_check_log_path(THD *thd,
goto err;
}
- if (my_stat(path, &f_stat, MYF(0)))
+ if (mysql_file_stat(key_file_misc, path, &f_stat, MYF(0)))
{
/*
A file system object exists. Check if argument is a file and we have
=== modified file 'sql/sql_db.cc'
--- a/sql/sql_db.cc 2009-11-03 22:02:10 +0000
+++ b/sql/sql_db.cc 2009-11-06 03:14:41 +0000
@@ -675,7 +675,7 @@ int mysql_create_db(THD *thd, char *db,
path_len= build_table_filename(path, sizeof(path) - 1, db, "", "", 0);
path[path_len-1]= 0; // Remove last '/' from path
- if (my_stat(path,&stat_info,MYF(0)))
+ if (mysql_file_stat(key_file_misc, path, &stat_info, MYF(0)))
{
if (!(create_options & HA_LEX_CREATE_IF_NOT_EXISTS))
{
=== modified file 'sql/sql_load.cc'
--- a/sql/sql_load.cc 2009-10-23 00:46:44 +0000
+++ b/sql/sql_load.cc 2009-11-06 03:14:41 +0000
@@ -340,7 +340,7 @@ int mysql_load(THD *thd,sql_exchange *ex
MY_RELATIVE_PATH | MY_UNPACK_FILENAME);
#if !defined(__WIN__) && ! defined(__NETWARE__)
MY_STAT stat_info;
- if (!my_stat(name,&stat_info,MYF(MY_WME)))
+ if (!mysql_file_stat(key_file_load, name, &stat_info, MYF(MY_WME)))
DBUG_RETURN(TRUE);
// if we are not in slave thread, the file must be:
=== modified file 'sql/sql_show.cc'
--- a/sql/sql_show.cc 2009-11-03 22:02:10 +0000
+++ b/sql/sql_show.cc 2009-11-06 03:14:41 +0000
@@ -425,7 +425,7 @@ find_files(THD *thd, List<LEX_STRING> *f
end= strend(buff);
if (end != buff && end[-1] == FN_LIBCHAR)
end[-1]= 0; // Remove end FN_LIBCHAR
- if (!my_stat(buff, file->mystat, MYF(0)))
+ if (!mysql_file_stat(key_file_misc, buff, file->mystat, MYF(0)))
continue;
}
#endif
@@ -3501,7 +3501,7 @@ int fill_schema_schemata(THD *thd, TABLE
path_len= build_table_filename(path, sizeof(path) - 1,
lookup_field_vals.db_value.str, "", "", 0);
path[path_len-1]= 0;
- if (!my_stat(path,&stat_info,MYF(0)))
+ if (!mysql_file_stat(key_file_misc, path, &stat_info, MYF(0)))
DBUG_RETURN(0);
}
=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc 2009-11-03 22:02:10 +0000
+++ b/sql/sql_table.cc 2009-11-06 03:14:41 +0000
@@ -4427,7 +4427,7 @@ static int prepare_for_repair(THD *thd,
// Name of data file
strxmov(from, table->s->normalized_path.str, ext[1], NullS);
- if (!my_stat(from, &stat_info, MYF(0)))
+ if (!mysql_file_stat(key_file_misc, from, &stat_info, MYF(0)))
goto end; // Can't use USE_FRM flag
my_snprintf(tmp, sizeof(tmp), "%s-%lx_%lx",
=== modified file 'storage/archive/ha_archive.cc'
--- a/storage/archive/ha_archive.cc 2009-11-03 22:02:10 +0000
+++ b/storage/archive/ha_archive.cc 2009-11-06 03:14:41 +0000
@@ -679,7 +679,7 @@ int ha_archive::create(const char *name,
*/
if ((frm_file= my_open(name_buff, O_RDONLY, MYF(0))) > 0)
{
- if (!my_fstat(frm_file, &file_stat, MYF(MY_WME)))
+ if (!mysql_file_fstat(frm_file, &file_stat, MYF(MY_WME)))
{
frm_ptr= (uchar *)my_malloc(sizeof(uchar) * file_stat.st_size, MYF(0));
if (frm_ptr)
=== modified file 'storage/myisam/mi_info.c'
--- a/storage/myisam/mi_info.c 2009-10-21 21:50:39 +0000
+++ b/storage/myisam/mi_info.c 2009-11-06 03:14:41 +0000
@@ -85,8 +85,7 @@ int mi_status(MI_INFO *info, register MI
x->data_file_name = share->data_file_name;
x->index_file_name = share->index_file_name;
}
- if ((flag & HA_STATUS_TIME) && !mysql_file_fstat(mi_key_file_dfile,
- info->dfile, &state, MYF(0)))
+ if ((flag & HA_STATUS_TIME) && !mysql_file_fstat(info->dfile, &state, MYF(0)))
x->update_time=state.st_mtime;
else
x->update_time=0;
=== modified file 'storage/perfschema/pfs.cc'
--- a/storage/perfschema/pfs.cc 2009-10-17 01:29:55 +0000
+++ b/storage/perfschema/pfs.cc 2009-11-06 03:14:41 +0000
@@ -1967,16 +1967,18 @@ static void end_file_wait_v1(PSI_file_lo
file->m_file_stat.m_write_bytes+= count;
klass->m_file_stat.m_count_write++;
klass->m_file_stat.m_write_bytes+= count;
- break;
- default:
break;
- }
-
- if ((wait->m_operation == OPERATION_TYPE_FILECLOSE) ||
- (wait->m_operation == OPERATION_TYPE_FILESTREAMCLOSE))
+ case OPERATION_TYPE_FILECLOSE:
+ case OPERATION_TYPE_FILESTREAMCLOSE:
+ case OPERATION_TYPE_FILESTAT:
release_file(pfs_locker->m_target.m_file);
- else if (wait->m_operation == OPERATION_TYPE_FILEDELETE)
+ break;
+ case OPERATION_TYPE_FILEDELETE:
destroy_file(wait->m_thread, pfs_locker->m_target.m_file);
+ break;
+ default:
+ break;
+ }
wait->m_thread->m_wait_locker_count--;
}
Attachment: [text/bzr-bundle] bzr/marc.alff@sun.com-20091106031441-qupwfsmoj5q7g0q4.bundle