USE sys DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `show_profile`(IN query_id bigint) BEGIN SELECT event_name AS stage, timer_wait / (1000 * 1000 * 1000 * 1000) AS duration FROM performance_schema.events_stages_history_long WHERE nesting_event_id = query_id ORDER BY timer_start; END ;; DELIMITER ; DELIMITER ;; CREATE DEFINER=`root`@`localhost` PROCEDURE `show_profiles`() begin SELECT event_id AS query_id, timer_wait / (1000 * 1000 * 1000 * 1000) AS duration, sys.format_statement(sql_text) AS sql_text FROM performance_schema.events_statements_history_long JOIN performance_schema.threads USING(thread_id) WHERE performance_schema.threads.processlist_id = @@pseudo_thread_id AND sql_text IS NOT NULL; end ;; DELIMITER ;