xref: /netbsd-src/external/cddl/dtracetoolkit/dist/Kernel/dnlcsnoop.d (revision c29d51755812ace2e87aeefdb06cb2b4dac7087a)
1 #!/usr/sbin/dtrace -s
2 /*
3  * dnlcsnoop.d - snoop DNLC activity.
4  *               Written in DTrace (Solaris 10 3/05).
5  *
6  * The DNLC is the Directory Name Lookup Cache. Filename lookups often
7  * return a hit from here, before needing to traverse the regular file
8  * system cache or go to disk.
9  *
10  * $Id: dnlcsnoop.d,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $
11  *
12  * USAGE:	dnlcsnoop.d     # wait several seconds, then hit Ctrl-C
13  *
14  * FIELDS:
15  *		PID             Process ID
16  *		CMD          	Command name
17  *		TIME         	Elapsed time for lookup, us
18  *		HIT          	DNLC hit Y/N
19  *		PATH         	Path for DNLC lookup
20  *
21  * COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg.
22  *
23  * CDDL HEADER START
24  *
25  *  The contents of this file are subject to the terms of the
26  *  Common Development and Distribution License, Version 1.0 only
27  *  (the "License").  You may not use this file except in compliance
28  *  with the License.
29  *
30  *  You can obtain a copy of the license at Docs/cddl1.txt
31  *  or http://www.opensolaris.org/os/licensing.
32  *  See the License for the specific language governing permissions
33  *  and limitations under the License.
34  *
35  * CDDL HEADER END
36  *
37  * 27-Mar-2004	Brendan Gregg	Created this.
38  * 14-Jun-2005	   "      "	Rewrote this a lot.
39  * 20-Apr-2006	   "      "	Last update.
40  */
41 
42 #pragma D option quiet
43 
44 /*
45  * Print header
46  */
47 dtrace:::BEGIN
48 {
49 	printf("%6s %-12s %5s %3s %s\n",
50 	    "PID", "CMD", "TIME", "HIT", "PATH");
51 }
52 
53 /*
54  * DNLC lookup
55  */
56 fbt:genunix:dnlc_lookup:entry
57 {
58 	/* store path */
59 	self->path = stringof(args[0]->v_path);
60 
61 	/* check for trailing "/" */
62 	this->len = strlen(self->path);
63 	self->join = *(char *)(args[0]->v_path + this->len - 1) == '/' ?
64 	    "" : "/";
65 
66 	/* store lookup name */
67 	self->name = stringof(arg1);
68 
69 	/* store start time */
70 	self->start = timestamp;
71 }
72 
73 /*
74  * DNLC return
75  */
76 fbt:genunix:dnlc_lookup:return
77 /self->start/
78 {
79 	/* calculate elapsed time */
80 	this->elapsed = (timestamp - self->start) / 1000;
81 
82 	/* print output */
83 	printf("%6d %-12.12s %5d %3s %s%s%s\n",
84 	    pid, execname, this->elapsed, arg1 == 0 ? "N" : "Y",
85 	    self->path, self->join, self->name);
86 
87 	/* clear variables */
88 	self->path = 0;
89 	self->join = 0;
90 	self->name = 0;
91 	self->start = 0;
92 }
93