perfschema statement instrumentation related changes

This commit is contained in:
Sergei Golubchik 2020-02-14 17:05:31 +01:00
parent 70e7b5095d
commit d4605bc90f
10 changed files with 79 additions and 25 deletions

View file

@ -41,6 +41,18 @@
@{
*/
#ifdef HAVE_PSI_INTERFACE
void init_scheduler_psi_keys()
{
const char *category= "scheduler";
PSI_server->register_statement(category, & Event_queue_element_for_exec::psi_info, 1);
}
PSI_statement_info Event_queue_element_for_exec::psi_info=
{ 0, "event", 0};
#endif
/*************************************************************************/
/**
@ -1428,10 +1440,20 @@ Event_job_data::execute(THD *thd, bool drop)
{
Parser_state parser_state;
sql_digest_state *parent_digest= thd->m_digest;
PSI_statement_locker *parent_locker= thd->m_statement_psi;
bool res;
if (parser_state.init(thd, thd->query(), thd->query_length()))
goto end;
if (parse_sql(thd, & parser_state, creation_ctx))
thd->m_digest= NULL;
thd->m_statement_psi= NULL;
res= parse_sql(thd, & parser_state, creation_ctx);
thd->m_digest= parent_digest;
thd->m_statement_psi= parent_locker;
if (res)
{
sql_print_error("Event Scheduler: %serror during compilation of %s.%s",
thd->is_fatal_error ? "fatal " : "", dbname.str, name.str);

View file

@ -30,6 +30,8 @@ class THD;
class Time_zone;
struct TABLE;
void init_scheduler_psi_keys(void);
class Event_queue_element_for_exec
{
public:
@ -48,6 +50,15 @@ private:
/* Prevent use of these */
Event_queue_element_for_exec(const Event_queue_element_for_exec &);
void operator=(Event_queue_element_for_exec &);
#ifdef HAVE_PSI_INTERFACE
public:
PSI_statement_info* get_psi_info()
{
return & psi_info;
}
static PSI_statement_info psi_info;
#endif
};

View file

@ -291,6 +291,15 @@ Event_worker_thread::run(THD *thd, Event_queue_element_for_exec *event)
DBUG_ASSERT(thd->m_digest == NULL);
DBUG_ASSERT(thd->m_statement_psi == NULL);
#ifdef HAVE_PSI_STATEMENT_INTERFACE
PSI_statement_locker_state state;
thd->m_statement_psi= MYSQL_START_STATEMENT(& state,
event->get_psi_info()->m_key,
event->dbname.str,
event->dbname.length,
thd->charset(), NULL);
#endif
thd->thread_stack= &my_stack; // remember where our stack is
res= post_init_event_thread(thd);
@ -319,7 +328,10 @@ Event_worker_thread::run(THD *thd, Event_queue_element_for_exec *event)
job_data.definer.str,
job_data.dbname.str, job_data.name.str);
end:
DBUG_ASSERT(thd->m_statement_psi == NULL);
#ifdef HAVE_PSI_STATEMENT_INTERFACE
MYSQL_END_STATEMENT(thd->m_statement_psi, thd->get_stmt_da());
thd->m_statement_psi= NULL;
#endif
DBUG_ASSERT(thd->m_digest == NULL);
DBUG_PRINT("info", ("Done with Event %s.%s", event->dbname.str,
event->name.str));

View file

@ -1065,6 +1065,8 @@ static void init_events_psi_keys(void)
count= array_elements(all_events_memory);
mysql_memory_register(category, all_events_memory, count);
init_scheduler_psi_keys();
}
#endif /* HAVE_PSI_INTERFACE */

View file

@ -1833,8 +1833,8 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi,
thd->m_statement_psi= MYSQL_START_STATEMENT(&thd->m_statement_state,
stmt_info_rpl.m_key,
thd->db.str, thd->db.length,
thd->charset());
THD_STAGE_INFO(thd, stage_init);
thd->charset(), NULL);
THD_STAGE_INFO(thd, stage_starting);
MYSQL_SET_STATEMENT_TEXT(thd->m_statement_psi, thd->query(), thd->query_length());
if (thd->m_digest != NULL)
thd->m_digest->reset(thd->m_token_array, max_digest_length);

