xref: /freebsd/share/dtrace/nfsattrstats (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 creates a trace of NFS RPCs, NFS attribute cache
31a223d3edSRui Paulo * activity, and NFS access cache activity, along with the system call
32a223d3edSRui Paulo * that instigated the activity. Notice that NFS events may happen
33a223d3edSRui Paulo * outside of the context of a system call, most likely due to the VM
34a223d3edSRui Paulo * system paging from NFS, in which case the system call name is
35a223d3edSRui Paulo * reported as "-"
36a223d3edSRui Paulo */
37ed43a220SGeorge V. Neville-Neil
38ed43a220SGeorge V. Neville-Neil#pragma D option quiet
39ed43a220SGeorge V. Neville-Neil
40ed43a220SGeorge V. Neville-Neildtrace:::BEGIN
41ed43a220SGeorge V. Neville-Neil{
42ed43a220SGeorge V. Neville-Neil	printf("probe\targ0\texecutable\tsyscall\n");
43ed43a220SGeorge V. Neville-Neil}
44ed43a220SGeorge V. Neville-Neil
45ed43a220SGeorge V. Neville-Neilsyscall:::entry
46ed43a220SGeorge V. Neville-Neil{
47ed43a220SGeorge V. Neville-Neil
48ed43a220SGeorge V. Neville-Neil        self->syscallname = probefunc;
49ed43a220SGeorge V. Neville-Neil}
50ed43a220SGeorge V. Neville-Neil
51ed43a220SGeorge V. Neville-Neilsyscall:::return
52ed43a220SGeorge V. Neville-Neil{
53ed43a220SGeorge V. Neville-Neil
54ed43a220SGeorge V. Neville-Neil        self->syscallname = "";
55ed43a220SGeorge V. Neville-Neil}
56ed43a220SGeorge V. Neville-Neil
57*c1eb4109SGeorge V. Neville-Neilnfscl:::
58ed43a220SGeorge V. Neville-Neil/self->syscallname != 0 && self->syscallname != ""/
59ed43a220SGeorge V. Neville-Neil{
60ed43a220SGeorge V. Neville-Neil
61ed43a220SGeorge V. Neville-Neil    printf("%s\t%s\t%s\t%s\n", probemod, stringof(arg0), execname,
62ed43a220SGeorge V. Neville-Neil	    self->syscallname);
63ed43a220SGeorge V. Neville-Neil}
64ed43a220SGeorge V. Neville-Neil
65*c1eb4109SGeorge V. Neville-Neilnfscl:::
66ed43a220SGeorge V. Neville-Neil/self->syscallname == 0 || self->syscallname == ""/
67ed43a220SGeorge V. Neville-Neil{
68ed43a220SGeorge V. Neville-Neil
69ed43a220SGeorge V. Neville-Neil    printf("%s\t%s\t%s\t%s\n", probemod, stringof(arg0), execname,
70ed43a220SGeorge V. Neville-Neil	    self->syscallname);
71ed43a220SGeorge V. Neville-Neil}
72