xref: /freebsd/share/dtrace/nfsclienttime (revision c1eb4109f3b1d90a9c1538179ea6a52a191899b2)
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 * $FreeBSD$
31a223d3edSRui Paulo *
32a223d3edSRui Paulo * This script measures all time spent waiting on RPC replies for each
33a223d3edSRui Paulo * system call, and then generates a histogram of those times sorted by
34a223d3edSRui Paulo * system call name.
35a223d3edSRui Paulo *
36a223d3edSRui Paulo * Currently only supports NFSv3
37a223d3edSRui Paulo *
38a223d3edSRui Paulo * Usage: nfsclienttime
39a223d3edSRui Paulo *
40a223d3edSRui Paulo * Press Ctrl-C to exit and display statistics.
41a223d3edSRui 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
56*c1eb4109SGeorge V. Neville-Neilnfscl: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
62*c1eb4109SGeorge V. Neville-Neilnfscl: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