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