1238660Sgnn#!/bin/sh
2238660Sgnn#
3238660Sgnn# Copyright (c) 2012 George V. Neville-Neil
4238660Sgnn# All rights reserved.
5238660Sgnn#
6238660Sgnn# Redistribution and use in source and binary forms, with or without
7238660Sgnn# modification, are permitted provided that the following conditions
8238660Sgnn# are met:
9238660Sgnn# 1. Redistributions of source code must retain the above copyright
10238660Sgnn#    notice, this list of conditions and the following disclaimer.
11238660Sgnn# 2. Redistributions in binary form must reproduce the above copyright
12238660Sgnn#    notice, this list of conditions and the following disclaimer in the
13238660Sgnn#    documentation and/or other materials provided with the distribution.
14238660Sgnn#
15238660Sgnn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16238660Sgnn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17238660Sgnn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18238660Sgnn# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19238660Sgnn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20238660Sgnn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21238660Sgnn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22238660Sgnn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23238660Sgnn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24238660Sgnn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25238660Sgnn# SUCH DAMAGE.
26238660Sgnn#
27238660Sgnn# $FreeBSD$
28238660Sgnn#
29238660Sgnn# The hotopen D script periodically outputs  table of which UIDs
30238660Sgnn# are opening files.   This is a very quick way to find out if
31238660Sgnn# a paritcular user is thrashing a system with rapid calls to
32238660Sgnn# open/close.
33238660Sgnn#
34238660Sgnn# Usage: hotopen
35238660Sgnn#
36238660Sgnn
37238660Sgnn/usr/sbin/dtrace -n '
38238660Sgnn#pragma D option quiet
39238660SgnnBEGIN
40238660Sgnn{
41238660Sgnn	printf("Files opened per UID in the last second.\n");
42238660Sgnn}
43238660Sgnn
44238660Sgnnsyscall::open:entry
45238660Sgnn{
46238660Sgnn	@files[uid] = count();
47238660Sgnn	output = 1;
48238660Sgnn}
49238660Sgnn
50238660Sgnntick-1sec
51238660Sgnn/output != 0/
52238660Sgnn{
53238660Sgnn	printf("%-20Y \n", walltimestamp);
54238660Sgnn	printa("uid %d\tcount %@d\n", @files, @files);
55238660Sgnn	trunc(@files);
56238660Sgnn	output = 0;
57238660Sgnn}
58238660Sgnn'
59