• mysql性能分析show profile/show profiles


    MySQL性能分析show profiles

    show profile 和 show profiles 语句可以展示当前会话(退出session后,profiling重置为0) 中执行语句的资源使用情况。

    Profiling 功能由MySQL会话变量 : profiling控制,默认是OFF.关闭状态。select @@profiling; 或者show variables like '%profi%';

    mysql> select @@profiling;
    +-------------+
    | @@profiling |
    +-------------+
    |           0 |
    +-------------+

    Profiling是针对进程(process)而非线程(threads),因此运行在服务器上的其他服务进程可能会影响分析结果。Profiling 信息收集依赖于调用 系统方法 getrusage().因此Windows系统不适用。

    开启Profiling功能:

    mysql> set profiling = 1;
    Query OK, 0 rows affected, 1 warning (0.00 sec)

    退出会话后,Profiling功能自动关闭。

    语句使用:

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

    mysql> show profiles;
    +----------+------------+-------------------------------+
    | Query_ID | Duration   | Query                         |
    +----------+------------+-------------------------------+
    |        1 | 0.00371475 | show variables like '%profi%' |
    |        2 | 0.00005700 | show prifiles                 |
    |        3 | 0.00011775 | SELECT DATABASE()             |
    |        4 | 0.00034875 | select * from student         |
    +----------+------------+-------------------------------+

    show profile: 展示最近一条语句执行的详细资源占用信息,默认显示 Status和Duration两列

    mysql> show profile;
    +----------------------+----------+
    | Status               | Duration |
    +----------------------+----------+
    | starting             | 0.000054 |
    | checking permissions | 0.000007 |
    | Opening tables       | 0.000116 |
    | init                 | 0.000019 |
    | System lock          | 0.000009 |
    | optimizing           | 0.000004 |
    | statistics           | 0.000011 |
    | preparing            | 0.000010 |
    | executing            | 0.000002 |
    | Sending data         | 0.000061 |
    | end                  | 0.000005 |
    | query end            | 0.000006 |
    | closing tables       | 0.000006 |
    | freeing items        | 0.000031 |
    | cleaning up          | 0.000010 |
    +----------------------+----------+

    show profile 还可根据 show profiles 列表中的 Query_ID ,选择显示某条记录的性能分析信息。

    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
    }

    实例:

    Examples:
    mysql> SELECT @@profiling;
    +-------------+
    | @@profiling |
    +-------------+
    |           0 |
    +-------------+
    1 row in set (0.00 sec)
    
    mysql> SET profiling = 1;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> DROP TABLE IF EXISTS t1;
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    mysql> CREATE TABLE T1 (id INT);
    Query OK, 0 rows affected (0.01 sec)
    
    mysql> SHOW PROFILES;
    +----------+----------+--------------------------+
    | Query_ID | Duration | Query                    |
    +----------+----------+--------------------------+
    |        0 | 0.000088 | SET PROFILING = 1        |
    |        1 | 0.000136 | DROP TABLE IF EXISTS t1  |
    |        2 | 0.011947 | CREATE TABLE t1 (id INT) |
    +----------+----------+--------------------------+
    3 rows in set (0.00 sec)
    
    mysql> SHOW PROFILE;
    +----------------------+----------+
    | Status               | Duration |
    +----------------------+----------+
    | checking permissions | 0.000040 |
    | creating table       | 0.000056 |
    | After create         | 0.011363 |
    | query end            | 0.000375 |
    | freeing items        | 0.000089 |
    | logging slow query   | 0.000019 |
    | cleaning up          | 0.000005 |
    +----------------------+----------+
    7 rows in set (0.00 sec)
    
    mysql> SHOW PROFILE FOR QUERY 1;
    +--------------------+----------+
    | Status             | Duration |
    +--------------------+----------+
    | query end          | 0.000107 |
    | freeing items      | 0.000008 |
    | logging slow query | 0.000015 |
    | cleaning up        | 0.000006 |
    +--------------------+----------+
    4 rows in set (0.00 sec)
    
    mysql> SHOW PROFILE CPU FOR QUERY 2;
    +----------------------+----------+----------+------------+
    | Status               | Duration | CPU_user | CPU_system |
    +----------------------+----------+----------+------------+
    | checking permissions | 0.000040 | 0.000038 |   0.000002 |
    | creating table       | 0.000056 | 0.000028 |   0.000028 |
    | After create         | 0.011363 | 0.000217 |   0.001571 |
    | query end            | 0.000375 | 0.000013 |   0.000028 |
    | freeing items        | 0.000089 | 0.000010 |   0.000014 |
    | logging slow query   | 0.000019 | 0.000009 |   0.000010 |
    | cleaning up          | 0.000005 | 0.000003 |   0.000002 |
    +----------------------+----------+----------+------------+
    7 rows in set (0.00 sec)
  • 相关阅读:
    Pod中spec的字段常用字段及含义
    day62-无名有名分组反向解析,路由分发,视图层等
    day61-数据增删改查,orm表关系,django请求生命周期流程图
    day60-静态文件,数据库,ORM
    day59-简易版本的web框架,django框架初识
    day58-jquery后续,前端BootSrtap,图书管理系统搭建
    day57-jQuery练习与操作,各种事件
    day56-js,jquery
    day55-js
    day54-js类型与对象
  • 原文地址:https://www.cnblogs.com/jkin/p/10255070.html
Copyright © 2020-2023  润新知