View file

@ -1166,9 +1166,9 @@ void net_after_header_psi(struct st_net *net, void *user_data,
thd->m_statement_psi= MYSQL_START_STATEMENT(&thd->m_statement_state,
stmt_info_new_packet.m_key,
thd->get_db(), thd->db.length,
thd->charset());
thd->charset(), NULL);
THD_STAGE_INFO(thd, stage_init);
THD_STAGE_INFO(thd, stage_starting);
}
/*
@ -9158,25 +9158,25 @@ PSI_stage_info stage_after_create= { 0, "After create", 0};
PSI_stage_info stage_after_opening_tables= { 0, "After opening tables", 0};
PSI_stage_info stage_after_table_lock= { 0, "After table lock", 0};
PSI_stage_info stage_allocating_local_table= { 0, "Allocating local table", 0};
PSI_stage_info stage_alter_inplace_prepare= { 0, "Preparing for alter table", 0};
PSI_stage_info stage_alter_inplace= { 0, "Altering table", 0};
PSI_stage_info stage_alter_inplace_prepare= { 0, "preparing for alter table", 0};
PSI_stage_info stage_alter_inplace= { 0, "altering table", 0};
PSI_stage_info stage_alter_inplace_commit= { 0, "Committing alter table to storage engine", 0};
PSI_stage_info stage_apply_event= { 0, "Apply log event", 0};
PSI_stage_info stage_changing_master= { 0, "Changing master", 0};
PSI_stage_info stage_checking_master_version= { 0, "Checking master version", 0};
PSI_stage_info stage_checking_permissions= { 0, "Checking permissions", 0};
PSI_stage_info stage_checking_privileges_on_cached_query= { 0, "Checking privileges on cached query", 0};
PSI_stage_info stage_checking_permissions= { 0, "checking permissions", 0};
PSI_stage_info stage_checking_privileges_on_cached_query= { 0, "checking privileges on cached query", 0};
PSI_stage_info stage_checking_query_cache_for_query= { 0, "Checking query cache for query", 0};
PSI_stage_info stage_cleaning_up= { 0, "Reset for next command", 0};
PSI_stage_info stage_closing_tables= { 0, "Closing tables", 0};
PSI_stage_info stage_closing_tables= { 0, "closing tables", 0};
PSI_stage_info stage_connecting_to_master= { 0, "Connecting to master", 0};
PSI_stage_info stage_converting_heap_to_myisam= { 0, "Converting HEAP to " TMP_ENGINE_NAME, 0};
PSI_stage_info stage_copying_to_group_table= { 0, "Copying to group table", 0};
PSI_stage_info stage_copying_to_tmp_table= { 0, "Copying to tmp table", 0};
PSI_stage_info stage_copy_to_tmp_table= { 0, "Copy to tmp table", 0};
PSI_stage_info stage_copy_to_tmp_table= { 0, "copy to tmp table", PSI_FLAG_STAGE_PROGRESS};
PSI_stage_info stage_creating_delayed_handler= { 0, "Creating delayed handler", 0};
PSI_stage_info stage_creating_sort_index= { 0, "Creating sort index", 0};
PSI_stage_info stage_creating_table= { 0, "Creating table", 0};
PSI_stage_info stage_creating_table= { 0, "creating table", 0};
PSI_stage_info stage_creating_tmp_table= { 0, "Creating tmp table", 0};
PSI_stage_info stage_deleting_from_main_table= { 0, "Deleting from main table", 0};
PSI_stage_info stage_deleting_from_reference_tables= { 0, "Deleting from reference tables", 0};
@ -9194,8 +9194,8 @@ PSI_stage_info stage_freeing_items= { 0, "Freeing items", 0};
PSI_stage_info stage_fulltext_initialization= { 0, "Fulltext initialization", 0};
PSI_stage_info stage_got_handler_lock= { 0, "Got handler lock", 0};
PSI_stage_info stage_got_old_table= { 0, "Got old table", 0};
PSI_stage_info stage_init= { 0, "Init", 0};
PSI_stage_info stage_init_update= { 0, "Init for update", 0};
PSI_stage_info stage_init= { 0, "init", 0};
PSI_stage_info stage_init_update= { 0, "init for update", 0};
PSI_stage_info stage_insert= { 0, "Insert", 0};
PSI_stage_info stage_invalidating_query_cache_entries_table= { 0, "Invalidating query cache entries (table)", 0};
PSI_stage_info stage_invalidating_query_cache_entries_table_list= { 0, "Invalidating query cache entries (table list)", 0};
@ -9214,7 +9214,7 @@ PSI_stage_info stage_starting_cleanup= { 0, "Starting cleanup", 0};
PSI_stage_info stage_rollback= { 0, "Rollback", 0};
PSI_stage_info stage_rollback_implicit= { 0, "Rollback_implicit", 0};
PSI_stage_info stage_commit= { 0, "Commit", 0};
PSI_stage_info stage_commit_implicit= { 0, "Commit_implicit", 0};
PSI_stage_info stage_commit_implicit= { 0, "Commit implicit", 0};
PSI_stage_info stage_queueing_master_event_to_the_relay_log= { 0, "Queueing master event to the relay log", 0};
PSI_stage_info stage_reading_event_from_the_relay_log= { 0, "Reading event from the relay log", 0};
PSI_stage_info stage_recreating_table= { 0, "Recreating table", 0};
@ -9229,7 +9229,7 @@ PSI_stage_info stage_searching_rows_for_update= { 0, "Searching rows for update"
PSI_stage_info stage_sending_binlog_event_to_slave= { 0, "Sending binlog event to slave", 0};
PSI_stage_info stage_sending_cached_result_to_client= { 0, "Sending cached result to client", 0};
PSI_stage_info stage_sending_data= { 0, "Sending data", 0};
PSI_stage_info stage_setup= { 0, "Setup", 0};
PSI_stage_info stage_setup= { 0, "setup", 0};
PSI_stage_info stage_show_explain= { 0, "Show explain", 0};
PSI_stage_info stage_slave_has_read_all_relay_log= { 0, "Slave has read all relay log; waiting for more updates", 0};
PSI_stage_info stage_sorting= { 0, "Sorting", 0};
@ -9242,7 +9242,7 @@ PSI_stage_info stage_storing_result_in_query_cache= { 0, "Storing result in quer
PSI_stage_info stage_storing_row_into_queue= { 0, "Storing row into queue", 0};
PSI_stage_info stage_system_lock= { 0, "System lock", 0};
PSI_stage_info stage_unlocking_tables= { 0, "Unlocking tables", 0};
PSI_stage_info stage_table_lock= { 0, "Table lock", 0};
PSI_stage_info stage_table_lock= { 0, "table lock", 0};
PSI_stage_info stage_filling_schema_table= { 0, "Filling schema table", 0};
PSI_stage_info stage_update= { 0, "Update", 0};
PSI_stage_info stage_updating= { 0, "Updating", 0};
@ -9272,7 +9272,6 @@ PSI_stage_info stage_waiting_for_query_cache_lock= { 0, "Waiting for query cache
PSI_stage_info stage_waiting_for_the_next_event_in_relay_log= { 0, "Waiting for the next event in relay log", 0};
PSI_stage_info stage_waiting_for_the_slave_thread_to_advance_position= { 0, "Waiting for the slave SQL thread to advance position", 0};
PSI_stage_info stage_waiting_to_finalize_termination= { 0, "Waiting to finalize termination", 0};
PSI_stage_info stage_waiting_to_get_readlock= { 0, "Waiting to get readlock", 0};
PSI_stage_info stage_binlog_waiting_background_tasks= { 0, "Waiting for background binlog tasks", 0};
PSI_stage_info stage_binlog_write= { 0, "Writing to binlog", 0};
PSI_stage_info stage_binlog_processing_checkpoint_notify= { 0, "Processing binlog checkpoint notification", 0};
@ -9291,6 +9290,7 @@ PSI_stage_info stage_gtid_wait_other_connection= { 0, "Waiting for other master
PSI_stage_info stage_slave_background_process_request= { 0, "Processing requests", 0};
PSI_stage_info stage_slave_background_wait_request= { 0, "Waiting for requests", 0};
PSI_stage_info stage_waiting_for_deadlock_kill= { 0, "Waiting for parallel replication deadlock handling to complete", 0};
PSI_stage_info stage_starting= { 0, "starting", 0};
#ifdef HAVE_PSI_INTERFACE
@ -9419,7 +9419,6 @@ PSI_stage_info *all_server_stages[]=
& stage_waiting_for_the_slave_thread_to_advance_position,
& stage_waiting_for_work_from_sql_thread,
& stage_waiting_to_finalize_termination,
& stage_waiting_to_get_readlock,
& stage_master_gtid_wait_primary,
& stage_master_gtid_wait,
& stage_gtid_wait_other_connection,
@ -9428,7 +9427,8 @@ PSI_stage_info *all_server_stages[]=
& stage_waiting_for_semi_sync_ack_from_slave,
& stage_waiting_for_semi_sync_slave,
& stage_reading_semi_sync_ack,
& stage_waiting_for_deadlock_kill
& stage_waiting_for_deadlock_kill,
& stage_starting
};
PSI_socket_key key_socket_tcpip, key_socket_unix, key_socket_client_connection;

View file

@ -655,7 +655,6 @@ extern PSI_stage_info stage_waiting_for_table_flush;
extern PSI_stage_info stage_waiting_for_the_next_event_in_relay_log;
extern PSI_stage_info stage_waiting_for_the_slave_thread_to_advance_position;
extern PSI_stage_info stage_waiting_to_finalize_termination;
extern PSI_stage_info stage_waiting_to_get_readlock;
extern PSI_stage_info stage_binlog_waiting_background_tasks;
extern PSI_stage_info stage_binlog_write;
extern PSI_stage_info stage_binlog_processing_checkpoint_notify;
@ -674,6 +673,7 @@ extern PSI_stage_info stage_gtid_wait_other_connection;
extern PSI_stage_info stage_slave_background_process_request;
extern PSI_stage_info stage_slave_background_wait_request;
extern PSI_stage_info stage_waiting_for_deadlock_kill;
extern PSI_stage_info stage_starting;
#ifdef HAVE_PSI_STATEMENT_INTERFACE
/**

View file

@ -2390,7 +2390,7 @@ public:
calling_line);
#endif
#ifdef HAVE_PSI_THREAD_INTERFACE
MYSQL_SET_STAGE(m_current_stage_key, calling_file, calling_line);
m_stage_progress_psi= MYSQL_SET_STAGE(m_current_stage_key, calling_file, calling_line);
#endif
}
@ -2988,6 +2988,8 @@ public:
PROFILING profiling;
#endif
/** Current stage progress instrumentation. */
PSI_stage_progress *m_stage_progress_psi;
/** Current statement digest. */
sql_digest_state *m_digest;
/** Current statement digest token array. */

