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 * 20-Apr-2006, ver 0.71 11 * 12 * 13 * USAGE: dnlcsnoop.d # wait several seconds, then hit Ctrl-C 14 * 15 * FIELDS: 16 * PID Process ID 17 * CMD Command name 18 * TIME Elapsed time for lookup, us 19 * HIT DNLC hit Y/N 20 * PATH Path for DNLC lookup 21 * 22 * COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg. 23 * 24 * CDDL HEADER START 25 * 26 * The contents of this file are subject to the terms of the 27 * Common Development and Distribution License, Version 1.0 only 28 * (the "License"). You may not use this file except in compliance 29 * with the License. 30 * 31 * You can obtain a copy of the license at Docs/cddl1.txt 32 * or http://www.opensolaris.org/os/licensing. 33 * See the License for the specific language governing permissions 34 * and limitations under the License. 35 * 36 * CDDL HEADER END 37 * 38 * 27-Mar-2004 Brendan Gregg Created this. 39 * 14-Jun-2005 " " Rewrote this a lot. 40 */ 41 42#pragma D option quiet 43 44/* 45 * Print header 46 */ 47dtrace:::BEGIN 48{ 49 printf("%6s %-12s %5s %3s %s\n", 50 "PID", "CMD", "TIME", "HIT", "PATH"); 51} 52 53/* 54 * DNLC lookup 55 */ 56fbt: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 */ 76fbt: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