3 * pathopens.d - full pathnames opened successfully count.
4 * Written using DTrace (Solaris 10 3/05)
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.
10 * $Id: pathopens.d 3 2007-08-01 10:50:08Z brendan $
15 * PATHNAME full pathname
16 * COUNT number of successful opens
18 * Similar to a script from DExplorer.
20 * COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg.
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
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.
36 * 28-Jun-2005 Brendan Gregg Created this.
37 * 12-Jan-2006 " " Fixed known error.
38 * 20-Apr-2006 " " Last update.
41 #pragma D option quiet
45 printf("Tracing... Hit Ctrl-C to end.\n");
55 /self->ok && arg0 != -1/
57 self->file = copyinstr(self->pathp);
58 self->char0 = copyin(self->pathp, 1);
60 /* fetch current working directory */
61 this->path = curthread->t_procp->p_user.u_cdir->v_path;
64 * Make the full pathname
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
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);
77 /* save to aggregation */
78 @num[self->full] = count();
98 printf("%6s %s\n", "COUNT", "PATHNAME");
99 printa("%@6d %s\n", @num);