Commit 358b942b authored by unknown's avatar unknown

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.
parent d29f4da4
show profiles;
Query_ID Duration Query
show profile all;
Status Duration CPU_user CPU_system Context_voluntary Context_involuntary Block_ops_in Block_ops_out Messages_sent Messages_received Page_faults_major Page_faults_minor Swaps Source_function Source_file Source_line
show session variables like 'profil%';
Variable_name Value
profiling OFF
......
# Verify that the protocol isn't violated if we ask for profiling info
# before profiling has recorded anything.
show profiles;
show profile all;
# default is OFF
show session variables like 'profil%';
select @@profiling;
......
......@@ -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;
}
......
This diff is collapsed.
......@@ -39,6 +39,7 @@ extern const char * const _unknown_func_;
extern ST_FIELD_INFO query_profile_statistics_info[];
int fill_query_profile_statistics_info(THD *thd, struct st_table_list *tables, Item *cond);
int make_profile_table_for_show(THD *thd, ST_SCHEMA_TABLE *schema_table);
#define PROFILE_NONE 0
......@@ -332,12 +333,6 @@ public:
/* SHOW PROFILES */
bool show_profiles();
/* SHOW PROFILE FOR QUERY query_id */
bool show(uint options, uint profiling_query_id);
/* SHOW PROFILE */
bool show_last(uint options);
/* ... from INFORMATION_SCHEMA.PROFILING ... */
int fill_statistics_info(THD *thd, struct st_table_list *tables, Item *cond);
};
......
......@@ -4344,7 +4344,8 @@ ST_SCHEMA_TABLE schema_tables[]=
{"OPEN_TABLES", open_tables_fields_info, create_schema_table,
fill_open_tables, make_old_format, 0, -1, -1, 1},
{"PROFILING", query_profile_statistics_info, create_schema_table,
fill_query_profile_statistics_info, NULL, NULL, -1, -1, false},
fill_query_profile_statistics_info, make_profile_table_for_show,
NULL, -1, -1, false},
{"ROUTINES", proc_fields_info, create_schema_table,
fill_schema_proc, make_proc_old_format, 0, -1, -1, 0},
{"SCHEMATA", schema_fields_info, create_schema_table,
......
......@@ -7044,7 +7044,13 @@ show_param:
| PROFILES_SYM
{ Lex->sql_command = SQLCOM_SHOW_PROFILES; }
| PROFILE_SYM opt_profile_defs opt_profile_args opt_limit_clause_init
{ Lex->sql_command = SQLCOM_SHOW_PROFILE; }
{
LEX *lex= Lex;
lex->sql_command= SQLCOM_SELECT;
lex->orig_sql_command= SQLCOM_SHOW_PROFILE;
if (prepare_schema_table(YYTHD, lex, NULL, SCH_PROFILES) != 0)
YYABORT;
}
| opt_var_type STATUS_SYM wild_and_where
{
LEX *lex= Lex;
......
......@@ -320,7 +320,7 @@ enum enum_schema_tables
SCH_COLUMN_PRIVILEGES,
SCH_KEY_COLUMN_USAGE,
SCH_OPEN_TABLES,
SCH_PROFILING,
SCH_PROFILES,
SCH_PROCEDURES,
SCH_SCHEMATA,
SCH_SCHEMA_PRIVILEGES,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment