如何使用Performance Schema查看Profiling

技术如何使用Performance Schema查看Profiling小编给大家分享一下如何使用Performance Schema查看Profiling,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!S

小编给大家分享一下如何使用性能模式查看侧写,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

显示个人资料可以用来关系型数据库执行语句时候所使用的资源(诸如IO,上下文切换,中央处理器,内存等等),但是从MySQL 5.6.7开始此特性将被移除,而使用性能模式代替,如下:

如何使用Performance  Schema查看Profiling

setup_actors 配置

MySQL 5.7.8,可以通过设置_参与者表来配置主机、用户或帐户的信息被收集,如下:

#默认情况下设置_参与者的配置是允许监控和收集所有前台线程的历史事件信息

选择*从

性能模式。setup _ actors

- - - - -

|主机|用户|角色|已启用|历史记录|

- - - - -

| % | % | %

|是|是|

- - - - -

一行一组(0.03秒)

#修改默认的配置,关闭对所有前台线程的监控和收集。并且插入新的行为指定的用户开启监控和收集信息

关系型数据库

更新性能_模式。设置_参与者设置已启用='否,历史记录='否'

-其中主机="%"和用户="%";

MySQL INSERT INTO performance _ schema。设置_参与者

(主机、用户、角色、已启用、历史记录)

- VALUES('localhost ',' test_user ',' % ',' YES ',' YES ');

#修改后的配置如下:

MySQL SELECT * FROM performance _ schema。setup _ actors

- - - - -

|主机|用户|角色|已启用|历史记录|

- - - - -

| % | % | % |否|否|

| localhost | test _ user | % | YES | YES |

- - - - -

#只监控和收集test_user@localhost用户相关的事件信息

Query Profiling Using Performance Schema

下文简单尝试下使用Performance Schema来查询profile相关信息,使用方法如下

1.开启setup_instruments表中statement和stage instrumentation相关配置,其中有些可能默认已经开启

MySQL UPDATE performance _ schema。设置_仪器设置启用='是',定时='是'

-哪里名字像' %语句/% ';

MySQL UPDATE performance _ schema。设置_仪器设置启用='是',定时='是'

r/>-> WHERE NAME LIKE '%stage/%';

2.开启events_statements_* and events_stages_*相关消费(consumers),有些项目已经默认开启

mysql> UPDATE performance_schema.setup_consumers SET ENABLED = 'YES'
-> WHERE NAME LIKE '%events_statements_%';
mysql> UPDATE performance_schema.setup_consumers SET ENABLED = 'YES'
-> WHERE NAME LIKE '%events_stages_%';

3.为了与show profile的结果做对比,开启profiling功能

mysql >set profiling=1;

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql >show warnings; #此处,也可以看到此特性将被移除的警告

+---------+------+----------------------------------------------------------------------+

| Level | Code | Message |

+---------+------+----------------------------------------------------------------------+

| Warning | 1287 | '@@profiling' is deprecated and will be removed in a future release. |

+---------+------+----------------------------------------------------------------------+

1 row in set (0.00 sec)

4.执行SQL语句

mysql >select * from t;

+----+------+

| 9 | 15 |

| 10 | 15 |

| 2 | 20 |

| 3 | 20 |

| 8 | 25 |

+----+------+

5 rows in set (0.00 sec)5 rows in set (0.00 sec)

5.查看profiling结果

mysql>show profiles;
+----------+------------+-----------------+
| Query_ID | Duration | Query |
+----------+------------+-----------------+
| 1 | 0.00010150 | show warnings |
| 2 | 0.00032075 | select * from t |
+----------+------------+-----------------+
2 rows in set, 1 warning (0.00 sec)

mysql>show profile for query 2;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| starting | 0.000038 |
| checking permissions | 0.000009 |
| Opening tables | 0.000048|
| init | 0.000022 |
| System lock | 0.000012 |
| optimizing | 0.000007 |
| statistics | 0.000016 |
| preparing | 0.000015 |
| executing | 0.000005 |
| Sending data | 0.000063 |
| end | 0.000008 |
| query end | 0.000009 |
| closing tables | 0.000013 |
| freeing items | 0.000012 |
| cleaning up | 0.000050 |
+----------------------+----------+
15 rows in set, 1 warning (0.00 sec)

