From bc6c18f75d05f9d8ae721fb95f84de21ba83baa7 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 3 Jan 2007 17:15:10 -0500 Subject: Bug#24795: Add SHOW PROFILE MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch contributed by Jeremy Cole. CLA received Oct 2006 by Kaj Arnö Add rudimentary query profiling support. libmysqld/Makefile.am: Add profile file to source list. sql/Makefile.am: Add profiling files to source and header lists. sql/ha_archive.cc: Macro-ized other discovered instances of setting proc_info. sql/ha_myisam.cc: Macroize setting thread-state info sql/item_func.cc: Macro-ized other discovered instances of setting proc_info. sql/lex.h: Add lexer info for profiling. sql/lock.cc: Macroize setting thread-state info sql/log_event.cc: Macro-ized other discovered instances of setting proc_info. sql/mysql_priv.h: Set constants for profiling. sql/repl_failsafe.cc: Macro-ized other discovered instances of setting proc_info. sql/slave.cc: Macro-ized other discovered instances of setting proc_info. sql/sp_head.cc: Macro-ized other discovered instances of setting proc_info. sql/sql_base.cc: Macroize setting thread-state info --- Macro-ized other discovered instances of setting proc_info. sql/sql_cache.cc: Macroize setting thread-state info sql/sql_class.cc: Integrate profiling. sql/sql_class.h: Instantiate profiling object. sql/sql_delete.cc: Macroize setting thread-state info sql/sql_insert.cc: Macroize setting thread-state info --- Macro-ized other discovered instances of setting proc_info. sql/sql_lex.cc: Initialize profiling. sql/sql_lex.h: Define lex tokens and allocate space for profiling options. sql/sql_parse.cc: Integrate profiling. --- Macro-ized other discovered instances of setting proc_info. sql/sql_repl.cc: Macro-ized other discovered instances of setting proc_info. sql/sql_select.cc: Macroize setting thread-state info. Clean up some lines. sql/sql_show.cc: Macro-ized other discovered instances of setting proc_info. --- Revert bad use of macro. sql/sql_table.cc: Macroize setting thread-state info sql/sql_update.cc: Macroize setting thread-state info sql/sql_view.cc: Macro-ized other discovered instances of setting proc_info. sql/sql_yacc.yy: Add parser info for profiling. --- Fix new YACC shift/reduce conflict. (Now at 249.) mysql-test/r/profile.result: Test profiling code. --- A not-very-useful result. mysql-test/t/profile.test: Test profiling code. --- Test syntax, but not values of profiles code. sql/sql_profile.cc: Add profiling code. --- Add wishlist comment. sql/sql_profile.h: Add profiling code. --- Changed the value of the macro so that it's syntactically equivalent to a single statement. --- sql/sql_parse.cc | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'sql/sql_parse.cc') diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index fec7e5ab20d..4124db36b7f 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1059,7 +1059,7 @@ void execute_init_command(THD *thd, sys_var_str *init_command_var, Vio* save_vio; ulong save_client_capabilities; - thd->proc_info= "Execution of init_command"; + THD_PROC_INFO(thd, "Execution of init_command"); /* We need to lock init_command_var because during execution of init_command_var query @@ -1159,7 +1159,7 @@ pthread_handler_t handle_one_connection(void *arg) net->compress=1; // Use compression thd->version= refresh_version; - thd->proc_info= 0; + THD_PROC_INFO(thd, 0); thd->command= COM_SLEEP; thd->set_time(); thd->init_for_queries(); @@ -1176,7 +1176,7 @@ pthread_handler_t handle_one_connection(void *arg) sctx->host_or_ip, "init_connect command failed"); sql_print_warning("%s", net->last_error); } - thd->proc_info=0; + THD_PROC_INFO(thd, 0); thd->set_time(); thd->init_for_queries(); } @@ -1259,7 +1259,7 @@ pthread_handler_t handle_bootstrap(void *arg) if (thd->variables.max_join_size == HA_POS_ERROR) thd->options |= OPTION_BIG_SELECTS; - thd->proc_info=0; + THD_PROC_INFO(thd, 0); thd->version=refresh_version; thd->security_ctx->priv_user= thd->security_ctx->user= (char*) my_strdup("boot", MYF(MY_WME)); @@ -2106,7 +2106,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (thd->lock || thd->open_tables || thd->derived_tables || thd->prelocked_mode) { - thd->proc_info="closing tables"; + THD_PROC_INFO(thd, "closing tables"); close_thread_tables(thd); /* Free tables */ } /* @@ -2129,9 +2129,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd, log_slow_statement(thd); - thd->proc_info="cleaning up"; + THD_PROC_INFO(thd, "cleaning up"); VOID(pthread_mutex_lock(&LOCK_thread_count)); // For process list - thd->proc_info=0; + THD_PROC_INFO(thd, 0); thd->command=COM_SLEEP; thd->query=0; thd->query_length=0; @@ -2164,8 +2164,6 @@ void log_slow_statement(THD *thd) */ if (thd->enable_slow_log && !thd->user_time) { - thd->proc_info="logging slow query"; - if ((ulong) (thd->start_time - thd->time_after_lock) > thd->variables.long_query_time || (thd->server_status & @@ -2174,6 +2172,7 @@ void log_slow_statement(THD *thd) /* == SQLCOM_END unless this is a SHOW command */ thd->lex->orig_sql_command == SQLCOM_END) { + THD_PROC_INFO(thd, "logging slow query"); thd->status_var.long_query_count++; mysql_slow_log.write(thd, thd->query, thd->query_length, start_of_query); } @@ -2697,6 +2696,20 @@ mysql_execute_command(THD *thd) (1L << (uint) MYSQL_ERROR::WARN_LEVEL_ERROR)); break; } + case SQLCOM_SHOW_PROFILES: + { + thd->profiling.store(); + thd->profiling.discard(); + res= thd->profiling.show_profiles(); + break; + } + case SQLCOM_SHOW_PROFILE: + { + thd->profiling.store(); + thd->profiling.discard(); // will get re-enabled by reset() + res= thd->profiling.show_last(lex->profile_options); + break; + } case SQLCOM_SHOW_NEW_MASTER: { if (check_global_access(thd, REPL_SLAVE_ACL)) @@ -3544,7 +3557,7 @@ end_with_restore_list: if (add_item_to_list(thd, new Item_null())) goto error; - thd->proc_info="init"; + THD_PROC_INFO(thd, "init"); if ((res= open_and_lock_tables(thd, all_tables))) break; @@ -4972,7 +4985,7 @@ end_with_restore_list: send_ok(thd); break; } - thd->proc_info="query end"; + THD_PROC_INFO(thd, "query end"); /* Two binlog-related cleanups: */ /* @@ -5143,6 +5156,8 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, else save_priv= &dummy; + THD_PROC_INFO(thd, "checking permissions"); + if ((!db || !db[0]) && !thd->db && !dont_check_global_grants) { DBUG_PRINT("error",("No database")); @@ -5630,6 +5645,7 @@ void mysql_reset_thd_for_next_command(THD *thd) thd->total_warn_count=0; // Warnings for this query thd->rand_used= 0; thd->sent_row_count= thd->examined_row_count= 0; + thd->profiling.reset(); } DBUG_VOID_RETURN; } @@ -5853,7 +5869,7 @@ void mysql_parse(THD *thd, char *inBuf, uint length) query_cache_abort(&thd->net); lex->unit.cleanup(); } - thd->proc_info="freeing items"; + THD_PROC_INFO(thd, "freeing items"); thd->end_statement(); thd->cleanup_after_query(); DBUG_ASSERT(thd->change_list.is_empty()); -- cgit v1.2.1 From fdcca56513a4e9086430b5380042ab9777a3656a Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 22 Feb 2007 10:03:08 -0500 Subject: Prevent bugs by making DBUG_* expressions syntactically equivalent to a single statement. --- Bug#24795: SHOW PROFILE Profiling is only partially functional on some architectures. Where there is no getrusage() system call, presently Null values are returned where it would be required. Notably, Windows needs some love applied to make it as useful. Syntax this adds: SHOW PROFILES SHOW PROFILE [types] [FOR QUERY n] [OFFSET n] [LIMIT n] where "n" is an integer and "types" is zero or many (comma-separated) of "CPU" "MEMORY" (not presently supported) "BLOCK IO" "CONTEXT SWITCHES" "PAGE FAULTS" "IPC" "SWAPS" "SOURCE" "ALL" It also adds a session variable (boolean) "profiling", set to "no" by default, and (integer) profiling_history_size, set to 15 by default. This patch abstracts setting THDs' "proc_info" behind a macro that can be used as a hook into the profiling code when profiling support is compiled in. All future code in this line should use that mechanism for setting thd->proc_info. --- Tests are now set to omit the statistics. --- Adds an Information_schema table, "profiling" for access to "show profile" data. --- Merge zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community-3--bug24795 into zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-community --- Fix merge problems. --- Fixed one bug in the query_source being NULL. Updated test results. --- Include more thorough profiling tests. Improve support for prepared statements. Use session-specific query IDs, starting at zero. --- Selecting from I_S.profiling is no longer quashed in profiling, as requested by Giuseppe. Limit the size of captured query text. No longer log queries that are zero length. BitKeeper/deleted/.del-profile.result: Rename: mysql-test/r/profile.result -> BitKeeper/deleted/.del-profile.result BitKeeper/deleted/.del-profile.test: Rename: mysql-test/t/profile.test -> BitKeeper/deleted/.del-profile.test BitKeeper/deleted/.del-sql_profile.cc: Rename: sql/sql_profile.cc -> BitKeeper/deleted/.del-sql_profile.cc BitKeeper/deleted/.del-sql_profile.h: Rename: sql/sql_profile.h -> BitKeeper/deleted/.del-sql_profile.h configure.in: Add a configure-time option to enable/disable query profiling. The default is enabled. include/my_dbug.h: DBUG_* statements should be syntactically equivalent to a single statement. myisam/mi_open.c: DBUG_* statements should be syntactically equivalent to a single statement. mysql-test/r/information_schema.result: Updated (re-recorded) tests that I missed somehow. I verified these for correctness. mysql-test/r/information_schema_db.result: Updated test results I missed. mysql-test/r/mysqlshow.result: Fix merge problems. ndb/src/ndbapi/DictCache.cpp: DBUG_* statements should be syntactically equivalent to a single statement. sql/ha_archive.cc: Abstract setting thread-info into a function or macro. --- Manual merge, undoing first patch. sql/ha_berkeley.cc: Include patch backported to 5.0-global. THD::options is a ulonglong, not ulong. sql/ha_myisam.cc: Abstract setting thread-info into a function or macro. --- Manual merge, undoing first patch. sql/ha_myisammrg.cc: DBUG_* statements should be syntactically equivalent to a single statement. sql/ha_ndbcluster.cc: DBUG_* statements should be syntactically equivalent to a single statement. sql/item_cmpfunc.cc: DBUG_* statements should be syntactically equivalent to a single statement. sql/item_func.cc: Abstract setting thread-info into a function or macro. --- Manual merge, undoing first patch. sql/lock.cc: Abstract setting thread-info into a function or macro. --- Manual merge, undoing first patch. sql/log_event.cc: Abstract setting thread-info into a function or macro. --- Manual merge, undoing first patch. sql/mysql_priv.h: Use 64-bit constants for the 64-bit bit field. Add a new option bit for whether profiling is active or not. sql/mysqld.cc: Add semicolon to DBUG statement. Add a new system variable and set it. --- Set the minimum, which is zero and not 50. sql/repl_failsafe.cc: Abstract setting thread-info into a function or macro. --- Manual merge, undoing first patch. sql/set_var.cc: Make a new system global variable and session variable, to determine behavior of profiling. --- Include patch backported to 5.0-global. THD::options is a ulonglong, not ulong. sql/set_var.h: The THD::options bit field is ulonglong, not ulong. sql/slave.cc: Abstract setting thread-info into a function or macro. --- Manual merge, undoing first patch. --- Include patch backported to 5.0-global. THD::options is a ulonglong, not ulong. sql/sp_head.cc: Abstract setting thread-info into a function or macro. --- Manual merge, undoing first patch. sql/sql_base.cc: Abstract setting thread-info into a function or macro. --- Manual merge, undoing first patch. --- Include patch backported to 5.0-global. THD::options is a ulonglong, not ulong. sql/sql_cache.cc: DBUG_* statements should be syntactically equivalent to a single statement. --- Fix merge problems. sql/sql_class.cc: Insert a pointer to the current thread in the profiling code. --- Manual merge, undoing first patch. --- Fix merge problems. sql/sql_class.h: Create a new system variable, profiling_history_size, and add a member to THD to hold profiling information about this thread's execution. --- Manual merge, undoing first patch. sql/sql_delete.cc: Abstract setting thread-info into a function or macro. --- Manual merge, undoing first patch. --- Include patch backported to 5.0-global. THD::options is a ulonglong, not ulong. sql/sql_insert.cc: Abstract setting thread-info into a function or macro. --- Manual merge, undoing first patch. --- Fix merge problems. sql/sql_lex.cc: Initialize profiling options to empty. --- Manual merge, undoing first patch. sql/sql_lex.h: Add info to the lexer object so that we can hold data that comes from parsing statements. Reuse memory addresses of uints that can't occur in the same state- ment. This is dangerous because it involves knowledge of what symbols are never used together, which is information stored obliquely in another file. --- Manual merge, undoing first patch. sql/sql_parse.cc: Add hooks to the parser to jump to profiling code. If profiling is not present, then return an error message upon being used. --- Manual merge, undoing first patch. --- Fix merge problems. --- Include patch backported to 5.0-global. THD::options is a ulonglong, not ulong. sql/sql_prepare.cc: From prepared statement execution, set the query source in the profiler, as we can't get it from thd . --- Make it less expensive to limit the size of the queries. sql/sql_repl.cc: Abstract setting thread-info into a function or macro. --- Manual merge, undoing first patch. sql/sql_select.cc: Abstract setting thread-info into a function or macro. --- Manual merge, undoing first patch. --- Fix merge problems. sql/sql_show.cc: Abstract setting thread-info into a function or macro. Also, remove "static" qualification on schema_table_store_record() so that external functions may use it. --- Manual merge, undoing first patch. sql/sql_table.cc: Abstract setting thread-info into a function or macro. --- Manual merge, undoing first patch. sql/sql_update.cc: Abstract setting thread-info into a function or macro. --- Manual merge, undoing first patch. sql/sql_view.cc: Abstract setting thread-info into a function or macro. --- Manual merge, undoing first patch. sql/sql_yacc.yy: Add new lexer symbols and insert new grammatical rules necessary to retreive profiling information. --- Manual merge, undoing first patch. --- Fix merge problems. sql/table.h: Add enum item for query profiling. BitKeeper/deleted/.del-profiling-master.opt: New BitKeeper file ``mysql-test/t/profiling-master.opt'' mysql-test/r/profiling.result: New BitKeeper file ``mysql-test/r/profiling.result'' --- Include more verbose that describes the queries so far. Include Giuseppe's tests. --- Selecting from I_S.profiling is no longer quashed in profiling, as requested by Giuseppe. mysql-test/t/profiling.test: New BitKeeper file ``mysql-test/t/profiling.test'' --- Include more verbose that describes the queries so far. Include Giuseppe's tests. --- Selecting from I_S.profiling is no longer quashed in profiling, as requested by Giuseppe. sql/sql_profile.cc: New BitKeeper file ``sql/sql_profile.cc'' --- If query_source is NULL, as can sometimes happen, then don't try to copy that memory. --- Make each new session use its own numbering of query_ids, and not show the global-pool numbers to the user. Provide a way for prepared statements to set the query_source. --- Selecting from I_S.profiling is no longer quashed in profiling, as requested by Giuseppe. Limit the size of captured query text. No longer log queries that are zero length. sql/sql_profile.h: New BitKeeper file ``sql/sql_profile.h'' --- Make each new session use its own numbering of query_ids, and not show the global-pool numbers to the user. Provide a way for prepared statements to set the query_source. --- Make it less expensive to limit the size of the queries. --- sql/sql_parse.cc | 71 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 24 deletions(-) (limited to 'sql/sql_parse.cc') diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 779db99a4ff..449d57c2b2d 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -140,14 +140,14 @@ static bool end_active_trans(THD *thd) if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN | OPTION_TABLE_LOCK)) { - DBUG_PRINT("info",("options: 0x%lx", (ulong) thd->options)); + DBUG_PRINT("info",("options: 0x%llx", thd->options)); /* Safety if one did "drop table" on locked tables */ if (!thd->locked_tables) thd->options&= ~OPTION_TABLE_LOCK; thd->server_status&= ~SERVER_STATUS_IN_TRANS; if (ha_commit(thd)) error=1; - thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); + thd->options&= ~(OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); } DBUG_RETURN(error); } @@ -171,7 +171,7 @@ static bool begin_trans(THD *thd) else { LEX *lex= thd->lex; - thd->options= ((thd->options & (ulong) ~(OPTION_STATUS_NO_TRANS_UPDATE)) | + thd->options= ((thd->options & ~(OPTION_STATUS_NO_TRANS_UPDATE)) | OPTION_BEGIN); thd->server_status|= SERVER_STATUS_IN_TRANS; if (lex->start_transaction_opt & MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT) @@ -1058,7 +1058,7 @@ void execute_init_command(THD *thd, sys_var_str *init_command_var, Vio* save_vio; ulong save_client_capabilities; - THD_PROC_INFO(thd, "Execution of init_command"); + thd_proc_info(thd, "Execution of init_command"); /* We need to lock init_command_var because during execution of init_command_var query @@ -1158,7 +1158,7 @@ pthread_handler_t handle_one_connection(void *arg) net->compress=1; // Use compression thd->version= refresh_version; - THD_PROC_INFO(thd, 0); + thd_proc_info(thd, 0); thd->command= COM_SLEEP; thd->set_time(); thd->init_for_queries(); @@ -1175,7 +1175,7 @@ pthread_handler_t handle_one_connection(void *arg) sctx->host_or_ip, "init_connect command failed"); sql_print_warning("%s", net->last_error); } - THD_PROC_INFO(thd, 0); + thd_proc_info(thd, 0); thd->set_time(); thd->init_for_queries(); } @@ -1258,7 +1258,7 @@ pthread_handler_t handle_bootstrap(void *arg) if (thd->variables.max_join_size == HA_POS_ERROR) thd->options |= OPTION_BIG_SELECTS; - THD_PROC_INFO(thd, 0); + thd_proc_info(thd, 0); thd->version=refresh_version; thd->security_ctx->priv_user= thd->security_ctx->user= (char*) my_strdup("boot", MYF(MY_WME)); @@ -1447,7 +1447,7 @@ int end_trans(THD *thd, enum enum_mysql_completiontype completion) */ thd->server_status&= ~SERVER_STATUS_IN_TRANS; res= ha_commit(thd); - thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); + thd->options&= ~(OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); break; case COMMIT_RELEASE: do_release= 1; /* fall through */ @@ -1464,7 +1464,7 @@ int end_trans(THD *thd, enum enum_mysql_completiontype completion) thd->server_status&= ~SERVER_STATUS_IN_TRANS; if (ha_rollback(thd)) res= -1; - thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); + thd->options&= ~(OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); if (!res && (completion == ROLLBACK_AND_CHAIN)) res= begin_trans(thd); break; @@ -2105,7 +2105,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, if (thd->lock || thd->open_tables || thd->derived_tables || thd->prelocked_mode) { - THD_PROC_INFO(thd, "closing tables"); + thd_proc_info(thd, "closing tables"); close_thread_tables(thd); /* Free tables */ } /* @@ -2128,9 +2128,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd, log_slow_statement(thd); - THD_PROC_INFO(thd, "cleaning up"); + thd_proc_info(thd, "cleaning up"); VOID(pthread_mutex_lock(&LOCK_thread_count)); // For process list - THD_PROC_INFO(thd, 0); + thd_proc_info(thd, 0); thd->command=COM_SLEEP; thd->query=0; thd->query_length=0; @@ -2163,6 +2163,8 @@ void log_slow_statement(THD *thd) */ if (thd->enable_slow_log && !thd->user_time) { + thd_proc_info(thd, "logging slow query"); + if ((ulong) (thd->start_time - thd->time_after_lock) > thd->variables.long_query_time || (thd->server_status & @@ -2171,7 +2173,7 @@ void log_slow_statement(THD *thd) /* == SQLCOM_END unless this is a SHOW command */ thd->lex->orig_sql_command == SQLCOM_END) { - THD_PROC_INFO(thd, "logging slow query"); + thd_proc_info(thd, "logging slow query"); thd->status_var.long_query_count++; mysql_slow_log.write(thd, thd->query, thd->query_length, start_of_query); } @@ -2698,16 +2700,33 @@ mysql_execute_command(THD *thd) } case SQLCOM_SHOW_PROFILES: { +#ifdef ENABLED_PROFILING thd->profiling.store(); thd->profiling.discard(); res= thd->profiling.show_profiles(); + if (res) + goto error; +#else + my_error(ER_FEATURE_DISABLED, MYF(0), "query profiling", "enable-profiling"); + goto error; +#endif break; } case SQLCOM_SHOW_PROFILE: { +#ifdef ENABLED_PROFILING thd->profiling.store(); thd->profiling.discard(); // will get re-enabled by reset() - res= thd->profiling.show_last(lex->profile_options); + if (lex->profile_query_id != 0) + res= thd->profiling.show(lex->profile_options, lex->profile_query_id); + else + res= thd->profiling.show_last(lex->profile_options); + if (res) + goto error; +#else + my_error(ER_FEATURE_DISABLED, MYF(0), "query profiling", "enable-profiling"); + goto error; +#endif break; } case SQLCOM_SHOW_NEW_MASTER: @@ -3557,7 +3576,7 @@ end_with_restore_list: if (add_item_to_list(thd, new Item_null())) goto error; - THD_PROC_INFO(thd, "init"); + thd_proc_info(thd, "init"); if ((res= open_and_lock_tables(thd, all_tables))) break; @@ -3721,7 +3740,7 @@ end_with_restore_list: if (thd->options & OPTION_TABLE_LOCK) { end_active_trans(thd); - thd->options&= ~(ulong) (OPTION_TABLE_LOCK); + thd->options&= ~(OPTION_TABLE_LOCK); } if (thd->global_read_lock) unlock_global_read_lock(thd); @@ -3747,7 +3766,7 @@ end_with_restore_list: send_ok(thd); } else - thd->options&= ~(ulong) (OPTION_TABLE_LOCK); + thd->options&= ~(OPTION_TABLE_LOCK); thd->in_lock_tables=0; break; case SQLCOM_CREATE_DB: @@ -4847,7 +4866,7 @@ create_sp_error: thd->transaction.xid_state.xa_state=XA_ACTIVE; thd->transaction.xid_state.xid.set(thd->lex->xid); xid_cache_insert(&thd->transaction.xid_state); - thd->options= ((thd->options & (ulong) ~(OPTION_STATUS_NO_TRANS_UPDATE)) | + thd->options= ((thd->options & ~(OPTION_STATUS_NO_TRANS_UPDATE)) | OPTION_BEGIN); thd->server_status|= SERVER_STATUS_IN_TRANS; send_ok(thd); @@ -4941,7 +4960,7 @@ create_sp_error: xa_state_names[thd->transaction.xid_state.xa_state]); break; } - thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); + thd->options&= ~(OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); thd->server_status&= ~SERVER_STATUS_IN_TRANS; xid_cache_delete(&thd->transaction.xid_state); thd->transaction.xid_state.xa_state=XA_NOTR; @@ -4971,7 +4990,7 @@ create_sp_error: my_error(ER_XAER_RMERR, MYF(0)); else send_ok(thd); - thd->options&= ~(ulong) (OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); + thd->options&= ~(OPTION_BEGIN | OPTION_STATUS_NO_TRANS_UPDATE); thd->server_status&= ~SERVER_STATUS_IN_TRANS; xid_cache_delete(&thd->transaction.xid_state); thd->transaction.xid_state.xa_state=XA_NOTR; @@ -4986,7 +5005,7 @@ create_sp_error: send_ok(thd); break; } - THD_PROC_INFO(thd, "query end"); + thd_proc_info(thd, "query end"); /* Two binlog-related cleanups: */ /* @@ -5157,8 +5176,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, else save_priv= &dummy; - THD_PROC_INFO(thd, "checking permissions"); - + thd_proc_info(thd, "checking permissions"); if ((!db || !db[0]) && !thd->db && !dont_check_global_grants) { DBUG_PRINT("error",("No database")); @@ -5605,6 +5623,9 @@ mysql_init_query(THD *thd, uchar *buf, uint length) DBUG_ENTER("mysql_init_query"); lex_start(thd, buf, length); mysql_reset_thd_for_next_command(thd); +#ifdef ENABLED_PROFILING + thd->profiling.reset(); +#endif DBUG_VOID_RETURN; } @@ -5646,7 +5667,9 @@ void mysql_reset_thd_for_next_command(THD *thd) thd->total_warn_count=0; // Warnings for this query thd->rand_used= 0; thd->sent_row_count= thd->examined_row_count= 0; +#ifdef ENABLED_PROFILING thd->profiling.reset(); +#endif } DBUG_VOID_RETURN; } @@ -5870,7 +5893,7 @@ void mysql_parse(THD *thd, char *inBuf, uint length) query_cache_abort(&thd->net); lex->unit.cleanup(); } - THD_PROC_INFO(thd, "freeing items"); + thd_proc_info(thd, "freeing items"); thd->end_statement(); thd->cleanup_after_query(); DBUG_ASSERT(thd->change_list.is_empty()); -- cgit v1.2.1 From 776891454e53bcfc21e9379ec17ddcdbcdf4c650 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 26 Feb 2007 13:11:36 -0500 Subject: Some changes suggested Serg, from message <20070223210659.GA24202@janus.mylan> configure.in: Use smarter autoconf help macro. sql/set_var.cc: Make a local variable static. sql/sql_lex.cc: Don't include CPP condition where it saves little time and decreases legibility. sql/sql_parse.cc: Use the name of the query in the error, instead of describing the feature. sql/sql_profile.cc: Update copyright. Make I_S schema table columns uppercase. sql/sql_profile.h: Update copyright. sql/sql_select.cc: Chagne tab indentation to spaces. --- sql/sql_parse.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sql/sql_parse.cc') diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 449d57c2b2d..370fa4a19c5 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2707,7 +2707,7 @@ mysql_execute_command(THD *thd) if (res) goto error; #else - my_error(ER_FEATURE_DISABLED, MYF(0), "query profiling", "enable-profiling"); + my_error(ER_FEATURE_DISABLED, MYF(0), "SHOW PROFILES", "enable-profiling"); goto error; #endif break; @@ -2724,7 +2724,7 @@ mysql_execute_command(THD *thd) if (res) goto error; #else - my_error(ER_FEATURE_DISABLED, MYF(0), "query profiling", "enable-profiling"); + my_error(ER_FEATURE_DISABLED, MYF(0), "SHOW PROFILE", "enable-profiling"); goto error; #endif break; -- cgit v1.2.1 From 6358aac386640b378c78904c8306f7cbbd219fdd Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 2 Jul 2007 07:27:39 -0400 Subject: Unify profiling SHOW code and INFORMATION_SCHEMA code for profiling. Also, Bug#26938: profiling client hang if used before enabled In the SHOW command, not sending header data because we had no rows to send was a protocol violation. Porting the SHOW PROFILE command to use the Information Schema table avoids that problem. mysql-test/r/profiling.result: Add headers of pre-profile SHOW test. mysql-test/t/profiling.test: Verify that the protocol isn't violated if we ask for profiling info before profiling has recorded anything. sql/sql_parse.cc: Remove SQLCOM_SHOW_PROFILE and add a I_S schema table entry. sql/sql_profile.cc: Add SHOW column-names and a new function that takes profile options set in the parser and packs a list of selected fields from the I_S table implementation. sql/sql_profile.h: Remove unused functions and add a new function. sql/sql_show.cc: Add a pointer to the function that selects fields from I_S table for SHOW command. sql/sql_yacc.yy: Prepare an I_S table for SHOW PROFILE. sql/table.h: Rename to match the intention. --- sql/sql_parse.cc | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'sql/sql_parse.cc') diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 34702dce957..8c1d627c5f5 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2315,6 +2315,15 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, break; } #endif + case SCH_PROFILES: + /* + Mark this current profiling record to be discarded. We don't + wish to have SHOW commands show up in profiling. + */ +#ifdef ENABLED_PROFILING + thd->profiling.discard(); +#endif + break; case SCH_OPEN_TABLES: case SCH_VARIABLES: case SCH_STATUS: @@ -2755,23 +2764,6 @@ mysql_execute_command(THD *thd) #else my_error(ER_FEATURE_DISABLED, MYF(0), "SHOW PROFILES", "enable-profiling"); goto error; -#endif - break; - } - case SQLCOM_SHOW_PROFILE: - { -#ifdef ENABLED_PROFILING - thd->profiling.store(); - thd->profiling.discard(); // will get re-enabled by reset() - if (lex->profile_query_id != 0) - res= thd->profiling.show(lex->profile_options, lex->profile_query_id); - else - res= thd->profiling.show_last(lex->profile_options); - if (res) - goto error; -#else - my_error(ER_FEATURE_DISABLED, MYF(0), "SHOW PROFILE", "enable-profiling"); - goto error; #endif break; } -- cgit v1.2.1 From 214fde4473563a21c585382dbb44b4112af8d096 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 3 Jul 2007 11:25:32 -0400 Subject: Avoid a warning on windows about a missing case enum. sql/sql_parse.cc: Avoid a warning on windows. --- sql/sql_parse.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/sql_parse.cc') diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 9b0fce13678..17ae8fee0ea 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -5502,6 +5502,7 @@ static bool check_show_access(THD *thd, TABLE_LIST *table) case SCH_COLUMN_PRIVILEGES: case SCH_TABLE_CONSTRAINTS: case SCH_KEY_COLUMN_USAGE: + case SCH_PROFILES: break; } -- cgit v1.2.1 From 8b71f3da34d7d7ad9c9f27cc1994f27acb703d9b Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 14 Nov 2007 15:11:58 -0500 Subject: Push history-limiting code until after the code that adds new history entries. Lazy deletion isn't smart or useful here. Backport from 5.1 . include/my_sys.h: Prepare for rename in 5.1. mysql-test/r/profiling.result: Backport tests from 5.1. mysql-test/t/profiling.test: Backport tests from 5.1. sql/mysql_priv.h: Backport changes from 5.1 . sql/sp_head.cc: Backport changes from 5.1 . sql/sql_class.cc: Backport changes from 5.1 . sql/sql_parse.cc: Backport changes from 5.1 . sql/sql_profile.cc: Push history-limiting code until after the code that adds new history entries. Lazy deletion isn't smart or useful here. Correct for 5.0 member existance and execution. sql/sql_profile.h: Backport changes from 5.1 . sql/sql_show.cc: Backport changes from 5.1 . --- sql/sql_parse.cc | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'sql/sql_parse.cc') diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 7e105689d22..e3166c07cbd 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1313,6 +1313,10 @@ pthread_handler_t handle_bootstrap(void *arg) thd->db_length+1+QUERY_CACHE_FLAGS_SIZE); thd->query[length] = '\0'; DBUG_PRINT("query",("%-.4096s",thd->query)); +#if defined(ENABLED_PROFILING) + thd->profiling.set_query_source(thd->query, length); +#endif + /* We don't need to obtain LOCK_thread_count here because in bootstrap mode we have only one thread. @@ -1522,6 +1526,7 @@ int end_trans(THD *thd, enum enum_mysql_completiontype completion) bool do_command(THD *thd) { + bool return_value; char *packet= 0; ulong packet_length; NET *net= &thd->net; @@ -1545,7 +1550,12 @@ bool do_command(THD *thd) thd->clear_error(); // Clear error message net_new_transaction(net); - if ((packet_length=my_net_read(net)) == packet_error) + + packet_length= my_net_read(net); +#if defined(ENABLED_PROFILING) + thd->profiling.start_new_query(); +#endif + if (packet_length == packet_error) { DBUG_PRINT("info",("Got error %d reading command from socket %s", net->error, @@ -1554,11 +1564,13 @@ bool do_command(THD *thd) if (net->error != 3) { statistic_increment(aborted_threads,&LOCK_status); - DBUG_RETURN(TRUE); // We have to close it. + return_value= TRUE; // We have to close it. + goto out; } net_send_error(thd, net->last_errno, NullS); net->error= 0; - DBUG_RETURN(FALSE); + return_value= FALSE; + goto out; } else { @@ -1583,7 +1595,13 @@ bool do_command(THD *thd) command == packet[0] == COM_SLEEP). In dispatch_command packet[packet_length] points beyond the end of packet. */ - DBUG_RETURN(dispatch_command(command,thd, packet+1, (uint) packet_length)); + return_value= dispatch_command(command, thd, packet+1, (uint) (packet_length)); + +out: +#if defined(ENABLED_PROFILING) + thd->profiling.finish_current_query(); +#endif + DBUG_RETURN(return_value); } #endif /* EMBEDDED_LIBRARY */ @@ -1805,6 +1823,9 @@ bool dispatch_command(enum enum_server_command command, THD *thd, mysql_log.write(thd,command, format, thd->query_length, thd->query); DBUG_PRINT("query",("%-.4096s",thd->query)); +#if defined(ENABLED_PROFILING) + thd->profiling.set_query_source(thd->query, thd->query_length); +#endif if (!(specialflag & SPECIAL_NO_PRIOR)) my_pthread_setprio(pthread_self(),QUERY_PRIOR); @@ -1831,6 +1852,13 @@ bool dispatch_command(enum enum_server_command command, THD *thd, next_packet++; length--; } + +#if defined(ENABLED_PROFILING) + thd->profiling.finish_current_query(); + thd->profiling.start_new_query("continuing"); + thd->profiling.set_query_source(next_packet, length); +#endif + VOID(pthread_mutex_lock(&LOCK_thread_count)); thd->query_length= length; thd->query= next_packet; @@ -2325,7 +2353,7 @@ int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident, wish to have SHOW commands show up in profiling. */ #ifdef ENABLED_PROFILING - thd->profiling.discard(); + thd->profiling.discard_current_query(); #endif break; case SCH_OPEN_TABLES: @@ -2762,8 +2790,7 @@ mysql_execute_command(THD *thd) case SQLCOM_SHOW_PROFILES: { #ifdef ENABLED_PROFILING - thd->profiling.store(); - thd->profiling.discard(); + thd->profiling.discard_current_query(); res= thd->profiling.show_profiles(); if (res) goto error; @@ -5887,9 +5914,6 @@ void mysql_reset_thd_for_next_command(THD *thd) thd->total_warn_count=0; // Warnings for this query thd->rand_used= 0; thd->sent_row_count= thd->examined_row_count= 0; -#ifdef ENABLED_PROFILING - thd->profiling.reset(); -#endif } DBUG_VOID_RETURN; } -- cgit v1.2.1