中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何使用Performance Schema查看Profiling

發布時間:2021-10-27 17:35:48 來源:億速云 閱讀:135 作者:小新 欄目:MySQL數據庫

小編給大家分享一下如何使用Performance Schema查看Profiling,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

SHOW PROFILE可以用來MySQL執行語句時候所使用的資源(諸如IO,上下文切換,CPU,Memory等等),但是從MySQL 5.6.7開始此特性將被移除,而使用Performance Schema代替,如下:

如何使用Performance Schema查看Profiling

setup_actors 配置

MySQL 5.7.8, 可以通過setup_actors表來配置host, user, or account的信息被收集,如下:
#默認情況下setup_actors 的配置是允許監控和收集所有前臺線程的歷史事件信息 

>SELECT * FROM performance_schema.setup_actors;
+------+------+------+---------+---------+
| HOST | USER | ROLE | ENABLED | HISTORY |
+------+------+------+---------+---------+
| %    | %    | %    | YES     | YES     |
+------+------+------+---------+---------+
1 row in set (0.03 sec)


#修改默認的配置,關閉對所有前臺線程的監控和收集。并且插入新的行為指定的用戶開啟監控和收集信息

mysql> UPDATE performance_schema.setup_actors SET ENABLED = 'NO', HISTORY = 'NO'
-> WHERE HOST = '%' AND USER = '%';
mysql> INSERT INTO performance_schema.setup_actors (HOST,USER,ROLE,ENABLED,HISTORY)
-> VALUES('localhost','test_user','%','YES','YES');

#修改后的配置如下:
mysql> SELECT * FROM performance_schema.setup_actors;
+-----------+-----------+------+---------+---------+
| HOST | USER | ROLE | ENABLED | HISTORY |
+-----------+-----------+------+---------+---------+
| % | % | % | NO | NO |
| 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.setup_instruments SET ENABLED = 'YES', TIMED = 'YES'
-> WHERE NAME LIKE '%statement/%';
mysql> UPDATE performance_schema.setup_instruments SET ENABLED = 'YES', TIMED = 'YES'
-> 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”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

洛浦县| 敖汉旗| 河间市| 玛纳斯县| 九江市| 克拉玛依市| 阿瓦提县| 清涧县| 新昌县| 牡丹江市| 汉中市| 江津市| 江城| 盘山县| 和平县| 澄城县| 滦平县| 余姚市| 湖州市| 临清市| 平潭县| 孙吴县| 永嘉县| 溧阳市| 尚志市| 家居| 琼结县| 姚安县| 垫江县| 湘潭县| 泗水县| 朝阳市| 博客| 漳平市| 瓮安县| 周宁县| 石渠县| 建始县| 积石山| 冷水江市| 厦门市|