zoukankan      html  css  js  c++  java
  • mysql怎样设置可以跟踪语句各阶段性能开销

    概述

     

    PROFILE 可以跟踪查询语句各个阶段 Time,IO,CPU,MEMORY 等资源使用情况,比较详细。所以系统一般不会记录太多。启用是全局的,所以每个连接都保持语句的资源使用情况。

     

    The SHOW PROFILE and SHOW PROFILES statements display profiling information that indicates resource usage for statements executed during the course of the current session.

     

    1、查看 PROFILE 是否启用

     

    mysql> select @@profiling; mysql> show variables like '%profiling%'; 

     

     

     

    have_profiling :是否可使用 profilingprofiling :是否启用profiling_history_size : 保留最近执行的记录数量。默认15,最大100,0相当于禁用。

     

    2、启用profile(为全局变量)

     

    mysql> set profiling = 1; mysql> set profiling_history_size = 10; 

     

     

     

    3、查看当前连接最近执行语句情况,编号越大为当前最近执行的

    mysql> show profiles; 

     

    4、查看以上查询开销:SHOW PROFILE Syntax

    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 

     

    默认显示时间信息,显示了该查询从开始到被清除各个阶段的执行时间。

    mysql> show profile; 

     

    其他查看方法:

    mysql> show profile; #默认显示时间信息 mysql> show profile CPU,BLOCK IO; #(时间)加上 CPU,BLOCK IO 使用情况 mysql> show profile for query 6; #query_id=6的(时间)信息 mysql> show profile CPU for query 6; #query_id=6的cpu信息 mysql> show profile CPU limit 6; #前6个状态信息(前6行) mysql> show profile CPU limit 6 offset 2;#第2行起前6个状态信息(前2~7行) 

     

    5、关闭跟踪

    set profiling = 0; set profiling_history_size = 0; 

     

  • 相关阅读:
    auto_ptr(转载)
    OSG在VS2008下的配置安装
    没有找到MSVCR80.dll (转)
    获取程序数据路径(转)
    vc中error LNK2001:unresolved external symbol _WinMain@16的解决方法(转)
    wxWidgets编程笔记二(samples使用设置)
    关于简繁转换的工作以及校正转换词汇表的设计
    汉文博士简繁汉字转换功能测试版已经上线
    感谢wangyanhan和sanwsw网友为汉文博士制作数据库
    汉文博士新增四角号码检索字典
  • 原文地址:https://www.cnblogs.com/chaihy/p/11138299.html
Copyright © 2011-2022 走看看