public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Add traceaio example
@ 2021-09-22 14:45 Nir Soffer
  0 siblings, 0 replies; 2+ messages in thread
From: Nir Soffer @ 2021-09-22 14:45 UTC (permalink / raw)
  To: systemtap; +Cc: kwolf, wcohen, Nir Soffer

Show how to trace arguments to io_submit. This is useful to debug EINVAL
errors, for example when number of iovecs exceeds limits.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
---
 testsuite/systemtap.examples/io/traceaio.meta | 13 ++++++
 testsuite/systemtap.examples/io/traceaio.stp  | 43 ++++++++++++++++++
 testsuite/systemtap.examples/io/traceaio.txt  | 44 +++++++++++++++++++
 3 files changed, 100 insertions(+)
 create mode 100644 testsuite/systemtap.examples/io/traceaio.meta
 create mode 100755 testsuite/systemtap.examples/io/traceaio.stp
 create mode 100644 testsuite/systemtap.examples/io/traceaio.txt

diff --git a/testsuite/systemtap.examples/io/traceaio.meta b/testsuite/systemtap.examples/io/traceaio.meta
new file mode 100644
index 000000000..ea120f9be
--- /dev/null
+++ b/testsuite/systemtap.examples/io/traceaio.meta
@@ -0,0 +1,13 @@
+title: Trace calls to io_submit
+name: traceaio.stp
+version: 1.0
+author: Nir Soffer
+keywords: io
+subsystem: io
+status: production
+exit: user-controlled
+output: trace
+scope: process
+description: Trace calls to io_submit, logging iocbs and iovecs.
+test_check: stap -p4 traceaio.stp -x 1
+test_installcheck: stap traceaio.stp -x 1 -T 1
diff --git a/testsuite/systemtap.examples/io/traceaio.stp b/testsuite/systemtap.examples/io/traceaio.stp
new file mode 100755
index 000000000..126ea9c3c
--- /dev/null
+++ b/testsuite/systemtap.examples/io/traceaio.stp
@@ -0,0 +1,43 @@
+#! /usr/bin/env stap
+#
+# Copyright (C) 2021 Red Hat, Inc.
+# Written by Nir Soffer <nsoffer@redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+
+probe begin {
+    println("Tracing started");
+}
+
+probe syscall.io_submit
+{
+    if (pid() == target()) {
+        printf("[%s] io_submit(%s)\n", thread_indent(0), argstr);
+
+        for (i = 0; i < nr; i++) {
+            iocbp = user_uint64(iocbpp_uaddr + i * 8)
+            fd = user_uint32(&@cast(iocbp, "iocb", "kernel")->aio_fildes)
+            opcode = user_uint16(&@cast(iocbp, "iocb", "kernel")->aio_lio_opcode)
+            offset = user_int64(&@cast(iocbp, "iocb", "kernel")->aio_offset)
+            nbytes = user_uint64(&@cast(iocbp, "iocb", "kernel")->aio_nbytes)
+            buf = user_uint64(&@cast(iocbp, "iocb", "kernel")->aio_buf)
+            printf("    iocb[%4d]=%p, fd=%d, opcode=%d, offset=%d, nbytes=%d, buf=%p\n",
+                   i, iocbp, fd, opcode, offset, nbytes, buf)
+
+            for (j = 0; j < nbytes; j++) {
+                iovecp = &@cast(buf, "iovec", "kernel")[j]
+                base = user_uint64(&@cast(iovecp, "iovec", "kernel")->iov_base)
+                len = user_uint32(&@cast(iovecp, "iovec", "kernel")->iov_len)
+                printf("        iovec[%4d]=%p, base=%p, len=%d\n",
+                       j, iovecp, base, len)
+            }
+        }
+    }
+}
+
+probe end {
+    println("Tracing stopped");
+}
diff --git a/testsuite/systemtap.examples/io/traceaio.txt b/testsuite/systemtap.examples/io/traceaio.txt
new file mode 100644
index 000000000..1d90dc592
--- /dev/null
+++ b/testsuite/systemtap.examples/io/traceaio.txt
@@ -0,0 +1,44 @@
+traceaio.stp - Trace io_submit calls
+
+  Trace calls to io_submit(), logging iocbs and iovecs. When processing calls
+  with large number of iocbs and iovecs, you may need to increase MAXACTION.
+
+# stap -D MAXACTION=2000 traceaio.stp -x {pid}
+Tracing started
+[     0 IO iothread1(21364):] io_submit(140719456722944, 1, 0x7ffbcf8b2410)
+    iocb[   0]=0x7ffb1d9d98c0, fd=15, opcode=8, offset=0, nbytes=1, buf=0x7ffbc801b6a8
+        iovec[   0]=0x7ffbc801b6a8, base=0x7ffb4f9dc000, len=4096
+[     0 IO iothread1(21364):] io_submit(140719456722944, 1, 0x7ffbcf8b2410)
+    iocb[   0]=0x7ffb1d9d9920, fd=15, opcode=7, offset=0, nbytes=1, buf=0x7ffbc801b688
+        iovec[   0]=0x7ffbc801b688, base=0x7ffbb3d11000, len=4096
+[     0 IO iothread1(21364):] io_submit(140719456722944, 4, 0x7ffbcf8b2410)
+    iocb[   0]=0x7ffb1d9d9920, fd=15, opcode=7, offset=8192, nbytes=1, buf=0x7ffbc801b688
+        iovec[   0]=0x7ffbc801b688, base=0x7ffb9d82f000, len=4096
+    iocb[   1]=0x7ffb251dc920, fd=15, opcode=7, offset=20480, nbytes=2, buf=0x7ffbc80315f0
+        iovec[   0]=0x7ffbc80315f0, base=0x7ffbb3f69000, len=4096
+        iovec[   1]=0x7ffbc8031600, base=0x7ffb7dc48000, len=4096
+    iocb[   2]=0x7ffb19999920, fd=15, opcode=7, offset=36864, nbytes=6, buf=0x7ffbc8025320
+        iovec[   0]=0x7ffbc8025320, base=0x7ffb4f676000, len=4096
+        iovec[   1]=0x7ffbc8025330, base=0x7ffbb6f75000, len=4096
+        iovec[   2]=0x7ffbc8025340, base=0x7ffb9ddab000, len=4096
+        iovec[   3]=0x7ffbc8025350, base=0x7ffbbab7d000, len=4096
+        iovec[   4]=0x7ffbc8025360, base=0x7ffb7c3fb000, len=4096
+        iovec[   5]=0x7ffbc8025370, base=0x7ffb7cff5000, len=4096
+    iocb[   3]=0x7ffb16f6f920, fd=15, opcode=7, offset=69632, nbytes=15, buf=0x7ffbc80662b8
+        iovec[   0]=0x7ffbc80662b8, base=0x7ffbb3f44000, len=4096
+        iovec[   1]=0x7ffbc80662c8, base=0x7ffbb85cd000, len=4096
+        iovec[   2]=0x7ffbc80662d8, base=0x7ffbb81de000, len=4096
+        iovec[   3]=0x7ffbc80662e8, base=0x7ffbba3b7000, len=4096
+        iovec[   4]=0x7ffbc80662f8, base=0x7ffb7daf3000, len=4096
+        iovec[   5]=0x7ffbc8066308, base=0x7ffbb1ec3000, len=4096
+        iovec[   6]=0x7ffbc8066318, base=0x7ffbb1ece000, len=4096
+        iovec[   7]=0x7ffbc8066328, base=0x7ffb7cff7000, len=4096
+        iovec[   8]=0x7ffbc8066338, base=0x7ffb7cd60000, len=4096
+        iovec[   9]=0x7ffbc8066348, base=0x7ffbba865000, len=4096
+        iovec[  10]=0x7ffbc8066358, base=0x7ffbb80cc000, len=4096
+        iovec[  11]=0x7ffbc8066368, base=0x7ffbb826c000, len=4096
+        iovec[  12]=0x7ffbc8066378, base=0x7ffbbaa19000, len=4096
+        iovec[  13]=0x7ffbc8066388, base=0x7ffbb8230000, len=4096
+        iovec[  14]=0x7ffbc8066398, base=0x7ffbb6ed0000, len=4096
+...
+^CTracing stopped
-- 
2.31.1


