Permalink
Browse files

some mysql scripts

  • Loading branch information...
1 parent d9eb765 commit 52c72bbf33a96d1fad418c7a0261a037123a580b Brendan Gregg committed Aug 13, 2012
View
@@ -0,0 +1,9 @@
+MySQL Scripts
+
+mysql_pid_*.d scripts that use the pid provider to trace a single
+ mysqld instance.
+
+mysql_*.d scripts that use the mysql provider probes (if available)
+ to trace all runinng mysqlds.
+
+innodb_*.d trace innodb internals using the pid provider.
@@ -0,0 +1,88 @@
+#!/usr/sbin/dtrace -s
+/*
+ * innodb_pid_iolatency.d Show storage latency distribution.
+ *
+ * USAGE: ./innodb_pid_iolatency.d -p mysqld_PID [interval]
+ *
+ * This traces innodb at the OS interface: os_file_read() and os_file_write().
+ * This includes back-end query I/O, but not other types including log I/O.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at http://smartos.org/CDDL
+ *
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file.
+ *
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Copyright (c) 2012 Joyent Inc., All rights reserved.
+ * Copyright (c) 2012 Brendan Gregg, All rights reserved.
+ *
+ * TESTED: these pid-provider probes may only work on some mysqld versions.
+ * 5.0.51a: ok
+ *
+ * SEE ALSO: innodb_pid_ioslow.d
+ */
+
+#pragma D option quiet
+#pragma D option defaultargs
+#pragma D option bufsize=32k
+
+dtrace:::BEGIN
+{
+ printf("Tracing PID %d... Hit Ctrl-C to end.\n", $target);
+ interval = $1 ? $1 : 1;
+ secs = interval;
+}
+
+pid$target::*os_file_read*:entry,
+pid$target::*os_file_write*:entry
+{
+ self->start = timestamp;
+}
+
+pid$target::*os_file_read*:return { this->dir = "read"; }
+pid$target::*os_file_write*:return { this->dir = "write"; }
+
+pid$target::*os_file_read*:return,
+pid$target::*os_file_write*:return
+/self->start/
+{
+ @time[this->dir] = quantize(timestamp - self->start);
+ @num = count();
+ self->start = 0;
+}
+
+profile:::tick-1s
+{
+ secs--;
+}
+
+profile:::tick-1s
+/secs == 0/
+{
+ normalize(@num, interval);
+ printa("\ninnodb IOPS: %@d; storage latency by direction (ns):",
+ @num);
+ printa(@time);
+ clear(@time); clear(@num);
+ secs = interval;
+}
+
+dtrace:::END
+{
+ trunc(@time); trunc(@num);
+}
View
@@ -0,0 +1,100 @@
+#!/usr/sbin/dtrace -s
+/*
+ * innodb_pid_ioslow.d Trace slow innodb storage I/O.
+ *
+ * USAGE: ./innodb_pid_ioslow.d -p mysqld_PID [interval]
+ *
+ * This traces innodb at the OS interface: os_file_read() and os_file_write().
+ * This includes back-end query I/O, but not other types including log I/O.
+ *
+ * This may be easier (albiet more inclusive) to measure at the VFS/ZFS
+ * interface. That would require the fbt provider, which isn't available
+ * in zones.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at http://smartos.org/CDDL
+ *
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file.
+ *
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Copyright (c) 2012 Joyent Inc., All rights reserved.
+ * Copyright (c) 2012 Brendan Gregg, All rights reserved.
+ *
+ * TESTED: these pid-provider probes may only work on some mysqld versions.
+ * 5.0.51a: ok
+ *
+ * SEE ALSO: innodb_pid_latency.d
+ */
+
+#pragma D option quiet
+#pragma D option defaultargs
+#pragma D option bufsize=128k
+
+dtrace:::BEGIN
+/$1 == 0/
+{
+ printf("USAGE: %s -p PID min_ms\n\n", $$0);
+ printf("\teg: %s -p 12345 100\n", $$0);
+ exit(1);
+}
+
+dtrace:::BEGIN
+{
+ min_ns = $1 * 1000000;
+ printf("Tracing... Min query time: %d ms. ", $1);
+ printf("TIME & CPU are in ms.\n\n");
+ printf(" %-4s %-4s %-7s %s\n", "TIME", "CPU", "SIZE(b)", "PATH");
+}
+
+pid$target::*os_file_read*:entry,
+pid$target::*os_file_write*:entry
+{
+ self->start = timestamp;
+ self->vstart = vtimestamp;
+}
+
+syscall::*read*:entry,syscall::*write*:entry
+/self->start/
+{
+ /* easier to fetch them now than from the C++ args */
+ self->fd = arg0 + 1;
+ self->bytes = arg2;
+}
+
+pid$target::*os_file_read*:return { this->dir = "R"; }
+pid$target::*os_file_write*:return { this->dir = "W"; }
+
+pid$target::*os_file_read*:return,
+pid$target::*os_file_write*:return
+/self->start && (timestamp - self->start) > min_ns/
+{
+ this->time = (timestamp - self->start) / 1000000;
+ this->vtime = (vtimestamp - self->vstart) / 1000000;
+ printf(" %-4d %-4d %-7d %s\n", this->time, this->vtime,
+ self->bytes, self->fd ? fds[self->fd - 1].fi_pathname : "");
+}
+
+pid$target::*os_file_read*:return,
+pid$target::*os_file_write*:return
+/self->start/
+{
+ self->start = 0;
+ self->vstart = 0;
+ self->fd = 0;
+ self->bytes = 0;
+}
@@ -0,0 +1,67 @@
+#!/usr/sbin/dtrace -s
+/*
+ * innodb_thread_concurrency.d measure thread concurrency sleeps
+ *
+ * USAGE: ./innodb_thread_concurrency.d -p mysqld_PID
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at http://smartos.org/CDDL
+ *
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file.
+ *
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Copyright (c) 2012 Joyent Inc., All rights reserved.
+ * Copyright (c) 2012 Brendan Gregg, All rights reserved.
+ *
+ * TESTED: these pid-provider probes may only work on some mysqld versions.
+ * 5.0.51a: ok
+ */
+
+pid$target::srv_conc_enter_innodb:entry
+{
+ self->srv = 1;
+}
+
+pid$target::os_thread_sleep:entry
+/self->srv/
+{
+ @["innodb srv sleep (ns)"] = quantize(arg0 * 1000);
+}
+
+pid$target::srv_conc_enter_innodb:return
+{
+ self->srv = 0;
+}
+
+pid$target::*dispatch_command*:entry
+{
+ self->start = timestamp;
+}
+
+pid$target::*dispatch_command*:return
+/self->start/
+{
+ @["query time (ns)"] = quantize(timestamp - self->start);
+ self->start = 0;
+}
+
+profile:::tick-1s
+{
+ printa(@);
+ trunc(@);
+}
@@ -0,0 +1,56 @@
+#!/usr/sbin/dtrace -s
+/*
+ * libmysql_pid_connect.d Trace MySQL connect latency.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at http://smartos.org/CDDL
+ *
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file.
+ *
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Copyright (c) 2012 Joyent Inc., All rights reserved.
+ * Copyright (c) 2012 Brendan Gregg, All rights reserved.
+ */
+
+#pragma D option quiet
+#pragma D option switchrate=10hz
+
+dtrace:::BEGIN
+{
+ printf("%-20s %16s %12s %6s %8s\n", "TIME", "HOST", "DB", "PORT", "LAT");
+}
+
+pid$target::mysql_real_connect:entry
+{
+ self->host = arg1 ? copyinstr(arg1) : "<null>";
+ self->db = arg4 ? copyinstr(arg4) : "<null>";
+ self->port = arg5;
+ self->start = timestamp;
+}
+
+pid$target::mysql_real_connect:return
+/self->start/
+{
+ this->delta = timestamp - self->start;
+ printf("%-20Y %16s %12s %6d %8d ms\n", walltimestamp,
+ self->host, self->db, self->port, this->delta / 1000000);
+ self->host = 0;
+ self->db = 0;
+ self->port = 0;
+ self->start = 0;
+}
View
@@ -0,0 +1,58 @@
+#!/usr/sbin/dtrace -Zs
+/*
+ * libmysql_pid_qtime.d Summarize MySQL client query latency.
+ *
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at http://smartos.org/CDDL
+ *
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file.
+ *
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ * Copyright (c) 2012 Joyent Inc., All rights reserved.
+ * Copyright (c) 2012 Brendan Gregg, All rights reserved.
+ */
+
+#pragma D option quiet
+
+dtrace:::BEGIN
+{
+ printf("Tracing... Hit Ctrl-C for report.\n");
+}
+
+pid$target::mysql_query:entry,
+pid$target::mysql_real_query:entry
+{
+ self->start = timestamp;
+}
+
+pid$target::mysql_query:return,
+pid$target::mysql_real_query:return
+/self->start/
+{
+ this->time = timestamp - self->start;
+ @["query time (ns)"] = quantize(this->time);
+ @a["average (ms)"] = avg(this->time);
+ self->start = 0;
+}
+
+dtrace:::END
+{
+ normalize(@a, 1000000);
+ printa(@);
+ printa(@a);
+}
Oops, something went wrong.

0 comments on commit 52c72bb

Please sign in to comment.