1N/A#!/usr/bin/sh
1N/A#
1N/A# dnlcstat - DNLC statistics.
1N/A# Written in DTrace (Solaris 10 3/05).
1N/A#
1N/A# The DNLC is the Directory Name Lookup Cache. Filename lookups often
1N/A# return a hit from here, before needing to traverse the regular file
1N/A# system cache or go to disk.
1N/A#
1N/A# $Id: dnlcstat 3 2007-08-01 10:50:08Z brendan $
1N/A#
1N/A# USAGE: dnlcstat [interval [count]]
1N/A#
1N/A# FIELDS:
1N/A#
1N/A# %hit hit percentage for this sample
1N/A# hit number of DNLC hits in this sample
1N/A# miss number of DNLC misses in this sample
1N/A#
1N/A# SEE ALSO: CacheKit, http://www.brendangregg.com/cachekit.html
1N/A# (contains a dnlcstat written in Perl, which uses less CPU)
1N/A#
1N/A# COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
1N/A#
1N/A# CDDL HEADER START
1N/A#
1N/A# The contents of this file are subject to the terms of the
1N/A# Common Development and Distribution License, Version 1.0 only
1N/A# (the "License"). You may not use this file except in compliance
1N/A# with the License.
1N/A#
1N/A# You can obtain a copy of the license at Docs/cddl1.txt
1N/A# or http://www.opensolaris.org/os/licensing.
1N/A# See the License for the specific language governing permissions
1N/A# and limitations under the License.
1N/A#
1N/A# CDDL HEADER END
1N/A#
1N/A# 27-Mar-2004 Brendan Gregg Created this.
1N/A# 14-Jun-2005 " " Updated style.
1N/A# 14-Jun-2005 " " Last update.
1N/A#
1N/A
1N/A##############################
1N/A# --- Process Arguments ---
1N/A#
1N/A
1N/A### default values
1N/Ainterval=1; count=-1
1N/A
1N/A### check arguments
1N/Aif [ "$1" = "-h" -o "$1" = "--help" ]; then
1N/A cat <<-END >&2
1N/A USAGE: dnlcstat [interval [count]]
1N/A dnlcstat # 1 second samples, infinite
1N/A eg,
1N/A dnlcstat 1 # print every 1 second
1N/A dnlcstat 5 6 # print every 5 seconds, 6 times
1N/A END
1N/A exit 1
1N/Afi
1N/A
1N/A### argument logic
1N/Aif [ "$1" -gt 0 ]; then
1N/A interval=$1; count=-1; shift
1N/Afi
1N/Aif [ "$1" -gt 0 ]; then
1N/A count=$1; shift
1N/Afi
1N/Aif [ $interval -eq 0 ]; then
1N/A interval=1
1N/Afi
1N/A
1N/A
1N/A#################################
1N/A# --- Main Program, DTrace ---
1N/A#
1N/A/usr/sbin/dtrace -n '
1N/A #pragma D option quiet
1N/A
1N/A /*
1N/A * Command line arguments
1N/A */
1N/A inline int INTERVAL = '$interval';
1N/A inline int COUNTER = '$count';
1N/A inline int SCREEN = 21;
1N/A
1N/A int hits; /* hits */
1N/A int misses; /* misses */
1N/A
1N/A /*
1N/A * Initialise variables
1N/A */
1N/A dtrace:::BEGIN
1N/A {
1N/A lines = SCREEN + 1;
1N/A counts = COUNTER;
1N/A secs = INTERVAL;
1N/A first = 1;
1N/A }
1N/A
1N/A /*
1N/A * Print header
1N/A */
1N/A dtrace:::BEGIN,
1N/A tick-1sec
1N/A /first || (secs == 0 && lines > SCREEN)/
1N/A {
1N/A printf("%10s %8s %8s\n","dnlc %hit","hit","miss");
1N/A lines = 0;
1N/A first = 0;
1N/A }
1N/A
1N/A /*
1N/A * Probe DNLC lookups
1N/A */
1N/A fbt:genunix:dnlc_lookup:return
1N/A {
1N/A hits += arg1 == 0 ? 0 : 1;
1N/A misses += arg1 == 0 ? 1 : 0;
1N/A }
1N/A
1N/A profile:::tick-1sec
1N/A {
1N/A secs--;
1N/A }
1N/A
1N/A
1N/A /*
1N/A * Print output line
1N/A */
1N/A profile:::tick-1sec
1N/A /secs == 0/
1N/A {
1N/A /* calculate hit percent */
1N/A this->divide = misses + hits == 0 ? 1 : misses + hits;
1N/A ratio = hits * 100 / this->divide;
1N/A
1N/A /* print output */
1N/A printf("%10d %8d %8d\n",ratio,hits,misses);
1N/A
1N/A /* clear counters */
1N/A hits = 0;
1N/A misses = 0;
1N/A
1N/A /* process counts */
1N/A secs = INTERVAL;
1N/A counts--;
1N/A lines++;
1N/A
1N/A }
1N/A
1N/A /*
1N/A * End
1N/A */
1N/A profile:::tick-1sec
1N/A /counts == 0/
1N/A {
1N/A exit(0);
1N/A }
1N/A'
1N/A