-- Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved. -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by -- the Free Software Foundation; version 2 of the License. -- -- This program is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- GNU General Public License for more details. -- -- You should have received a copy of the GNU General Public License -- along with this program; if not, write to the Free Software -- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Outputs a JSON formatted stack of all statements, stages and events
within Performance Schemafor the specified thread.
Parameters -----------
thd_id (BIGINTUNSIGNED):
The id of the thread to trace. This should match the thread_id columnfrom the performance_schema.threads table.
in_verbose (BOOLEAN):
Include file:lineno information in the events.
/*!50602 -- Do not track the current thread, it will kill the stack UPDATEperformance_schema.threads SETinstrumented='NO' WHEREprocesslist_id=CONNECTION_ID();
*/
SET SESSION group_concat_max_len=@@global.max_allowed_packet;
-- Select the entire stack of events SELECT GROUP_CONCAT(CONCAT( '{'
, CONCAT_WS( ', '
, CONCAT('"nesting_event_id": "', IF(nesting_event_id ISNULL, '0', nesting_event_id), '"')
, CONCAT('"event_id": "', event_id, '"') -- Convert from picoseconds to microseconds
, CONCAT( '"timer_wait": ', ROUND(timer_wait/1000000, 2))
, CONCAT( '"event_info": "'
, CASE WHEN event_name NOTLIKE'wait/io%'THENREPLACE(SUBSTRING_INDEX(event_name, '/', -2), '\\', '\\\\') WHEN event_name NOTLIKE'wait/io/file%'OR event_name NOTLIKE'wait/io/socket%'THENREPLACE(SUBSTRING_INDEX(event_name, '/', -4), '\\', '\\\\') ELSE event_name
END
, '"'
) -- Always dump the extra wait information gathered for statements
, CONCAT( '"wait_info": "', IFNULL(wait_info, ''), '"') -- If debug is enabled, add the file:lineno information for waits
, CONCAT( '"source": "', IF(trueAND event_name LIKE'wait%', IFNULL(wait_info, ''), ''), '"') -- Depending on the type of event, name it appropriately
, CASE WHEN event_name LIKE'wait/io/file%'THEN'"event_type": "io/file"' WHEN event_name LIKE'wait/io/table%'THEN'"event_type": "io/table"' WHEN event_name LIKE'wait/io/socket%'THEN'"event_type": "io/socket"' WHEN event_name LIKE'wait/synch/mutex%'THEN'"event_type": "synch/mutex"' WHEN event_name LIKE'wait/synch/cond%'THEN'"event_type": "synch/cond"' WHEN event_name LIKE'wait/synch/rwlock%'THEN'"event_type": "synch/rwlock"' WHEN event_name LIKE'wait/lock%'THEN'"event_type": "lock"' WHEN event_name LIKE'statement/%'THEN'"event_type": "stmt"' WHEN event_name LIKE'stage/%'THEN'"event_type": "stage"' WHEN event_name LIKE'%idle%'THEN'"event_type": "idle"' ELSE''
END
)
, '}'
) ORDERBY event_id ASCSEPARATOR',') event INTO json_objects FROM ( /*!50600 -- Select all statements, with the extra tracing information available (SELECTthread_id,event_id,event_name,timer_wait,timer_start,nesting_event_id, CONCAT(sql_text,'\\n', 'errors:',errors,'\\n', 'warnings:',warnings,'\\n', 'locktime:',ROUND(lock_time/1000000,2),'us\\n', 'rowsaffected:',rows_affected,'\\n', 'rowssent:',rows_sent,'\\n', 'rowsexamined:',rows_examined,'\\n', 'tmptables:',created_tmp_tables,'\\n', 'tmpdisktables:',created_tmp_disk_tables,'\\n', 'selectscan:',select_scan,'\\n', 'selectfulljoin:',select_full_join,'\\n', 'selectfullrangejoin:',select_full_range_join,'\\n', 'selectrange:',select_range,'\\n', 'selectrangecheck:',select_range_check,'\\n', 'sortmergepasses:',sort_merge_passes,'\\n', 'sortrows:',sort_rows,'\\n', 'sortrange:',sort_range,'\\n', 'sortscan:',sort_scan,'\\n', 'noindexused:',IF(no_index_used,'TRUE','FALSE'),'\\n', 'nogoodindexused:',IF(no_good_index_used,'TRUE','FALSE'),'\\n' )ASwait_info FROMperformance_schema.events_statements_history_longWHEREthread_id=thd_id) UNION -- Select all stages (SELECTthread_id,event_id,event_name,timer_wait,timer_start,nesting_event_id,nullASwait_info FROMperformance_schema.events_stages_history_longWHEREthread_id=thd_id)
UNION */ -- Select all events, adding information appropriate to the event
(SELECT thread_id, event_id,
CONCAT(event_name , IF(event_name NOTLIKE'wait/synch/mutex%', IFNULL(CONCAT(' - ', operation), ''), ''), IF(number_of_bytes ISNOTNULL, CONCAT(' ', number_of_bytes, ' bytes'), ''), IF(event_name LIKE'wait/io/file%', '\\n', ''), IF(object_schema ISNOTNULL, CONCAT('\\nObject: ', object_schema, '.'), ''), IF(object_name ISNOTNULL, IF (event_name LIKE'wait/io/socket%', -- Print the socket if used, else the IP:port as reported
CONCAT(IF (object_name LIKE':0%', @@socket, object_name)),
object_name), ''), /*!50600 IF(index_name IS NOT NULL, CONCAT(' Index: ', index_name), ''),*/'\\n'
) AS event_name,
timer_wait, timer_start, nesting_event_id, source AS wait_info FROM performance_schema.events_waits_history_long WHERE thread_id = thd_id)) events ORDERBY event_id;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.