xref: /netbsd-src/external/cddl/dtracetoolkit/dist/Disk/iofile.d (revision c29d51755812ace2e87aeefdb06cb2b4dac7087a)
1 #!/usr/sbin/dtrace -s
2 /*
3  * iofile.d - I/O wait time by filename and process.
4  *            Written using DTrace (Solaris 10 3/05).
5  *
6  * This prints the total I/O wait times for each filename by process.
7  * This can help determine why an application is performing poorly by
8  * identifying which file they are waiting on, and the total times.
9  * Both disk and NFS I/O are measured.
10  *
11  * $Id: iofile.d,v 1.1.1.1 2015/09/30 22:01:07 christos Exp $
12  *
13  * USAGE:	iofile.d	# wait, then hit Ctrl-C to end
14  *
15  * FIELDS:
16  *		PID		Process ID
17  *		CMD		Process name
18  *		TIME		Total wait time for disk events, us
19  *		FILE		File pathname
20  *
21  * BASED ON: /usr/demo/dtrace/iocpu.d
22  *
23  * SEE ALSO: iosnoop, iotop
24  *
25  * PORTIONS: Copyright (c) 2005, 2006 Brendan Gregg.
26  *
27  * CDDL HEADER START
28  *
29  *  The contents of this file are subject to the terms of the
30  *  Common Development and Distribution License, Version 1.0 only
31  *  (the "License").  You may not use this file except in compliance
32  *  with the License.
33  *
34  *  You can obtain a copy of the license at Docs/cddl1.txt
35  *  or http://www.opensolaris.org/os/licensing.
36  *  See the License for the specific language governing permissions
37  *  and limitations under the License.
38  *
39  * CDDL HEADER END
40  *
41  * 24-Jul-2005	Brendan Gregg	Created this.
42  * 20-Apr-2006	   "      "	Last update.
43  */
44 
45 #pragma D option quiet
46 
47 /* print header */
48 dtrace:::BEGIN
49 {
50 	printf("Tracing... Hit Ctrl-C to end.\n");
51 }
52 
53 /* save time at start */
54 io:::wait-start
55 {
56 	self->start = timestamp;
57 }
58 
59 /* process event */
60 io:::wait-done
61 /self->start/
62 {
63 	/*
64 	 * wait-done is used as we are measing wait times. It also
65 	 * is triggered when the correct thread is on the CPU, obviating
66 	 * the need to link process details to the start event.
67 	 */
68 	this->elapsed = timestamp - self->start;
69 	@files[pid, execname, args[2]->fi_pathname] = sum(this->elapsed);
70 	self->start = 0;
71 }
72 
73 /* print report */
74 dtrace:::END
75 {
76 	normalize(@files, 1000);
77 	printf("%6s %-12s %8s %s\n", "PID", "CMD", "TIME", "FILE");
78 	printa("%6d %-12.12s %@8d %s\n", @files);
79 }
80