xref: /freebsd/share/dtrace/nfsclienttime (revision a223d3ed90bfe313ce5987d468a25a915d7d1254)
1*a223d3edSRui Paulo#!/usr/sbin/dtrace -s
2*a223d3edSRui Paulo/*
3*a223d3edSRui Paulo * Copyright (c) 2012 Robert N. M. Watson
4*a223d3edSRui Paulo * All rights reserved.
5*a223d3edSRui Paulo *
6*a223d3edSRui Paulo * This software was developed at the University of Cambridge Computer
7*a223d3edSRui Paulo * Laboratory with support from a grant from Google, Inc.
8*a223d3edSRui Paulo *
9*a223d3edSRui Paulo * Redistribution and use in source and binary forms, with or without
10*a223d3edSRui Paulo * modification, are permitted provided that the following conditions
11*a223d3edSRui Paulo * are met:
12*a223d3edSRui Paulo * 1. Redistributions of source code must retain the above copyright
13*a223d3edSRui Paulo *    notice, this list of conditions and the following disclaimer.
14*a223d3edSRui Paulo * 2. Redistributions in binary form must reproduce the above copyright
15*a223d3edSRui Paulo *    notice, this list of conditions and the following disclaimer in the
16*a223d3edSRui Paulo *    documentation and/or other materials provided with the distribution.
17*a223d3edSRui Paulo *
18*a223d3edSRui Paulo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19*a223d3edSRui Paulo * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*a223d3edSRui Paulo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*a223d3edSRui Paulo * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22*a223d3edSRui Paulo * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23*a223d3edSRui Paulo * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24*a223d3edSRui Paulo * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*a223d3edSRui Paulo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26*a223d3edSRui Paulo * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*a223d3edSRui Paulo * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*a223d3edSRui Paulo * SUCH DAMAGE.
29*a223d3edSRui Paulo *
30*a223d3edSRui Paulo * $FreeBSD$
31*a223d3edSRui Paulo *
32*a223d3edSRui Paulo * This script measures all time spent waiting on RPC replies for each
33*a223d3edSRui Paulo * system call, and then generates a histogram of those times sorted by
34*a223d3edSRui Paulo * system call name.
35*a223d3edSRui Paulo *
36*a223d3edSRui Paulo * Currently only supports NFSv3
37*a223d3edSRui Paulo *
38*a223d3edSRui Paulo * Usage: nfsclienttime
39*a223d3edSRui Paulo *
40*a223d3edSRui Paulo * Press Ctrl-C to exit and display statistics.
41*a223d3edSRui Paulo */
42c94c8819SGeorge V. Neville-Neil
43c94c8819SGeorge V. Neville-Neil#pragma D option quiet
44c94c8819SGeorge V. Neville-Neil
45c94c8819SGeorge V. Neville-Neildtrace:::BEGIN
46c94c8819SGeorge V. Neville-Neil{
47c94c8819SGeorge V. Neville-Neil	printf("Collecting data...press Ctrl-C to exit.\n");
48c94c8819SGeorge V. Neville-Neil}
49c94c8819SGeorge V. Neville-Neil
50c94c8819SGeorge V. Neville-Neilsyscall:::entry
51c94c8819SGeorge V. Neville-Neil{
52c94c8819SGeorge V. Neville-Neil
53c94c8819SGeorge V. Neville-Neil        self->count = 0;
54c94c8819SGeorge V. Neville-Neil}
55c94c8819SGeorge V. Neville-Neil
56c94c8819SGeorge V. Neville-Neilnfsclient:nfs3::start
57c94c8819SGeorge V. Neville-Neil{
58c94c8819SGeorge V. Neville-Neil
59c94c8819SGeorge V. Neville-Neil        self->timestamp = timestamp;
60c94c8819SGeorge V. Neville-Neil}
61c94c8819SGeorge V. Neville-Neil
62c94c8819SGeorge V. Neville-Neilnfsclient:nfs3::done
63c94c8819SGeorge V. Neville-Neil{
64c94c8819SGeorge V. Neville-Neil
65c94c8819SGeorge V. Neville-Neil        self->count += (timestamp - self->timestamp);
66c94c8819SGeorge V. Neville-Neil}
67c94c8819SGeorge V. Neville-Neil
68c94c8819SGeorge V. Neville-Neilsyscall:::return
69c94c8819SGeorge V. Neville-Neil/self->count != 0/  {
70c94c8819SGeorge V. Neville-Neil
71c94c8819SGeorge V. Neville-Neil        @syscalls[probefunc] = quantize(self->count);
72c94c8819SGeorge V. Neville-Neil}
73