View file

@ -1911,7 +1911,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
com_statement_info[command].m_key,
thd->db.str, thd->db.length,
thd->charset(), NULL);
THD_STAGE_INFO(thd, stage_init);
THD_STAGE_INFO(thd, stage_starting);
MYSQL_SET_STATEMENT_TEXT(thd->m_statement_psi, beginning_of_next_stmt,
length);

View file

@ -10744,6 +10744,8 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
to->file->extra(HA_EXTRA_PREPARE_FOR_ALTER_TABLE);
to->file->ha_start_bulk_insert(from->file->stats.records,
ignore ? 0 : HA_CREATE_UNIQUE_INDEX_BY_SORT);
mysql_stage_set_work_estimated(thd->m_stage_progress_psi, from->file->stats.records);
List_iterator<Create_field> it(create);
Create_field *def;
copy_end=copy;
@ -10844,7 +10846,6 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
from->file->column_bitmaps_signal();
THD_STAGE_INFO(thd, stage_copy_to_tmp_table);
/* Tell handler that we have values for all columns in the to table */
to->use_all_columns();
/* Add virtual columns to vcol_set to ensure they are updated */
@ -10990,7 +10991,11 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to,
}
}
else
{
DEBUG_SYNC(thd, "copy_data_between_tables_before");
found_count++;
mysql_stage_set_work_completed(thd->m_stage_progress_psi, found_count);
}
thd->get_stmt_da()->inc_current_row_for_warning();
}