Skip to content

ps_is_instrument_default_enabled()

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

  • 参数:

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

  • 定义语句

DROP FUNCTION IF EXISTS ps_is_instrument_default_enabled;

DELIMITER $$

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

            Returns whether an instrument is enabled 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_enabled(\'statement/sql/select\');
            +--------------------------------------------------------------+
            | sys.ps_is_instrument_default_enabled(\'statement/sql/select\') |
            +--------------------------------------------------------------+
            | YES                                                          |
            +--------------------------------------------------------------+
            1 row in set (0.00 sec)
            '
    SQL SECURITY INVOKER
    DETERMINISTIC
    READS SQL DATA
BEGIN
    DECLARE v_enabled ENUM('YES', 'NO');

    -- Currently the same in all versions
    SET v_enabled = IF(in_instrument LIKE 'wait/io/file/%'
                        OR in_instrument LIKE 'wait/io/table/%'
                        OR in_instrument LIKE 'statement/%'
                        OR in_instrument LIKE 'memory/performance_schema/%'
                        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_enabled;
END$$

DELIMITER ;

上一篇: ps_is_consumer_enabled()函数 | 下一篇: ps_is_instrument_default_timed()函数

Clone this wiki locally