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 * 20-Apr-2006, ver 0.71
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 */
43
44#pragma D option quiet
45
46/* print header */
47dtrace:::BEGIN
48{
49	printf("Tracing... Hit Ctrl-C to end.\n");
50}
51
52/* save time at start */
53io:::wait-start
54{
55	self->start = timestamp;
56}
57
58/* process event */
59io:::wait-done
60/self->start/
61{
62	/*
63	 * wait-done is used as we are measing wait times. It also
64	 * is triggered when the correct thread is on the CPU, obviating
65	 * the need to link process details to the start event.
66	 */
67	this->elapsed = timestamp - self->start;
68	@files[pid, execname, args[2]->fi_pathname] = sum(this->elapsed);
69	self->start = 0;
70}
71
72/* print report */
73dtrace:::END
74{
75	normalize(@files, 1000);
76	printf("%6s %-12s %8s %s\n", "PID", "CMD", "TIME", "FILE");
77	printa("%6d %-12.12s %@8d %s\n", @files);
78}
79
80