MySQL 8.4.3
Source Code Documentation
sql_profile.cc File Reference

Implement query profiling as as list of metaphorical fences, with one fence per query, and each fencepost a change of thd->proc_info state (with a snapshot of system statistics). More...

#include "sql/sql_profile.h"
#include "my_config.h"
#include <string.h>
#include <algorithm>
#include "decimal.h"
#include "m_string.h"
#include "my_base.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_sqlcommand.h"
#include "my_sys.h"
#include "my_systime.h"
#include "mysql/strings/m_ctype.h"
#include "nulls.h"
#include "sql-common/my_decimal.h"
#include "sql/field.h"
#include "sql/item.h"
#include "sql/protocol.h"
#include "sql/psi_memory_key.h"
#include "sql/query_options.h"
#include "sql/sql_class.h"
#include "sql/sql_error.h"
#include "sql/sql_lex.h"
#include "sql/sql_list.h"
#include "sql/sql_show.h"
#include "sql/system_variables.h"
#include "sql_string.h"

Macros

#define TIME_FLOAT_DIGITS   9
 
#define TIME_I_S_DECIMAL_SIZE    (TIME_FLOAT_DIGITS * 100) + (TIME_FLOAT_DIGITS - 3)
 two vals encoded: (dec*100)+len More...
 
#define MAX_QUERY_HISTORY   101U
 
#define RUSAGE_USEC(tv)   ((tv).tv_sec * 1000 * 1000 + (tv).tv_usec)
 
#define RUSAGE_DIFF_USEC(tv1, tv2)   (RUSAGE_USEC((tv1)) - RUSAGE_USEC((tv2)))
 

Functions

int fill_query_profile_statistics_info (THD *thd, Table_ref *tables, Item *)
 Connects Information_Schema and Profiling. More...
 
int make_profile_table_for_show (THD *thd, ST_SCHEMA_TABLE *schema_table)
 

Variables

static const size_t MAX_QUERY_LENGTH = 300
 
ST_FIELD_INFO query_profile_statistics_info []
 

Detailed Description

Implement query profiling as as list of metaphorical fences, with one fence per query, and each fencepost a change of thd->proc_info state (with a snapshot of system statistics).

When asked, we can then iterate over the fenceposts and calculate the distance between them, to inform the user what happened during a particular query or thd->proc_info state.

User variables that inform profiling behavior:

  • "profiling", boolean, session only, "Are queries profiled?"
  • "profiling_history_size", integer, session + global, "Num queries stored?"

Macro Definition Documentation

◆ MAX_QUERY_HISTORY

#define MAX_QUERY_HISTORY   101U

◆ RUSAGE_DIFF_USEC

#define RUSAGE_DIFF_USEC (   tv1,
  tv2 
)    (RUSAGE_USEC((tv1)) - RUSAGE_USEC((tv2)))

◆ RUSAGE_USEC

#define RUSAGE_USEC (   tv)    ((tv).tv_sec * 1000 * 1000 + (tv).tv_usec)

◆ TIME_FLOAT_DIGITS

#define TIME_FLOAT_DIGITS   9

◆ TIME_I_S_DECIMAL_SIZE

#define TIME_I_S_DECIMAL_SIZE    (TIME_FLOAT_DIGITS * 100) + (TIME_FLOAT_DIGITS - 3)

two vals encoded: (dec*100)+len

Function Documentation

◆ fill_query_profile_statistics_info()

int fill_query_profile_statistics_info ( THD thd,
Table_ref tables,
Item  
)

Connects Information_Schema and Profiling.

◆ make_profile_table_for_show()

int make_profile_table_for_show ( THD thd,
ST_SCHEMA_TABLE schema_table 
)

Variable Documentation

◆ MAX_QUERY_LENGTH

const size_t MAX_QUERY_LENGTH = 300
static

◆ query_profile_statistics_info

ST_FIELD_INFO query_profile_statistics_info[]
Initial value:
= {
{"QUERY_ID", 20, MYSQL_TYPE_LONG, 0, false, "Query_id", 0},
{"SEQ", 20, MYSQL_TYPE_LONG, 0, false, "Seq", 0},
{"STATE", 30, MYSQL_TYPE_STRING, 0, false, "Status", 0},
{"DURATION", TIME_I_S_DECIMAL_SIZE, MYSQL_TYPE_DECIMAL, 0, false,
"Duration", 0},
{"CPU_USER", TIME_I_S_DECIMAL_SIZE, MYSQL_TYPE_DECIMAL, 0, true, "CPU_user",
0},
{"CPU_SYSTEM", TIME_I_S_DECIMAL_SIZE, MYSQL_TYPE_DECIMAL, 0, true,
"CPU_system", 0},
{"CONTEXT_VOLUNTARY", 20, MYSQL_TYPE_LONG, 0, true, "Context_voluntary", 0},
{"CONTEXT_INVOLUNTARY", 20, MYSQL_TYPE_LONG, 0, true, "Context_involuntary",
0},
{"BLOCK_OPS_IN", 20, MYSQL_TYPE_LONG, 0, true, "Block_ops_in", 0},
{"BLOCK_OPS_OUT", 20, MYSQL_TYPE_LONG, 0, true, "Block_ops_out", 0},
{"MESSAGES_SENT", 20, MYSQL_TYPE_LONG, 0, true, "Messages_sent", 0},
{"MESSAGES_RECEIVED", 20, MYSQL_TYPE_LONG, 0, true, "Messages_received", 0},
{"PAGE_FAULTS_MAJOR", 20, MYSQL_TYPE_LONG, 0, true, "Page_faults_major", 0},
{"PAGE_FAULTS_MINOR", 20, MYSQL_TYPE_LONG, 0, true, "Page_faults_minor", 0},
{"SWAPS", 20, MYSQL_TYPE_LONG, 0, true, "Swaps", 0},
{"SOURCE_FUNCTION", 30, MYSQL_TYPE_STRING, 0, true, "Source_function", 0},
{"SOURCE_FILE", 20, MYSQL_TYPE_STRING, 0, true, "Source_file", 0},
{"SOURCE_LINE", 20, MYSQL_TYPE_LONG, 0, true, "Source_line", 0},
{nullptr, 0, MYSQL_TYPE_STRING, 0, true, nullptr, 0}}
@ MYSQL_TYPE_STRING
Definition: field_types.h:88
@ MYSQL_TYPE_LONG
Definition: field_types.h:59
@ MYSQL_TYPE_DECIMAL
Definition: field_types.h:56
#define TIME_I_S_DECIMAL_SIZE
two vals encoded: (dec*100)+len
Definition: sql_profile.cc:74