]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/Misc/woof.d
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / Misc / woof.d
1 #!/usr/sbin/dtrace -s
2 /*
3  * woof.d - Bark whenever new processes appear. Needs /dev/audio.
4  *          Written in DTrace (Solaris 10 3/05).
5  *
6  * $Id: woof.d 3 2007-08-01 10:50:08Z brendan $
7  *
8  * USAGE:       woof.d &
9  *
10  * SEE ALSO:    /usr/dt/bin/sdtaudiocontrol     # to set volume
11  *
12  * COPYRIGHT: Copyright (c) 2006 Brendan Gregg.
13  *
14  * CDDL HEADER START
15  *
16  *  The contents of this file are subject to the terms of the
17  *  Common Development and Distribution License, Version 1.0 only
18  *  (the "License").  You may not use this file except in compliance
19  *  with the License.
20  *
21  *  You can obtain a copy of the license at Docs/cddl1.txt
22  *  or http://www.opensolaris.org/os/licensing.
23  *  See the License for the specific language governing permissions
24  *  and limitations under the License.
25  *
26  * CDDL HEADER END
27  *
28  * 14-Aug-2006  Brendan Gregg   Created this.
29  * 14-Aug-2006     "      "     Last update.
30  */
31
32 #pragma D option quiet
33 #pragma D option destructive
34 #pragma D option switchrate=10hz
35
36 inline int SCREEN_OUTPUT = 0;   /* Set to 1 for screen output */
37
38 /* barks prevents woof.d from barking too much (up to 20 barks/second) */
39 int barks;
40
41 dtrace:::BEGIN
42 {
43         SCREEN_OUTPUT ? trace("Beware of the dog!\n") : 1;
44 }
45
46 /*
47  * Call the shell to run a background audioplay command (cat > /dev/audio
48  * doesn't always work). One problem this creates is a feedback loop,
49  * where we bark at our own barks, or at other dogs barks; entertaining
50  * as this is, it can really slog the system and has been avoided by
51  * checking our ancestory.
52  */
53 proc:::exec-success
54 /!progenyof($pid) && barks++ < 2/
55 {
56         SCREEN_OUTPUT ? trace("Woof! ") : 1;
57         system("audioplay /usr/share/audio/samples/au/bark.au &");
58 }
59
60 profile:::tick-10hz
61 {
62         barks = 0;
63 }