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

转载自            http://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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

举例

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

    select @@profiling;
       
       
    • 1

    这里写图片描述

  2. 打开 profiling 功能

    set profiling=1;
       
       
    • 1

    这里写图片描述

  3. 执行sql语句 
    这里写图片描述

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

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

    show profile for query 2;
       
       
    • 1

    这里写图片描述

  6. 可指定资源类型查询


show profile cpu,swaps for query 2; 

这里写图片描述


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值