xref: /freebsd/share/dtrace/disklatency (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
1*1a457459SJohn-Mark Gurney#!/usr/sbin/dtrace -s
2*1a457459SJohn-Mark Gurney/*-
3*1a457459SJohn-Mark Gurney * Copyright 2014 John-Mark Gurney.
4*1a457459SJohn-Mark Gurney * All rights reserved.
5*1a457459SJohn-Mark Gurney *
6*1a457459SJohn-Mark Gurney * Redistribution and use in source and binary forms, with or without
7*1a457459SJohn-Mark Gurney * modification, are permitted provided that the following conditions
8*1a457459SJohn-Mark Gurney * are met:
9*1a457459SJohn-Mark Gurney * 1. Redistributions of source code must retain the above copyright
10*1a457459SJohn-Mark Gurney *    notice, this list of conditions and the following disclaimer.
11*1a457459SJohn-Mark Gurney * 2. Redistributions in binary form must reproduce the above copyright
12*1a457459SJohn-Mark Gurney *    notice, this list of conditions and the following disclaimer in the
13*1a457459SJohn-Mark Gurney *    documentation and/or other materials provided with the distribution.
14*1a457459SJohn-Mark Gurney *
15*1a457459SJohn-Mark Gurney * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*1a457459SJohn-Mark Gurney * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*1a457459SJohn-Mark Gurney * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*1a457459SJohn-Mark Gurney * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*1a457459SJohn-Mark Gurney * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*1a457459SJohn-Mark Gurney * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*1a457459SJohn-Mark Gurney * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*1a457459SJohn-Mark Gurney * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*1a457459SJohn-Mark Gurney * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*1a457459SJohn-Mark Gurney * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*1a457459SJohn-Mark Gurney * SUCH DAMAGE.
26*1a457459SJohn-Mark Gurney *
27*1a457459SJohn-Mark Gurney */
28*1a457459SJohn-Mark Gurney
29*1a457459SJohn-Mark Gurney#pragma D option quiet
30*1a457459SJohn-Mark Gurney#pragma D option dynvarsize=16m
31*1a457459SJohn-Mark Gurney
32*1a457459SJohn-Mark Gurneydtrace:::BEGIN
33*1a457459SJohn-Mark Gurney{
34*1a457459SJohn-Mark Gurney	printf("Tracing... Hit Ctrl-C to end.\n");
35*1a457459SJohn-Mark Gurney}
36*1a457459SJohn-Mark Gurney
37*1a457459SJohn-Mark Gurneyio:::start
38*1a457459SJohn-Mark Gurney{
39*1a457459SJohn-Mark Gurney	start_time[arg0] = timestamp;
40*1a457459SJohn-Mark Gurney}
41*1a457459SJohn-Mark Gurney
42*1a457459SJohn-Mark Gurneyio:::done
43*1a457459SJohn-Mark Gurney/this->start = start_time[arg0]/
44*1a457459SJohn-Mark Gurney{
45*1a457459SJohn-Mark Gurney	this->delta = (timestamp - this->start) / 1000;
46*1a457459SJohn-Mark Gurney	@q[args[1]->device_name, args[1]->unit_number] =
47*1a457459SJohn-Mark Gurney	    lquantize(this->delta, 4000, 80000, 4000);
48*1a457459SJohn-Mark Gurney	@max[args[1]->device_name, args[1]->unit_number] = max(this->delta);
49*1a457459SJohn-Mark Gurney	@avg[args[1]->device_name, args[1]->unit_number] = avg(this->delta);
50*1a457459SJohn-Mark Gurney	@stddev[args[1]->device_name, args[1]->unit_number] = stddev(this->delta);
51*1a457459SJohn-Mark Gurney	start_time[arg0] = 0;
52*1a457459SJohn-Mark Gurney}
53*1a457459SJohn-Mark Gurney
54*1a457459SJohn-Mark Gurneytick-10s
55*1a457459SJohn-Mark Gurney{
56*1a457459SJohn-Mark Gurney	printa("   %s (%d), us:\n%@d\n", @q);
57*1a457459SJohn-Mark Gurney	printa("max%s (%d), us:\n%@d\n", @max);
58*1a457459SJohn-Mark Gurney	printa("avg%s (%d), us:\n%@d\n", @avg);
59*1a457459SJohn-Mark Gurney	printa("stddev%s (%d), us:\n%@d\n", @stddev);
60*1a457459SJohn-Mark Gurney
61*1a457459SJohn-Mark Gurney	clear(@q);
62*1a457459SJohn-Mark Gurney	clear(@max);
63*1a457459SJohn-Mark Gurney	clear(@avg);
64*1a457459SJohn-Mark Gurney	clear(@stddev);
65*1a457459SJohn-Mark Gurney}
66