summaryrefslogtreecommitdiff
path: root/sql/sql_profile.cc
diff options
context:
space:
mode:
authorunknown <cmiller@zippy.cornsilk.net>2007-10-31 17:24:32 -0400
committerunknown <cmiller@zippy.cornsilk.net>2007-10-31 17:24:32 -0400
commitcca4ea275bc24a48e48703ed357752c416710a20 (patch)
tree665a520664743bd33169c3aaafedcb407c8c4de5 /sql/sql_profile.cc
parentfc70ac4627c4d7094dc1c1b4d6d61ab81fcd5546 (diff)
parent4c0078853fbd2052270198217aa19d573a516f92 (diff)
downloadmariadb-git-cca4ea275bc24a48e48703ed357752c416710a20.tar.gz
Merge zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community
into zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.1 CMakeLists.txt: Auto merged BitKeeper/deleted/.del-Makefile.am~2: Auto merged BitKeeper/deleted/.del-README~1: Auto merged BitKeeper/deleted/.del-configure.js: Auto merged BitKeeper/deleted/.del-ha_berkeley.cc: Auto merged BitKeeper/triggers/post-commit: Auto merged client/CMakeLists.txt: Auto merged extra/CMakeLists.txt: Auto merged include/config-win.h: Auto merged libmysql/CMakeLists.txt: Auto merged libmysqld/Makefile.am: Auto merged mysql-test/r/func_in.result: Auto merged mysql-test/r/information_schema_db.result: Auto merged mysql-test/t/func_in.test: Auto merged mysql-test/t/information_schema.test: Auto merged server-tools/instance-manager/CMakeLists.txt: Auto merged sql/CMakeLists.txt: Auto merged sql/Makefile.am: Auto merged sql/ha_ndbcluster.cc: Auto merged sql/item_cmpfunc.cc: Auto merged sql/item_func.cc: Auto merged sql/lex.h: Auto merged sql/lock.cc: Auto merged sql/log_event.cc: Auto merged sql/mysql_priv.h: Auto merged sql/mysqld.cc: Auto merged sql/slave.cc: Auto merged sql/sp_head.cc: Auto merged sql/sql_base.cc: Auto merged sql/sql_cache.cc: Auto merged sql/sql_class.cc: Auto merged sql/sql_class.h: Auto merged sql/sql_delete.cc: Auto merged sql/sql_insert.cc: Auto merged sql/sql_lex.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_prepare.cc: Auto merged sql/sql_repl.cc: Auto merged sql/sql_table.cc: Auto merged sql/sql_update.cc: Auto merged sql/sql_view.cc: Auto merged sql/sql_yacc.yy: Auto merged sql/structs.h: Auto merged storage/archive/ha_archive.cc: Auto merged storage/myisam/CMakeLists.txt: Auto merged storage/myisam/ha_myisam.cc: Auto merged storage/myisam/mi_open.c: Auto merged storage/myisammrg/ha_myisammrg.cc: Auto merged storage/ndb/src/ndbapi/DictCache.cpp: Auto merged BitKeeper/deleted/.del-mysqld.vcproj~6aa7b3f9c3e28fcb: Manual merge. configure.in: Manual merge. mysql-test/r/information_schema.result: Manual merge. mysql-test/t/profiling.test: Manual merge. sql/set_var.cc: Manual merge. sql/sql_parse.cc: Manual merge. sql/sql_profile.cc: Manual merge. sql/sql_profile.h: Manual merge. sql/sql_select.cc: Manual merge. sql/sql_show.cc: Manual merge. sql/table.h: Manual merge. storage/ndb/src/common/util/File.cpp: Manual merge. support-files/mysql.spec.sh: Manual merge.
Diffstat (limited to 'sql/sql_profile.cc')
-rw-r--r--sql/sql_profile.cc347
1 files changed, 102 insertions, 245 deletions
diff --git a/sql/sql_profile.cc b/sql/sql_profile.cc
index 90b4c4768af..6083fcd744b 100644
--- a/sql/sql_profile.cc
+++ b/sql/sql_profile.cc
@@ -62,6 +62,56 @@ ST_FIELD_INFO query_profile_statistics_info[]=
{NULL, 0, MYSQL_TYPE_STRING, 0, true, NULL, NULL}
};
+
+int make_profile_table_for_show(THD *thd, ST_SCHEMA_TABLE *schema_table)
+{
+ int profile_options = thd->lex->profile_options;
+ int fields_include_condition_truth_values[]= {
+ FALSE, /* Query_id */
+ FALSE, /* Seq */
+ TRUE, /* Status */
+ TRUE, /* Duration */
+ profile_options & PROFILE_CPU, /* CPU_user */
+ profile_options & PROFILE_CPU, /* CPU_system */
+ profile_options & PROFILE_CONTEXT, /* Context_voluntary */
+ profile_options & PROFILE_CONTEXT, /* Context_involuntary */
+ profile_options & PROFILE_BLOCK_IO, /* Block_ops_in */
+ profile_options & PROFILE_BLOCK_IO, /* Block_ops_out */
+ profile_options & PROFILE_IPC, /* Messages_sent */
+ profile_options & PROFILE_IPC, /* Messages_received */
+ profile_options & PROFILE_PAGE_FAULTS, /* Page_faults_major */
+ profile_options & PROFILE_PAGE_FAULTS, /* Page_faults_minor */
+ profile_options & PROFILE_SWAPS, /* Swaps */
+ profile_options & PROFILE_SOURCE, /* Source_function */
+ profile_options & PROFILE_SOURCE, /* Source_file */
+ profile_options & PROFILE_SOURCE, /* Source_line */
+ };
+
+ ST_FIELD_INFO *field_info;
+ Name_resolution_context *context= &thd->lex->select_lex.context;
+ int i;
+
+ for (i= 0; schema_table->fields_info[i].field_name != NULL; i++)
+ {
+ if (! fields_include_condition_truth_values[i])
+ continue;
+
+ field_info= &schema_table->fields_info[i];
+ Item_field *field= new Item_field(context,
+ NullS, NullS, field_info->field_name);
+ if (field)
+ {
+ field->set_name(field_info->old_name,
+ strlen(field_info->old_name),
+ system_charset_info);
+ if (add_item_to_list(thd, field))
+ return 1;
+ }
+ }
+ return 0;
+}
+
+
#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
#define RUSAGE_USEC(tv) ((tv).tv_sec*1000*1000 + (tv).tv_usec)
@@ -242,212 +292,6 @@ void QUERY_PROFILE::reset()
DBUG_VOID_RETURN;
}
-bool QUERY_PROFILE::show(uint options)
-{
- THD *thd= profiling->thd;
- List<Item> field_list;
- DBUG_ENTER("QUERY_PROFILE::show");
-
- field_list.push_back(new Item_empty_string("Status", MYSQL_ERRMSG_SIZE));
- field_list.push_back(new Item_return_int("Duration", TIME_FLOAT_DIGITS,
- MYSQL_TYPE_DOUBLE));
-
- if (options & PROFILE_CPU)
- {
- field_list.push_back(new Item_return_int("CPU_user", TIME_FLOAT_DIGITS,
- MYSQL_TYPE_DOUBLE));
- field_list.push_back(new Item_return_int("CPU_system", TIME_FLOAT_DIGITS,
- MYSQL_TYPE_DOUBLE));
- }
-
- if (options & PROFILE_MEMORY)
- {
- }
-
- if (options & PROFILE_CONTEXT)
- {
- field_list.push_back(new Item_return_int("Context_voluntary", 10,
- MYSQL_TYPE_LONG));
- field_list.push_back(new Item_return_int("Context_involuntary", 10,
- MYSQL_TYPE_LONG));
- }
-
- if (options & PROFILE_BLOCK_IO)
- {
- field_list.push_back(new Item_return_int("Block_ops_in", 10,
- MYSQL_TYPE_LONG));
- field_list.push_back(new Item_return_int("Block_ops_out", 10,
- MYSQL_TYPE_LONG));
- }
-
- if (options & PROFILE_IPC)
- {
- field_list.push_back(new Item_return_int("Messages_sent", 10,
- MYSQL_TYPE_LONG));
- field_list.push_back(new Item_return_int("Messages_received", 10,
- MYSQL_TYPE_LONG));
- }
-
- if (options & PROFILE_PAGE_FAULTS)
- {
- field_list.push_back(new Item_return_int("Page_faults_major", 10,
- MYSQL_TYPE_LONG));
- field_list.push_back(new Item_return_int("Page_faults_minor", 10,
- MYSQL_TYPE_LONG));
- }
-
- if (options & PROFILE_SWAPS)
- {
- field_list.push_back(new Item_return_int("Swaps", 10, MYSQL_TYPE_LONG));
- }
-
- if (options & PROFILE_SOURCE)
- {
- field_list.push_back(new Item_empty_string("Source_function",
- MYSQL_ERRMSG_SIZE));
- field_list.push_back(new Item_empty_string("Source_file",
- MYSQL_ERRMSG_SIZE));
- field_list.push_back(new Item_return_int("Source_line", 10,
- MYSQL_TYPE_LONG));
- }
-
- if (thd->protocol->send_fields(&field_list,
- Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
- DBUG_RETURN(TRUE);
-
- Protocol *protocol= thd->protocol;
- SELECT_LEX *sel= &thd->lex->select_lex;
- SELECT_LEX_UNIT *unit= &thd->lex->unit;
- ha_rows idx= 0;
- unit->set_limit(sel);
- PROFILE_ENTRY *previous= &profile_start;
-
- PROFILE_ENTRY *entry;
- void *iterator;
- for (iterator= entries.new_iterator();
- iterator != NULL;
- iterator= entries.iterator_next(iterator))
- {
- entry= entries.iterator_value(iterator);
-
-#ifdef HAVE_GETRUSAGE
- struct rusage *rusage= &(entry->rusage);
-#endif
- String elapsed;
-
- if (++idx <= unit->offset_limit_cnt)
- continue;
- if (idx > unit->select_limit_cnt)
- break;
-
- protocol->prepare_for_resend();
-
- /*
- This entry, n, has a point in time, T(n), and a status phrase, S(n). The
- status phrase S(n) describes the period of time that begins at T(n). The
- previous status phrase S(n-1) describes the period of time that starts at
- T(n-1) and ends at T(n). Since we want to describe the time that a status
- phrase took T(n)-T(n-1), this line must describe the previous status.
- */
- protocol->store(previous->status, strlen(previous->status),
- system_charset_info);
- protocol->store((double)(entry->time_usecs -
- previous->time_usecs)/(1000.0*1000),
- (uint32) TIME_FLOAT_DIGITS-1, &elapsed);
-
- if (options & PROFILE_CPU)
- {
-#ifdef HAVE_GETRUSAGE
- String cpu_utime, cpu_stime;
- protocol->store((double)(RUSAGE_DIFF_USEC(rusage->ru_utime,
- previous->rusage.ru_utime))/(1000.0*1000),
- (uint32) TIME_FLOAT_DIGITS-1, &cpu_utime);
- protocol->store((double)(RUSAGE_DIFF_USEC(rusage->ru_stime,
- previous->rusage.ru_stime))/(1000.0*1000),
- (uint32) TIME_FLOAT_DIGITS-1, &cpu_stime);
-#else
- protocol->store_null();
- protocol->store_null();
-#endif
- }
-
- if (options & PROFILE_CONTEXT)
- {
-#ifdef HAVE_GETRUSAGE
- protocol->store((uint32)(rusage->ru_nvcsw - previous->rusage.ru_nvcsw));
- protocol->store((uint32)(rusage->ru_nivcsw - previous->rusage.ru_nivcsw));
-#else
- protocol->store_null();
- protocol->store_null();
-#endif
- }
-
- if (options & PROFILE_BLOCK_IO)
- {
-#ifdef HAVE_GETRUSAGE
- protocol->store((uint32)(rusage->ru_inblock - previous->rusage.ru_inblock));
- protocol->store((uint32)(rusage->ru_oublock - previous->rusage.ru_oublock));
-#else
- protocol->store_null();
- protocol->store_null();
-#endif
- }
-
- if (options & PROFILE_IPC)
- {
-#ifdef HAVE_GETRUSAGE
- protocol->store((uint32)(rusage->ru_msgsnd - previous->rusage.ru_msgsnd));
- protocol->store((uint32)(rusage->ru_msgrcv - previous->rusage.ru_msgrcv));
-#else
- protocol->store_null();
- protocol->store_null();
-#endif
- }
-
- if (options & PROFILE_PAGE_FAULTS)
- {
-#ifdef HAVE_GETRUSAGE
- protocol->store((uint32)(rusage->ru_majflt - previous->rusage.ru_majflt));
- protocol->store((uint32)(rusage->ru_minflt - previous->rusage.ru_minflt));
-#else
- protocol->store_null();
- protocol->store_null();
-#endif
- }
-
- if (options & PROFILE_SWAPS)
- {
-#ifdef HAVE_GETRUSAGE
- protocol->store((uint32)(rusage->ru_nswap - previous->rusage.ru_nswap));
-#else
- protocol->store_null();
-#endif
- }
-
- if (options & PROFILE_SOURCE)
- {
- if ((entry->function != NULL) && (entry->file != NULL))
- {
- protocol->store(entry->function, strlen(entry->function),
- system_charset_info);
- protocol->store(entry->file, strlen(entry->file), system_charset_info);
- protocol->store((uint32) entry->line);
- } else {
- protocol->store_null();
- protocol->store_null();
- protocol->store_null();
- }
- }
-
- if (protocol->write())
- DBUG_RETURN(TRUE);
-
- previous= entry;
- }
- send_eof(thd);
- DBUG_RETURN(FALSE);
-}
-
PROFILING::PROFILING()
:profile_id_counter(1), keeping(TRUE), enabled(FALSE), current(NULL), last(NULL)
{
@@ -494,9 +338,6 @@ void PROFILING::store()
DBUG_VOID_RETURN;
}
- while (history.elements > thd->variables.profiling_history_size)
- delete history.pop();
-
if (likely(((thd)->options & OPTION_PROFILING) == 0))
DBUG_VOID_RETURN;
@@ -526,6 +367,9 @@ void PROFILING::store()
if (enabled)
current= new QUERY_PROFILE(this, thd->query, thd->query_length);
+ while (history.elements > thd->variables.profiling_history_size)
+ delete history.pop();
+
DBUG_VOID_RETURN;
}
@@ -630,38 +474,11 @@ void PROFILING::set_query_source(char *query_source_arg, uint query_length_arg)
DBUG_VOID_RETURN;
}
-bool PROFILING::show(uint options, uint profiling_query_id)
-{
- DBUG_ENTER("PROFILING::show");
- QUERY_PROFILE *prof;
-
- void *iterator;
- for (iterator= history.new_iterator();
- iterator != NULL;
- iterator= history.iterator_next(iterator))
- {
- prof= history.iterator_value(iterator);
-
- if(prof->profiling_query_id == profiling_query_id)
- DBUG_RETURN(prof->show(options));
- }
-
- my_error(ER_WRONG_ARGUMENTS, MYF(0), "SHOW PROFILE");
- DBUG_RETURN(TRUE);
-}
-
-bool PROFILING::show_last(uint options)
-{
- DBUG_ENTER("PROFILING::show_last");
- if (!history.is_empty()) {
- DBUG_RETURN(last->show(options));
- }
- DBUG_RETURN(TRUE);
-}
-
/**
Fill the information schema table, "query_profile", as defined in show.cc .
+ There are two ways to get to this function: Selecting from the information
+ schema, and a SHOW command.
*/
int PROFILING::fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond)
{
@@ -696,6 +513,31 @@ int PROFILING::fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond)
{
entry= query->entries.iterator_value(entry_iterator);
+ if (thd->lex->orig_sql_command == SQLCOM_SHOW_PROFILE)
+ {
+ /*
+ We got here via a SHOW command. That means that we stored
+ information about the query we wish to show and that isn't
+ in a WHERE clause at a higher level to filter out rows we
+ wish to exclude.
+
+ Because that functionality isn't available in the server yet,
+ we must filter here, at the wrong level. Once one can con-
+ struct where and having conditions at the SQL layer, then this
+ condition should be ripped out.
+ */
+ if (thd->lex->profile_query_id == 0) /* 0 == show final query */
+ {
+ if (query != last)
+ continue;
+ }
+ else
+ {
+ if (thd->lex->profile_query_id != query->profiling_query_id)
+ continue;
+ }
+ }
+
/* Set default values for this row. */
restore_record(table, s->default_values);
@@ -715,16 +557,31 @@ int PROFILING::fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond)
*/
table->field[2]->store(previous->status, strlen(previous->status),
system_charset_info);
- table->field[3]->store((double)(entry->time_usecs -
- previous->time_usecs)/(1000*1000));
+
+ my_decimal duration;
+ double2my_decimal(E_DEC_FATAL_ERROR,
+ (entry->time_usecs-previous->time_usecs)/(1000.0*1000),
+ &duration);
+ table->field[3]->store_decimal(&duration);
#ifdef HAVE_GETRUSAGE
- table->field[4]->store((double)RUSAGE_DIFF_USEC(entry->rusage.ru_utime,
- previous->rusage.ru_utime)/(1000.0*1000));
- table->field[4]->set_notnull();
- table->field[5]->store((double)RUSAGE_DIFF_USEC(entry->rusage.ru_stime,
- previous->rusage.ru_stime)/(1000.0*1000));
+ my_decimal cpu_utime, cpu_stime;
+ double2my_decimal(E_DEC_FATAL_ERROR,
+ RUSAGE_DIFF_USEC(entry->rusage.ru_utime,
+ previous->rusage.ru_utime) /
+ (1000.0*1000),
+ &cpu_utime);
+
+ double2my_decimal(E_DEC_FATAL_ERROR,
+ RUSAGE_DIFF_USEC(entry->rusage.ru_stime,
+ previous->rusage.ru_stime) /
+ (1000.0*1000),
+ &cpu_stime);
+
+ table->field[4]->store_decimal(&cpu_utime);
+ table->field[5]->store_decimal(&cpu_stime);
+ table->field[4]->set_notnull();
table->field[5]->set_notnull();
#else
/* TODO: Add CPU-usage info for non-BSD systems */