6.查找刚才执行SQL的EVENT_ID,这步骤类似于show profiles查看query id.通过查询表events_statements_history_long获得对应的EVENT_ID

如何使用Performance Schema查看Profiling

注:此处只为了说明问题,可能还查询到很多其他的SQL,但是我们自己知道我们执行的SQL是哪条,其他的SQL此处都被省略了

7.通过查询events_stages_history_long表(NESTING_EVENT_ID=EVENT_ID)获得最终结果

mysql>SELECT event_name AS Stage, TRUNCATE(TIMER_WAIT/1000000000000,6) AS Duration

>FROM performance_schema.events_stages_history_long WHERE NESTING_EVENT_ID=79;
+--------------------------------+----------+
| Stage | Duration |
+--------------------------------+----------+
| stage/sql/init | 0.000048 |
| stage/sql/checking permissions | 0.000008 |
| stage/sql/Opening tables | 0.000051 |
| stage/sql/init | 0.000019 |
| stage/sql/System lock | 0.000012 |
| stage/sql/optimizing | 0.000006 |
| stage/sql/statistics | 0.000016 |
| stage/sql/preparing | 0.000015 |
| stage/sql/executing | 0.000004 |
| stage/sql/Sending data | 0.000066 |
| stage/sql/end | 0.000005 |
| stage/sql/query end | 0.000008 |
| stage/sql/closing tables | 0.000013 |
| stage/sql/freeing items | 0.000011 |
| stage/sql/cleaning up | 0.000001 |
+--------------------------------+----------+
15 rows in set (0.01 sec)

如上,实现了通过Performance Schema来查询profileing相关信息,最终能看到的选项跟show profile显示的选项几乎一样,只是各项的值好像不太一致。

看完了这篇文章,相信你对“如何使用Performance Schema查看Profiling”有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!

内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/52402.html

(0)

相关推荐

  • 有哪些更改数据库密码的方式

    技术有哪些更改数据库密码的方式这篇文章主要讲解了“有哪些更改数据库密码的方式”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“有哪些更改数据库密码的方式”吧!1.忘记 roo

    攻略 2021年10月22日
  • 梦想当老师的英语作文,我的梦想老师英语作文50字左右

    技术梦想当老师的英语作文,我的梦想老师英语作文50字左右《My dream is to be a teacher》i have a dream,i want to be a english teacher.first,e

    生活 2021年10月28日
  • leetcode反转链表怎么用(leetcode链表怎么分割)

    技术LeetCode如何实现部分链表反转这篇文章将为大家详细讲解有关LeetCode如何实现部分链表反转,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。部分链表反转。1)链表为空或者一个

    攻略 2021年12月15日
  • 如何将eclipse项目导入myeclipse(可以同时安装eclipse和myeclipse)

    技术如何进行MyEclipse6.5+Eclipse3.4的中文问题浅析今天就跟大家聊聊有关如何进行MyEclipse6.5+Eclipse3.4的中文问题浅析,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了

    攻略 2021年12月18日
  • 控制流程语句

    技术控制流程语句 控制流程语句控制流程语句:
    语句:就是使用分号分的代码就是一个语句。
    顺序语句:就式从上往下执行所有代码就是语句。int i = 3;  //声明变量语句;  //空语句Sstem.o

    礼包 2021年12月13日
  • 美女生日祝福语八个字,朋友生日祝福语,女性简短八个

    技术美女生日祝福语八个字,朋友生日祝福语,女性简短八个1.生日快乐,永远美丽美女生日祝福语八个字!2.今天,你是最美丽的,美好的生日祝福,送给你,美丽的生日礼物,送给你3.时间的轮回让我们陪伴着你过了一个又一个的生日,看

    生活 2021年10月28日