1 #!/usr/sbin/dtrace -s 2 /* 3 Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed with certain software (including 10 but not limited to OpenSSL) that is licensed under separate terms, 11 as designated in a particular file or component or in included license 12 documentation. The authors of MySQL hereby grant you an additional 13 permission to link the program and your derivative works with the 14 separately licensed software that they have included with MySQL. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License, version 2.0, for more details. 20 21 You should have received a copy of the GNU General Public License 22 along with this program; if not, write to the Free Software 23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 */ 25 26 /* 27 Creates a report on each query executed at the individual statement 28 level, showing rows matched, updated, and total query time 29 */ 30 31 #pragma D option quiet 32 33 dtrace:::BEGIN 34 { 35 printf("%-60s %-8s %-8s %-8s\n", "Query", "RowsU", "RowsM", "Dur (ms)"); 36 } 37 38 mysql*:::update-start, mysql*:::insert-start, 39 mysql*:::delete-start, mysql*:::multi-delete-start, 40 mysql*:::multi-delete-done, mysql*:::select-start, 41 mysql*:::insert-select-start, mysql*:::multi-update-start 42 { 43 self->query = copyinstr(arg0); 44 self->querystart = timestamp; 45 } 46 47 mysql*:::insert-done, mysql*:::select-done, 48 mysql*:::delete-done, mysql*:::multi-delete-done, mysql*:::insert-select-done 49 / self->querystart / 50 { 51 this->elapsed = ((timestamp - self->querystart)/1000000); 52 printf("%-60s %-8d %-8d %d\n", 53 self->query, 54 0, 55 arg1, 56 this->elapsed); 57 self->querystart = 0; 58 } 59 60 mysql*:::update-done, mysql*:::multi-update-done 61 / self->querystart / 62 { 63 this->elapsed = ((timestamp - self->querystart)/1000000); 64 printf("%-60s %-8d %-8d %d\n", 65 self->query, 66 arg1, 67 arg2, 68 this->elapsed); 69 self->querystart = 0; 70 } 71