profiling – MySQL资源使用情况剖析工具

1,981 total views, 1 views today

profiling 用于剖析当前session执行SQL语句的资源使用情况。

如何使用profileing

1、开启profiling

set profiling = 1;

profiling变量默认是0(off),且一般开启session级别。

 

2、执行需要诊断剖析SQL语句

show tables like ‘sbtest%’;

 

3、查看性能剖析

先明确两个命令:
show prfiles :查看最近执行的SQL命令的信息(包含 QUERY_ID,持续时间,命令),展现的条数由 profiling_history_size 变量确定,默认是15,如果想保留更多请调大该变量的值,最大值100。最小值是0,表示禁用profiling。

show profile :展现单个SQL命令剖析的细节。根据 show profiles的输出结果中的 QUERY_ID,带入到 show profile for query n中,那么展示的就是这个QUERY_ID的性能剖析信息。不写 for query n ,展示的则是最后一次执行的SQL命令的剖析信息。

我们想看 QUERY_ID 为4的SQL命令剖析内容。可以看到“checking permissions”占据了最多的时间消耗。

 

可以扩展看到更多的详细资料类型占用,比如CPU、内存、上下文切换等等。

  • 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

查看用户和系统CPU使用时间

 
查看IO输入、输出的次数

 
也可以通过 INFORMATION_SCHEMA.PROFILING 表查询profiling信息。这两种方式的结果相同。

参考:https://dev.mysql.com/doc/refman/5.7/en/show-profile.html

发表评论

必填项已用*标注