]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/Proc/pathopens.d
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / Proc / pathopens.d
1 #!/usr/sbin/dtrace -s
2 /*
3  * pathopens.d - full pathnames opened successfully count.
4  *               Written using DTrace (Solaris 10 3/05)
5  *
6  * This program prints a count of the number of times files have been
7  * successfully opened. This is somewhat special in that the full pathname
8  * is calculated, even if the file open referred to a relative pathname.
9  *
10  * $Id: pathopens.d 3 2007-08-01 10:50:08Z brendan $
11  *
12  * USAGE:       fileopens.d
13  *
14  * FIELDS:
15  *              PATHNAME        full pathname
16  *              COUNT           number of successful opens
17  *
18  * Similar to a script from DExplorer.
19  *
20  * COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg.
21  *
22  * CDDL HEADER START
23  *
24  *  The contents of this file are subject to the terms of the
25  *  Common Development and Distribution License, Version 1.0 only
26  *  (the "License").  You may not use this file except in compliance
27  *  with the License.
28  *
29  *  You can obtain a copy of the license at Docs/cddl1.txt
30  *  or http://www.opensolaris.org/os/licensing.
31  *  See the License for the specific language governing permissions
32  *  and limitations under the License.
33  *
34  * CDDL HEADER END
35  *
36  * 28-Jun-2005  Brendan Gregg   Created this.
37  * 12-Jan-2006     "      "     Fixed known error.
38  * 20-Apr-2006     "      "     Last update.
39  */
40
41 #pragma D option quiet
42
43 dtrace:::BEGIN
44 {
45         printf("Tracing... Hit Ctrl-C to end.\n");
46 }
47
48 syscall::open*:entry
49 {
50         self->pathp = arg0;
51         self->ok = 1;
52 }
53
54 syscall::open*:return
55 /self->ok && arg0 != -1/
56 {
57         self->file = copyinstr(self->pathp);
58         self->char0 = copyin(self->pathp, 1);
59
60         /* fetch current working directory */
61         this->path = curthread->t_procp->p_user.u_cdir->v_path;
62
63         /*
64          * Make the full pathname
65          *
66          * This routine takes the cwd and the filename, and generates a
67          * full pathname. Sometimes the filename is absolute, so we must
68          * ignore the cwd. This also checks if the cwd ends in an
69          * unnecessary '/'.
70          */
71         this->len = strlen(this->path);
72         self->join = *(char *)(this->path + this->len - 1) == '/' ?  "" : "/";
73         self->dir = strjoin(cwd, self->join);
74         self->dir = *(char *)self->char0 == '/' ? "" : self->dir;
75         self->full = strjoin(self->dir, self->file);
76
77         /* save to aggregation */
78         @num[self->full] = count();
79
80         /* cleanup */
81         self->join  = 0;
82         self->full  = 0;
83         self->dir   = 0;
84         self->file  = 0;
85         self->char0 = 0;
86 }
87
88 syscall::open*:return
89 /self->ok/
90 {
91         /* cleanup */
92         self->ok    = 0;
93         self->pathp = 0;
94 }
95
96 dtrace:::END
97 {
98         printf("%6s %s\n", "COUNT", "PATHNAME");
99         printa("%@6d %s\n", @num);
100 }