1269765Sjmg#!/usr/sbin/dtrace -s
2269765Sjmg/*-
3269765Sjmg * Copyright 2014 John-Mark Gurney.
4269765Sjmg * All rights reserved.
5269765Sjmg *
6269765Sjmg * Redistribution and use in source and binary forms, with or without
7269765Sjmg * modification, are permitted provided that the following conditions
8269765Sjmg * are met:
9269765Sjmg * 1. Redistributions of source code must retain the above copyright
10269765Sjmg *    notice, this list of conditions and the following disclaimer.
11269765Sjmg * 2. Redistributions in binary form must reproduce the above copyright
12269765Sjmg *    notice, this list of conditions and the following disclaimer in the
13269765Sjmg *    documentation and/or other materials provided with the distribution.
14269765Sjmg *
15269765Sjmg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16269765Sjmg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17269765Sjmg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18269765Sjmg * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19269765Sjmg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20269765Sjmg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21269765Sjmg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22269765Sjmg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23269765Sjmg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24269765Sjmg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25269765Sjmg * SUCH DAMAGE.
26269765Sjmg *
27269765Sjmg *	$FreeBSD: releng/11.0/share/dtrace/disklatencycmd 269765 2014-08-09 20:40:03Z jmg $
28269765Sjmg *
29269765Sjmg */
30269765Sjmg
31269765Sjmg#pragma D option quiet
32269765Sjmg
33269765Sjmg/* from http://www.mail-archive.com/dtrace-discuss@opensolaris.org/msg03755.html */
34269765Sjmg#pragma D option aggsize=8m
35269765Sjmg#pragma D option bufsize=16m
36269765Sjmg#pragma D option dynvarsize=32m
37269765Sjmg/*
38269765Sjmg#pragma D option aggrate=0
39269765Sjmg#pragma D option cleanrate=50Hz
40269765Sjmg*/
41269765Sjmg
42269765Sjmgdtrace:::BEGIN
43269765Sjmg{
44269765Sjmg	printf("Tracing... Hit Ctrl-C to end.\n");
45269765Sjmg	dstart = timestamp;
46269765Sjmg}
47269765Sjmg
48269765Sjmgio:::start
49269765Sjmg{
50269765Sjmg	start_time[arg0] = timestamp;
51269765Sjmg}
52269765Sjmg
53269765Sjmgio:::done
54269765Sjmg/this->start = start_time[arg0]/
55269765Sjmg{
56269765Sjmg	this->delta = (timestamp - this->start) / 1000;
57269765Sjmg	@q[args[1]->device_name, args[1]->unit_number] =
58269765Sjmg	    lquantize(this->delta, 4000, 80000, 4000);
59269765Sjmg	@max[args[1]->device_name, args[1]->unit_number] = max(this->delta);
60269765Sjmg	@avg[args[1]->device_name, args[1]->unit_number] = avg(this->delta);
61269765Sjmg	@stddev[args[1]->device_name, args[1]->unit_number] = stddev(this->delta);
62269765Sjmg	start_time[arg0] = 0;
63269765Sjmg}
64269765Sjmg
65269765Sjmgdtrace:::END
66269765Sjmg{
67269765Sjmg	printf("total time, us: %d\n", (timestamp - dstart) / 1000);
68269765Sjmg	printa("   %s (%d), us:\n%@d\n", @q);
69269765Sjmg	printa("max%s (%d), us: %@d\n", @max);
70269765Sjmg	printa("avg%s (%d), us: %@d\n", @avg);
71269765Sjmg	printa("stddev%s (%d), us: %@d\n", @stddev);
72269765Sjmg}
73