Skip to content

ps_is_instrument_default_timed()

xiaoboluo768 edited this page Jun 9, 2020 · 2 revisions
  • 在setup_instruments表中检查指定instruments是否启用定时器功能,默认只启用'wait/io/file/%'、'wait/io/table/%'、'statement/%'、'wait/lock/table/sql/handler'、'idle'、'stage/innodb/%'、'stage/sql/copy to tmp table'这些instruments的timed,传入参数值不匹配这些instruments即表示是指定instruments的定时器功能默认是关闭的(返回NO),如果匹配则表示指定的instruments的定时器功能默认是启用的(返回YES)

  • 参数:

    • in_instrument VARCHAR(128):要检查是否默认启用定时器功能的instruments的名称字符串
  • 返回值:一个ENUM('YES','NO')值

  • 定义语句

DROP FUNCTION IF EXISTS ps_is_instrument_default_timed;

DELIMITER $$

CREATE DEFINER='root'@'localhost' FUNCTION ps_is_instrument_default_timed (
        in_instrument VARCHAR(128)
    )
    RETURNS ENUM('YES', 'NO')
    COMMENT '
            Description
            -----------

            Returns whether an instrument is timed by default in this version of MySQL.

            Parameters
            -----------

            in_instrument VARCHAR(128): 
              The instrument to check.

            Returns
            -----------

            ENUM(\'YES\', \'NO\')

            Example
            -----------

            mysql> SELECT sys.ps_is_instrument_default_timed(\'statement/sql/select\');
            +------------------------------------------------------------+
            | sys.ps_is_instrument_default_timed(\'statement/sql/select\') |
            +------------------------------------------------------------+
            | YES                                                        |
            +------------------------------------------------------------+
            1 row in set (0.00 sec)
            '
    SQL SECURITY INVOKER
    DETERMINISTIC
    READS SQL DATA
BEGIN
    DECLARE v_timed ENUM('YES', 'NO');

    -- Currently the same in all versions
    SET v_timed = IF(in_instrument LIKE 'wait/io/file/%'
                        OR in_instrument LIKE 'wait/io/table/%'
                        OR in_instrument LIKE 'statement/%'
                        OR in_instrument IN ('wait/lock/table/sql/handler', 'idle')
              /*!50707
                        OR in_instrument LIKE 'stage/innodb/%'
                        OR in_instrument = 'stage/sql/copy to tmp table'
              */
                      ,
                      'YES',
                      'NO'
                    );

    RETURN v_timed;
END$$

DELIMITER ;

上一篇: ps_is_instrument_default_enabled()函数 | 下一篇: ps_is_thread_instrumented()函数

Clone this wiki locally