Performance Schema 仪器阶段,它们是语句执行过程中的步骤,例如解析语句、打开表或执行
filesort
操作。阶段对应于表中显示的SHOW
PROCESSLIST
或可见
的线程状态INFORMATION_SCHEMA.PROCESSLIST
。当状态值改变时,阶段开始和结束。
在事件层次结构中,等待事件嵌套在阶段事件中,阶段事件嵌套在语句事件中。
这些表存储阶段事件:
events_stages_current
:每个线程的当前阶段事件。events_stages_history
:每个线程结束的最近阶段事件。events_stages_history_long
:全局结束的最新阶段事件(跨所有线程)。
以下部分描述阶段事件表。也有汇集阶段事件信息的汇总表;参见 第 22.12.9.2 节,“阶段汇总表”。
有关三个阶段事件表之间关系的更多信息,请参阅 第 22.9 节,“当前和历史事件的性能模式表”。
配置阶段事件收集
控制是否采集stage事件,设置相关instruments和consumer的状态:
该
setup_instruments
表包含名称以 开头的工具stage
。使用这些工具来启用或禁用各个阶段事件类的收集。该
setup_consumers
表包含名称与当前和历史阶段事件表名称相对应的消费者值。使用这些消费者来过滤阶段事件的集合。
默认情况下禁用舞台乐器。例如:
mysql> SELECT *
FROM performance_schema.setup_instruments
WHERE NAME RLIKE 'stage/sql/[a-c]';
+----------------------------------------------------+---------+-------+
| NAME | ENABLED | TIMED |
+----------------------------------------------------+---------+-------+
| stage/sql/After create | NO | NO |
| stage/sql/allocating local table | NO | NO |
| stage/sql/altering table | NO | NO |
| stage/sql/committing alter table to storage engine | NO | NO |
| stage/sql/Changing master | NO | NO |
| stage/sql/Checking master version | NO | NO |
| stage/sql/checking permissions | NO | NO |
| stage/sql/checking privileges on cached query | NO | NO |
| stage/sql/checking query cache for query | NO | NO |
| stage/sql/cleaning up | NO | NO |
| stage/sql/closing tables | NO | NO |
| stage/sql/Connecting to master | NO | NO |
| stage/sql/converting HEAP to MyISAM | NO | NO |
| stage/sql/Copying to group table | NO | NO |
| stage/sql/Copying to tmp table | NO | NO |
| stage/sql/copy to tmp table | NO | NO |
| stage/sql/Creating delayed handler | NO | NO |
| stage/sql/Creating sort index | NO | NO |
| stage/sql/creating table | NO | NO |
| stage/sql/Creating tmp table | NO | NO |
+----------------------------------------------------+---------+-------+
默认情况下禁用阶段消费者:
mysql> SELECT *
FROM performance_schema.setup_consumers
WHERE NAME LIKE 'events_stages%';
+----------------------------+---------+
| NAME | ENABLED |
+----------------------------+---------+
| events_stages_current | NO |
| events_stages_history | NO |
| events_stages_history_long | NO |
+----------------------------+---------+
要在服务器启动时控制阶段事件收集,请在my.cnf
文件中使用如下行:
使能够:
[mysqld] performance-schema-instrument='stage/%=ON' performance-schema-consumer-events-stages-current=ON performance-schema-consumer-events-stages-history=ON performance-schema-consumer-events-stages-history-long=ON
禁用:
[mysqld] performance-schema-instrument='stage/%=OFF' performance-schema-consumer-events-stages-current=OFF performance-schema-consumer-events-stages-history=OFF performance-schema-consumer-events-stages-history-long=OFF
要在运行时控制阶段事件收集,请更新
setup_instruments
和
setup_consumers
表:
使能够:
UPDATE performance_schema.setup_instruments SET ENABLED = 'YES', TIMED = 'YES' WHERE NAME LIKE 'stage/%'; UPDATE performance_schema.setup_consumers SET ENABLED = 'YES' WHERE NAME LIKE 'events_stages%';
禁用:
UPDATE performance_schema.setup_instruments SET ENABLED = 'NO', TIMED = 'NO' WHERE NAME LIKE 'stage/%'; UPDATE performance_schema.setup_consumers SET ENABLED = 'NO' WHERE NAME LIKE 'events_stages%';
要仅收集特定的舞台事件,请仅启用相应的舞台乐器。要仅为特定阶段事件表收集阶段事件,请启用阶段工具,但仅启用与所需表对应的阶段消费者。
该setup_timers
表包含一个NAME
值为 的
行,该行stage
指示阶段事件计时的单位。默认单位是NANOSECOND
:
mysql> SELECT *
FROM performance_schema.setup_timers
WHERE NAME = 'stage';
+-------+------------+
| NAME | TIMER_NAME |
+-------+------------+
| stage | NANOSECOND |
+-------+------------+
要更改计时单位,请修改
TIMER_NAME
值:
UPDATE performance_schema.setup_timers
SET TIMER_NAME = 'MICROSECOND'
WHERE NAME = 'stage';
有关配置事件收集的其他信息,请参阅第 22.3 节,“性能模式启动配置”和第 22.4 节,“性能模式运行时配置”。