xref: /illumos-gate/usr/src/test/zfs-tests/tests/perf/scripts/io.d (revision 8c69cc8fbe729fa7b091e901c4b50508ccc6bb33)
1 #!/usr/sbin/dtrace -s
2 
3 /*
4  * This file and its contents are supplied under the terms of the
5  * Common Development and Distribution License ("CDDL"), version 1.0.
6  * You may only use this file in accordance with the terms of version
7  * 1.0 of the CDDL.
8  *
9  * A full copy of the text of the CDDL should have accompanied this
10  * source.  A copy of the CDDL is also available via the Internet at
11  * http://www.illumos.org/license/CDDL.
12  */
13 
14 /*
15  * Copyright (c) 2013, 2015 by Delphix. All rights reserved.
16  */
17 
18 /*
19  * time: Seconds since the epoch
20  * @ops: The number of reads and writes per interval
21  * @bytes: Bytes read and written per interval
22  * @latencies: Mean read and write latency per interval in ns
23  *   These aggregations are indexed with read/write for back end
24  *   statistics and zfs_read/zfs_write for ZPL level statistics.
25  */
26 
27 #pragma D option aggsortkey
28 #pragma D option quiet
29 
30 BEGIN
31 {
32 	@ops["read"] = count();
33 	@ops["write"] = count();
34 	@ops["zfs_read"] = count();
35 	@ops["zfs_write"] = count();
36 	@latencies["read"] = avg(0);
37 	@latencies["write"] = avg(0);
38 	@latencies["zfs_read"] = avg(0);
39 	@latencies["zfs_write"] = avg(0);
40 	@bytes["read"] = sum(0);
41 	@bytes["write"] = sum(0);
42 	@bytes["zfs_read"] = sum(0);
43 	@bytes["zfs_write"] = sum(0);
44 	clear(@ops);
45 	clear(@latencies);
46 	clear(@bytes);
47 }
48 
49 fbt:zfs:zfs_read:entry,
50 fbt:zfs:zfs_write:entry
51 {
52 	this->zp = (znode_t *)args[0]->v_data;
53 	this->poolname = stringof(this->zp->z_zfsvfs->z_os->os_spa->spa_name);
54 }
55 
56 fbt:zfs:zfs_read:entry,
57 fbt:zfs:zfs_write:entry
58 / this->poolname == $$1 /
59 {
60 	self->ts = timestamp;
61 	@ops[probefunc] = count();
62 	@bytes[probefunc] = sum(args[1]->uio_resid);
63 }
64 
65 fbt:zfs:zfs_read:return,
66 fbt:zfs:zfs_write:return
67 / self->ts != 0 /
68 {
69 	@latencies[probefunc] = avg(timestamp - self->ts);
70 	self->ts = 0;
71 }
72 
73 io:::start
74 / strstr($$2, args[1]->dev_statname) != NULL /
75 {
76 	start[args[0]->b_edev, args[0]->b_blkno] = timestamp;
77 }
78 
79 io:::done
80 / start[args[0]->b_edev, args[0]->b_blkno] /
81 {
82 	this->elapsed = timestamp - start[args[0]->b_edev, args[0]->b_blkno];
83 	this->name = args[0]->b_flags & B_READ ? "read" : "write";
84 	@ops[this->name] = count();
85 	@bytes[this->name] = sum(args[0]->b_bcount);
86 	@latencies[this->name] = avg(this->elapsed);
87 	start[args[0]->b_edev, args[0]->b_blkno] = 0;
88 }
89 
90 tick-$3s
91 {
92 	printf("%u\n", `time);
93 	printa("ops_%-21s%@u\n", @ops);
94 	printa("bytes_%-21s%@u\n", @bytes);
95 	printa("latencies_%-21s%@u\n", @latencies);
96 
97 	clear(@ops);
98 	clear(@bytes);
99 	clear(@latencies);
100 }
101 
102 ERROR
103 {
104 	trace(arg1);
105 	trace(arg2);
106 	trace(arg3);
107 	trace(arg4);
108 	trace(arg5);
109 }
110