mysql performance storage engine

mysql performance storage engine

概要

  1. mysql的运行时状态记录的存储引擎,实现了PSI(Performance Storage Interface)
  2. 通过WITH_PERFSCHEMA_STORAGE_ENGINE宏来决定是否编译,启用后会自动启用HAVE_PSI_INTERFACE, 该宏会影响mysql_thread_create的行为

启动过程

# sql/mysqld.cc:mysqld_main
# 在sql/sys_vars中声明所有的mysql参数,在sys_var类型的构造函数中将这些参数注册到all_sys_vars
# 解析命令行和配置文件传入的参数,这里主要是为了解析pfs相关的参数,写入到pfs_param的成员中去
ho_error = handle_options(&remaining_argc, &remaining_argv,
                           (my_option*)(all_early_options.buffer), NULL);
if (ho_error == 0) {
    if (pfs_param.m_enabled)
        PSI_hook = initialize_performance_schema(&pfs_param);
}

if (PSI_hook) 
    # 5.5貌似只有v1
    PSI_server = (PSI*) PSI_hook->get_interface(PSI_CURRENT_VERSION)

if (PSI_server) {
    # psi 开头的key变量的值,会调用注册storage/perfschema/pfs.cc中的register_*函数注册all_server_mutexes, all_server_rwlocks, all_server_threads等变量
    init_server_psi_keys();

    PSI_thread *psi = PSI_server->new_thread(key_thread_main, NULL, 0);
    if (psi)
        PSI_server->set_thread(psi);

    my_thread_global_reinit();

    initialize_performance_schema_acl(opt_bootstrap);
    
    if (!opt_bootstrap) 
        check_performance_schema();

    initialize_information_schema_acl();

    if (PSI_server) 
        PSI_server->delete_current_thread();
}

原文地址:https://www.cnblogs.com/zhedan/p/12488104.html