^ permalink raw reply	[flat|nested] 2+ messages in thread
* [PATCH] Add traceaio example
@ 2021-09-22 15:24 Nir Soffer
  0 siblings, 0 replies; 2+ messages in thread
From: Nir Soffer @ 2021-09-22 15:24 UTC (permalink / raw)
  To: systemtap

Show how to trace arguments to io_submit. This is useful to debug EINVAL
errors, for example when number of iovecs exceeds limits.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
---
 testsuite/systemtap.examples/io/traceaio.meta | 13 ++++++
 testsuite/systemtap.examples/io/traceaio.stp  | 43 ++++++++++++++++++
 testsuite/systemtap.examples/io/traceaio.txt  | 44 +++++++++++++++++++
 3 files changed, 100 insertions(+)
 create mode 100644 testsuite/systemtap.examples/io/traceaio.meta
 create mode 100755 testsuite/systemtap.examples/io/traceaio.stp
 create mode 100644 testsuite/systemtap.examples/io/traceaio.txt

diff --git a/testsuite/systemtap.examples/io/traceaio.meta b/testsuite/systemtap.examples/io/traceaio.meta
new file mode 100644
index 000000000..ea120f9be
--- /dev/null
+++ b/testsuite/systemtap.examples/io/traceaio.meta
@@ -0,0 +1,13 @@
+title: Trace calls to io_submit
+name: traceaio.stp
+version: 1.0
+author: Nir Soffer
+keywords: io
+subsystem: io
+status: production
+exit: user-controlled
+output: trace
+scope: process
+description: Trace calls to io_submit, logging iocbs and iovecs.
+test_check: stap -p4 traceaio.stp -x 1
+test_installcheck: stap traceaio.stp -x 1 -T 1
diff --git a/testsuite/systemtap.examples/io/traceaio.stp b/testsuite/systemtap.examples/io/traceaio.stp
new file mode 100755
index 000000000..126ea9c3c
--- /dev/null
+++ b/testsuite/systemtap.examples/io/traceaio.stp
@@ -0,0 +1,43 @@
+#! /usr/bin/env stap
+#
+# Copyright (C) 2021 Red Hat, Inc.
+# Written by Nir Soffer <nsoffer@redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+
+probe begin {
+    println("Tracing started");
+}
+
+probe syscall.io_submit
+{
+    if (pid() == target()) {
+        printf("[%s] io_submit(%s)\n", thread_indent(0), argstr);
+
+        for (i = 0; i < nr; i++) {
+            iocbp = user_uint64(iocbpp_uaddr + i * 8)
+            fd = user_uint32(&@cast(iocbp, "iocb", "kernel")->aio_fildes)
+            opcode = user_uint16(&@cast(iocbp, "iocb", "kernel")->aio_lio_opcode)
+            offset = user_int64(&@cast(iocbp, "iocb", "kernel")->aio_offset)
+            nbytes = user_uint64(&@cast(iocbp, "iocb", "kernel")->aio_nbytes)
+            buf = user_uint64(&@cast(iocbp, "iocb", "kernel")->aio_buf)
+            printf("    iocb[%4d]=%p, fd=%d, opcode=%d, offset=%d, nbytes=%d, buf=%p\n",
+                   i, iocbp, fd, opcode, offset, nbytes, buf)
+
+            for (j = 0; j < nbytes; j++) {
+                iovecp = &@cast(buf, "iovec", "kernel")[j]
+                base = user_uint64(&@cast(iovecp, "iovec", "kernel")->iov_base)
+                len = user_uint32(&@cast(iovecp, "iovec", "kernel")->iov_len)
+                printf("        iovec[%4d]=%p, base=%p, len=%d\n",
+                       j, iovecp, base, len)
+            }
+        }
+    }
+}
+
+probe end {
+    println("Tracing stopped");
+}
diff --git a/testsuite/systemtap.examples/io/traceaio.txt b/testsuite/systemtap.examples/io/traceaio.txt
new file mode 100644
index 000000000..1d90dc592
--- /dev/null
+++ b/testsuite/systemtap.examples/io/traceaio.txt
@@ -0,0 +1,44 @@
+traceaio.stp - Trace io_submit calls
+
+  Trace calls to io_submit(), logging iocbs and iovecs. When processing calls
+  with large number of iocbs and iovecs, you may need to increase MAXACTION.
+
+# stap -D MAXACTION=2000 traceaio.stp -x {pid}
+Tracing started
+[     0 IO iothread1(21364):] io_submit(140719456722944, 1, 0x7ffbcf8b2410)
+    iocb[   0]=0x7ffb1d9d98c0, fd=15, opcode=8, offset=0, nbytes=1, buf=0x7ffbc801b6a8
+        iovec[   0]=0x7ffbc801b6a8, base=0x7ffb4f9dc000, len=4096
+[     0 IO iothread1(21364):] io_submit(140719456722944, 1, 0x7ffbcf8b2410)
+    iocb[   0]=0x7ffb1d9d9920, fd=15, opcode=7, offset=0, nbytes=1, buf=0x7ffbc801b688
+        iovec[   0]=0x7ffbc801b688, base=0x7ffbb3d11000, len=4096
+[     0 IO iothread1(21364):] io_submit(140719456722944, 4, 0x7ffbcf8b2410)
+    iocb[   0]=0x7ffb1d9d9920, fd=15, opcode=7, offset=8192, nbytes=1, buf=0x7ffbc801b688
+        iovec[   0]=0x7ffbc801b688, base=0x7ffb9d82f000, len=4096
+    iocb[   1]=0x7ffb251dc920, fd=15, opcode=7, offset=20480, nbytes=2, buf=0x7ffbc80315f0
+        iovec[   0]=0x7ffbc80315f0, base=0x7ffbb3f69000, len=4096
+        iovec[   1]=0x7ffbc8031600, base=0x7ffb7dc48000, len=4096
+    iocb[   2]=0x7ffb19999920, fd=15, opcode=7, offset=36864, nbytes=6, buf=0x7ffbc8025320
+        iovec[   0]=0x7ffbc8025320, base=0x7ffb4f676000, len=4096
+        iovec[   1]=0x7ffbc8025330, base=0x7ffbb6f75000, len=4096
+        iovec[   2]=0x7ffbc8025340, base=0x7ffb9ddab000, len=4096
+        iovec[   3]=0x7ffbc8025350, base=0x7ffbbab7d000, len=4096
+        iovec[   4]=0x7ffbc8025360, base=0x7ffb7c3fb000, len=4096
+        iovec[   5]=0x7ffbc8025370, base=0x7ffb7cff5000, len=4096
+    iocb[   3]=0x7ffb16f6f920, fd=15, opcode=7, offset=69632, nbytes=15, buf=0x7ffbc80662b8
+        iovec[   0]=0x7ffbc80662b8, base=0x7ffbb3f44000, len=4096
+        iovec[   1]=0x7ffbc80662c8, base=0x7ffbb85cd000, len=4096
+        iovec[   2]=0x7ffbc80662d8, base=0x7ffbb81de000, len=4096
+        iovec[   3]=0x7ffbc80662e8, base=0x7ffbba3b7000, len=4096
+        iovec[   4]=0x7ffbc80662f8, base=0x7ffb7daf3000, len=4096
+        iovec[   5]=0x7ffbc8066308, base=0x7ffbb1ec3000, len=4096
+        iovec[   6]=0x7ffbc8066318, base=0x7ffbb1ece000, len=4096
+        iovec[   7]=0x7ffbc8066328, base=0x7ffb7cff7000, len=4096
+        iovec[   8]=0x7ffbc8066338, base=0x7ffb7cd60000, len=4096
+        iovec[   9]=0x7ffbc8066348, base=0x7ffbba865000, len=4096
+        iovec[  10]=0x7ffbc8066358, base=0x7ffbb80cc000, len=4096
+        iovec[  11]=0x7ffbc8066368, base=0x7ffbb826c000, len=4096
+        iovec[  12]=0x7ffbc8066378, base=0x7ffbbaa19000, len=4096
+        iovec[  13]=0x7ffbc8066388, base=0x7ffbb8230000, len=4096
+        iovec[  14]=0x7ffbc8066398, base=0x7ffbb6ed0000, len=4096
+...
+^CTracing stopped
-- 
2.31.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-09-22 15:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-22 14:45 [PATCH] Add traceaio example Nir Soffer
2021-09-22 15:24 Nir Soffer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).