万梅资源网 Design By www.ubjie.com

profile是什么

当我们要对某一条sql的性能进行分析时,可以使用它。

Profiling是从 mysql5.0.3版本以后才开放的。

启动profile之后,所有查询包括错误的语句都会记录在内。

关闭会话或者set profiling=0 就关闭了。(如果将profiling_history_size参数设置为0,同样具有关闭MySQL的profiling效果。)

此工具可用来查询SQL执行状态,System lock和Table lock 花多少时间等等,

对定位一条语句的I/O消耗和CPU消耗 非常重要。(SQL 语句执行所消耗的最大两部分资源就是IO和CPU)

--在mysql5.7之后,profile信息将逐渐被废弃,mysql推荐使用performance schema

mysql官网定义

The SHOW PROFILE and SHOW PROFILES statements display profiling information that indicates resource usage for statements executed during the course of the current session.

简单的说,当前会话资源的消耗情况。

注意:show profile和show Profiles都是不建议使用的,在mysql后期的版本中可能会被删除;官网建议使用Performance Schema

怎么使用

profile默认关闭,生产环境中也建议关闭。

查看当前环境的profile设置

mysql> show variables like '%profiling%';
+------------------------+-------+
| Variable_name   | Value |
+------------------------+-------+
| have_profiling   | YES |
| profiling    | OFF |
| profiling_history_size | 15 |
+------------------------+-------+

profiling off表示profile关闭,profiling_history_size 15表示保存最近15条SQL的资源消耗情况。

开启profile功能,可以使用命令

set global profiling = 1;

然后就可以使用下面命令

show profiles;

查看最近15条SQL的情况;

如果要查看某一条的具体情况,SQL格式为:

SHOW PROFILE [type [, type] ... ]
 [FOR QUERY n]
 [LIMIT row_count [OFFSET offset]]

type: {
 ALL
 | BLOCK IO
 | CONTEXT SWITCHES
 | CPU
 | IPC
 | MEMORY
 | PAGE FAULTS
 | SOURCE
 | SWAPS
}

官网对type中各个字段的解释为:

    ALL displays all information

    BLOCK IO displays counts for block input and output operations

    CONTEXT SWITCHES displays counts for voluntary and involuntary context switches

    CPU displays user and system CPU usage times

    IPC displays counts for messages sent and received

    MEMORY is not currently implemented

    PAGE FAULTS displays counts for major and minor page faults

    SOURCE displays the names of functions from the source code, together with the name and line number of the file in which the function occurs

    SWAPS displays swap counts

profiling 对每个会话有效,当会话结束后,当前的profiling信息就会丢失。

使用案例

mysql> show profiles;
+----------+------------+----------------------------+
| Query_ID | Duration | Query      |
+----------+------------+----------------------------+
|  1 | 0.00060275 | select * from customers |
|  2 | 0.00222450 | show tables    |
|  3 | 0.00567425 | select * from offices  |
|  4 | 0.00052050 | show tables    |
|  5 | 0.01123300 | select * from payments  |
|  6 | 0.00111675 | show tables    |
|  7 | 0.02049625 | select * from productlines |
+----------+------------+----------------------------+

在排查SQL执行情况,或者是哪条SQL执行非常慢,慢在哪里;profile都是非常的辅助工具。

显示一条SQL的具体花销在哪里

mysql> show profile for query 7;
+----------------------+----------+
| Status    | Duration |
+----------------------+----------+
| starting    | 0.000043 |
| checking permissions | 0.000005 |
| Opening tables  | 0.014552 |
| init     | 0.000025 |
| System lock   | 0.000009 |
| optimizing   | 0.000004 |
| statistics   | 0.000011 |
| preparing   | 0.000010 |
| executing   | 0.000003 |
| Sending data   | 0.005653 |
| end     | 0.000010 |
| query end   | 0.000009 |
| closing tables  | 0.000020 |
| freeing items  | 0.000121 |
| cleaning up   | 0.000023 |
+----------------------+----------+

信息一目了然,这样我就能对SQL执行情况有个大概的了解。

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对的支持。

万梅资源网 Design By www.ubjie.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
万梅资源网 Design By www.ubjie.com

《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线

暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。

艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。

《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。