MySQL性能分析语句 show profile/show profiles

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/littleboyandgirl/article/details/68486642

功能说明

  • show profile 和 show profiles 语句可以展示当前会话(退出session后,profiling重置为0) 中执行语句的资源使用情况.
  • Profiling 功能由MySQL会话变量 : profiling控制,默认是OFF.关闭状态.

    • select @@profiling;
    • show variables like ‘%profil%’;
      通过以上两个语句均可以查看 当前session是否打开了profile功能.
      这里写图片描述
  • Profiling 信息收集依赖于调用 系统方法 getrusage().因此Windows系统不适用.

  • 另外Profiling是针对进程(process)而非线程(threads),因此运行在服务器上的其他服务进程可能会影响分析结果.

语句使用

  • show profiles :列表,显示最近发送到服务器上执行的语句的资源使用情况.显示的记录数由变量:profiling_history_size 控制,默认15条.
    这里写图片描述

  • show profile: 展示最近一条语句执行的详细资源占用信息,默认显示 Status和Duration两列.
    这里写图片描述

  • show profile 还可根据 show profiles 列表中的 Query_ID ,选择显示某条记录的性能分析信息.
语法结构:

 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

举例

  1. 查看是否打开了性能分析功能

    select @@profiling;

    这里写图片描述

  2. 打开 profiling 功能

    set profiling=1;

    这里写图片描述

    扫描二维码关注公众号,回复: 3219596 查看本文章
  3. 执行sql语句
    这里写图片描述

  4. 执行 show profiles 查看分析列表
    这里写图片描述

  5. 查询第二条语句的执行情况

    show profile for query 2;

    这里写图片描述

  6. 可指定资源类型查询


show profile cpu,swaps for query 2;

这里写图片描述

参考:
MySQL 操作手册: 13.7.5.31 SHOW PROFILE Syntax
MySQL操作手册: 详细的State描述

猜你喜欢

转载自blog.csdn.net/littleboyandgirl/article/details/68486642