码迷,mamicode.com
首页 > 数据库 > 详细

4.mysql profile的使用方法

时间:2020-12-23 11:52:30      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:ring   duration   clean   执行   准备   swap   lock   func   statistic   

profile的使用

1、作用

使用profile可以对某一条sql性能进行分析

2、语法


mysql> show variables like ‘%profil%‘;
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| have_profiling         | YES   |
| profiling              | ON    |  开启profile功能
| profiling_history_size | 15    |  profile能记录多少条sql
+------------------------+-------+

set profiling = 0/1;       关闭或开启profile功能
mysql> show profiles;      查看当前profile记录的所有sql
+----------+-------------+------------------------------------------------------------+
| Query_ID | Duration    | Query                                                      |
+----------+-------------+------------------------------------------------------------+
|        1 |  0.00163850 | show variables like ‘%profil%‘                             |
|        2 |  0.00005825 | show warnings                                              |
|        3 | 23.85836475 | select * from course c left join study s on c.age = s.snum |
|        4 |  0.23801475 | select * from study s left join course c on c.age = s.snum |
|        5 |  0.00010450 | set profiling=1                                            |
|        6 |  0.00190400 | show variables like ‘%prifil%‘                             |
|        7 |  0.00175100 | show variables like ‘%profil%‘                             |
+----------+-------------+------------------------------------------------------------+
mysql> show profile for query 4;  查看某个Query的执行持续时间分布
+----------------------+----------+
| Status               | Duration |
+----------------------+----------+
| starting             | 0.000131 |
| checking permissions | 0.000008 |
| checking permissions | 0.000005 |
| Opening tables       | 0.000015 |
| init                 | 0.000023 |
| System lock          | 0.000009 |
| optimizing           | 0.000008 |
| statistics           | 0.000027 |
| preparing            | 0.000012 |
| executing            | 0.000004 |
| Sending data         | 0.237726 |
| end                  | 0.000010 |
| query end            | 0.000007 |
| closing tables       | 0.000008 |
| freeing items        | 0.000014 |
| cleaning up          | 0.000010 |
+----------------------+----------+
show profile [all|cpu|block io|……] for query number;      可以查看[全部|cpu相关|io相关]细节

3、含义分析

show profile all for query n;

横向栏意义
+----------------------+----------+----------+------------+
"Status": "query end", 状态
"Duration": "1.751142", 持续时间
"CPU_user": "0.008999", cpu用户
"CPU_system": "0.003999", cpu系统
"Context_voluntary": "98", 上下文主动切换
"Context_involuntary": "0", 上下文被动切换
"Block_ops_in": "8", 阻塞的输入操作
"Block_ops_out": "32", 阻塞的输出操作
"Messages_sent": "0", 消息发出
"Messages_received": "0", 消息接受
"Page_faults_major": "0", 主分页错误
"Page_faults_minor": "0", 次分页错误
"Swaps": "0", 交换次数
"Source_function": "mysql_execute_command", 源功能
"Source_file": "sql_parse.cc", 源文件
"Source_line": "4465" 源代码行
+----------------------+----------+----------+------------+

纵向栏意义
+----------------------+----------+----------+------------+
starting:开始
checking permissions:检查权限
Opening tables:打开表
init : 初始化
System lock :系统锁
optimizing : 优化
statistics : 统计
preparing :准备
executing :执行
Sending data :发送数据
Sorting result :排序
end :结束
query end :查询 结束
closing tables : 关闭表 /去除TMP 表
freeing items : 释放物品
cleaning up :清理
+----------------------+----------+----------+------------+

4.mysql profile的使用方法

标签:ring   duration   clean   执行   准备   swap   lock   func   statistic   

原文地址:https://www.cnblogs.com/unsigned1995/p/14154031.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!