diff --git a/include/mysql/components/services/bits/psi_thread_bits.h b/include/mysql/components/services/bits/psi_thread_bits.h index 57f50d890cab..21e22e44c120 100644 --- a/include/mysql/components/services/bits/psi_thread_bits.h +++ b/include/mysql/components/services/bits/psi_thread_bits.h @@ -636,6 +636,40 @@ typedef int (*get_thread_held_locks_v1_t)(PSI_thread *thread, const char **held_lock_names, int max_count); +/** + Record start of delay before first quantum. + + @param thread the thread instrumentation + @param delay_start Delay start timestamp in ns. +*/ +typedef void (*thread_start_delay_v1_t)(PSI_thread *thread, + int64_t delay_start); + +/** + Record start of quantum and end of delay between quantums. + + @param thread the thread instrumentation + @param quantum_start Delay start timestamp in ns. +*/ +typedef void (*thread_start_quantum_v1_t)(PSI_thread *thread, + int64_t quantum_start); + +/** + Record end of quantum and start of delay between quantums. + + @param thread the thread instrumentation + @param quantum_end Delay start timestamp in ns. +*/ +typedef void (*thread_end_quantum_v1_t)(PSI_thread *thread, + int64_t quantum_end); + +/** + Reset CPU stats at the end of query. + + @param thread the thread instrumentation +*/ +typedef void (*thread_reset_cpu_stats_v1_t)(PSI_thread *thread); + typedef struct PSI_thread_info_v5 PSI_thread_info; typedef void (*thread_detect_telemetry_v7_t)(PSI_thread *thread); diff --git a/include/mysql/components/services/psi_thread_service.h b/include/mysql/components/services/psi_thread_service.h index 52f58bcd5e7c..a64d05170c55 100644 --- a/include/mysql/components/services/psi_thread_service.h +++ b/include/mysql/components/services/psi_thread_service.h @@ -225,6 +225,8 @@ END_SERVICE_DEFINITION(psi_thread_v5) Status: deprecated, use version 7 instead. Changes compared to version 5: - added set_thread_secondary_engine + - added thread_start_delay, thread_start_quantum, thread_end_quantum, + thread_reset_cpu_stats */ BEGIN_SERVICE_DEFINITION(psi_thread_v6) @@ -302,6 +304,16 @@ notify_session_connect_v1_t notify_session_connect; notify_session_disconnect_v1_t notify_session_disconnect; /** @sa notify_session_change_user_v1_t. */ notify_session_change_user_v1_t notify_session_change_user; +/** @sa get_thread_held_locks_v1_t. */ +get_thread_held_locks_v1_t get_thread_held_locks; +/** @sa thread_start_delay_v1_t. */ +thread_start_delay_v1_t thread_start_delay; +/** @sa thread_start_quantum_v1_t. */ +thread_start_quantum_v1_t thread_start_quantum; +/** @sa thread_end_quantum_v1_t. */ +thread_end_quantum_v1_t thread_end_quantum; +/** @sa thread_reset_cpu_stats_v1_t. */ +thread_reset_cpu_stats_v1_t thread_reset_cpu_stats; END_SERVICE_DEFINITION(psi_thread_v6) /* diff --git a/include/mysql/psi/psi_abi_thread_v1.h.pp b/include/mysql/psi/psi_abi_thread_v1.h.pp index 275dad28a4c4..57f08871aee3 100644 --- a/include/mysql/psi/psi_abi_thread_v1.h.pp +++ b/include/mysql/psi/psi_abi_thread_v1.h.pp @@ -171,6 +171,13 @@ typedef int (*get_thread_held_locks_v1_t)(PSI_thread *thread, const char **held_lock_names, int max_count); +typedef void (*thread_start_delay_v1_t)(PSI_thread *thread, + int64_t delay_start); +typedef void (*thread_start_quantum_v1_t)(PSI_thread *thread, + int64_t quantum_start); +typedef void (*thread_end_quantum_v1_t)(PSI_thread *thread, + int64_t quantum_end); +typedef void (*thread_reset_cpu_stats_v1_t)(PSI_thread *thread); typedef struct PSI_thread_info_v5 PSI_thread_info; typedef void (*thread_detect_telemetry_v7_t)(PSI_thread *thread); typedef void (*thread_abort_telemetry_v7_t)(PSI_thread *thread); @@ -303,6 +310,10 @@ notify_session_change_user_v1_t notify_session_change_user; set_mem_cnt_THD_v1_t set_mem_cnt_THD; get_thread_held_locks_v1_t get_thread_held_locks; + thread_start_delay_v1_t thread_start_delay; + thread_start_quantum_v1_t thread_start_quantum; + thread_end_quantum_v1_t thread_end_quantum; + thread_reset_cpu_stats_v1_t thread_reset_cpu_stats; }; struct PSI_thread_service_v7 { register_thread_v5_t register_thread; @@ -348,6 +359,10 @@ thread_detect_telemetry_v7_t detect_telemetry; thread_abort_telemetry_v7_t abort_telemetry; get_thread_held_locks_v1_t get_thread_held_locks; + thread_start_delay_v1_t thread_start_delay; + thread_start_quantum_v1_t thread_start_quantum; + thread_end_quantum_v1_t thread_end_quantum; + thread_reset_cpu_stats_v1_t thread_reset_cpu_stats; }; typedef struct PSI_thread_service_v7 PSI_thread_service_t; extern PSI_thread_service_t *psi_thread_service; diff --git a/include/mysql/psi/psi_thread.h b/include/mysql/psi/psi_thread.h index 185ca1411f84..cc573374a578 100644 --- a/include/mysql/psi/psi_thread.h +++ b/include/mysql/psi/psi_thread.h @@ -304,6 +304,8 @@ struct PSI_thread_service_v5 { @since PSI_THREAD_VERSION_6 Changes from version 5: - added set_thread_secondary_engine + - added thread_start_delay, thread_start_quantum, thread_end_quantum, + thread_reset_cpu_stats */ struct PSI_thread_service_v6 { /** @sa register_thread_v5_t. */ @@ -388,6 +390,14 @@ struct PSI_thread_service_v6 { set_mem_cnt_THD_v1_t set_mem_cnt_THD; /** @sa get_thread_held_locks_v1_t. */ get_thread_held_locks_v1_t get_thread_held_locks; + /** @sa thread_start_delay_v1_t. */ + thread_start_delay_v1_t thread_start_delay; + /** @sa thread_start_quantum_v1_t. */ + thread_start_quantum_v1_t thread_start_quantum; + /** @sa thread_end_quantum_v1_t. */ + thread_end_quantum_v1_t thread_end_quantum; + /** @sa thread_reset_cpu_stats_v1_t. */ + thread_reset_cpu_stats_v1_t thread_reset_cpu_stats; }; /** @@ -480,8 +490,17 @@ struct PSI_thread_service_v7 { thread_detect_telemetry_v7_t detect_telemetry; thread_abort_telemetry_v7_t abort_telemetry; + /** @sa get_thread_held_locks_v1_t. */ get_thread_held_locks_v1_t get_thread_held_locks; + /** @sa thread_start_delay_v1_t. */ + thread_start_delay_v1_t thread_start_delay; + /** @sa thread_start_quantum_v1_t. */ + thread_start_quantum_v1_t thread_start_quantum; + /** @sa thread_end_quantum_v1_t. */ + thread_end_quantum_v1_t thread_end_quantum; + /** @sa thread_reset_cpu_stats_v1_t. */ + thread_reset_cpu_stats_v1_t thread_reset_cpu_stats; }; typedef struct PSI_thread_service_v7 PSI_thread_service_t; diff --git a/include/pfs_thread_provider.h b/include/pfs_thread_provider.h index 93774be31ac9..db36d7e4fc91 100644 --- a/include/pfs_thread_provider.h +++ b/include/pfs_thread_provider.h @@ -164,6 +164,14 @@ void pfs_abort_telemetry_vc(PSI_thread *thread); int pfs_get_thread_held_locks_vc(PSI_thread *thread, const char **held_lock_names, int max_count); +void pfs_thread_start_delay_vc(PSI_thread *thread, int64_t delay_start); + +void pfs_thread_start_quantum_vc(PSI_thread *thread, int64_t quantum_start); + +void pfs_thread_end_quantum_vc(PSI_thread *thread, int64_t quantum_end); + +void pfs_thread_reset_cpu_stats_vc(PSI_thread *thread); + #endif /* WITH_LOCK_ORDER */ #endif /* MYSQL_DYNAMIC_PLUGIN */ #endif /* MYSQL_SERVER || PFS_DIRECT_CALL */ diff --git a/mysql-test/r/dd_upgrade_test.result b/mysql-test/r/dd_upgrade_test.result index 7f13bdf083d5..085ac14bca8f 100644 --- a/mysql-test/r/dd_upgrade_test.result +++ b/mysql-test/r/dd_upgrade_test.result @@ -467,6 +467,8 @@ threads CREATE TABLE `threads` ( `MAX_TOTAL_MEMORY` bigint unsigned NOT NULL, `TELEMETRY_ACTIVE` enum('YES','NO') NOT NULL, `THREAD_PRIORITY` int DEFAULT NULL, + `CPU_USAGE` time(6) DEFAULT NULL, + `DELAY_TOTAL` time(6) DEFAULT NULL, PRIMARY KEY (`THREAD_ID`), KEY `PROCESSLIST_ID` (`PROCESSLIST_ID`), KEY `THREAD_OS_ID` (`THREAD_OS_ID`), diff --git a/mysql-test/suite/perfschema/include/processlist_load.inc b/mysql-test/suite/perfschema/include/processlist_load.inc index 35d09b07a3e3..84be476009e4 100644 --- a/mysql-test/suite/perfschema/include/processlist_load.inc +++ b/mysql-test/suite/perfschema/include/processlist_load.inc @@ -26,7 +26,7 @@ SHOW FULL PROCESSLIST; --echo --echo # Performance Schema processlist table --echo ---replace_column 1 3 6