From c13b48ae366b9286d597a2ab216599a4610a12bb Mon Sep 17 00:00:00 2001 From: Artem Avetian Date: Thu, 25 Aug 2022 15:26:59 +0300 Subject: [PATCH] Update ps_trace_thread_57.sql --- procedures/ps_trace_thread_57.sql | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/procedures/ps_trace_thread_57.sql b/procedures/ps_trace_thread_57.sql index 313d518..8329cc8 100644 --- a/procedures/ps_trace_thread_57.sql +++ b/procedures/ps_trace_thread_57.sql @@ -108,6 +108,7 @@ CREATE DEFINER='root'@'localhost' PROCEDURE ps_trace_thread ( MODIFIES SQL DATA BEGIN DECLARE v_done bool DEFAULT FALSE; + DECLARE v_file_err bool DEFAULT FALSE; DECLARE v_start, v_runtime DECIMAL(20,2) DEFAULT 0.0; DECLARE v_min_event_id bigint unsigned DEFAULT 0; DECLARE v_this_thread_enabed ENUM('YES', 'NO'); @@ -236,6 +237,12 @@ BEGIN ) events ORDER BY event_id; DECLARE CONTINUE HANDLER FOR NOT FOUND SET v_done = TRUE; + -- Exit if file already exists + DECLARE CONTINUE HANDLER FOR 1086 + BEGIN + SET v_file_err = TRUE; + SELECT CONCAT('File \'',in_outfile,'\' already exists') AS 'Error'; + END; SET @log_bin := @@sql_log_bin; SET sql_log_bin = 0; @@ -320,9 +327,11 @@ BEGIN EXECUTE stmt_output; DEALLOCATE PREPARE stmt_output; - SELECT CONCAT('Stack trace written to ', in_outfile) AS 'Info'; - SELECT CONCAT('dot -Tpdf -o /tmp/stack_', in_thread_id, '.pdf ', in_outfile) AS 'Convert to PDF'; - SELECT CONCAT('dot -Tpng -o /tmp/stack_', in_thread_id, '.png ', in_outfile) AS 'Convert to PNG'; + IF (NOT v_file_err) THEN + SELECT CONCAT('Stack trace written to ', in_outfile) AS 'Info'; + SELECT CONCAT('dot -Tpdf -o /tmp/stack_', in_thread_id, '.pdf ', in_outfile) AS 'Convert to PDF'; + SELECT CONCAT('dot -Tpng -o /tmp/stack_', in_thread_id, '.png ', in_outfile) AS 'Convert to PNG'; + END IF; DROP TEMPORARY TABLE tmp_events; -- Reset the settings for the performance schema