1af71f40aSPawel Jakub Dawidek#!/usr/sbin/dtrace -s 2af71f40aSPawel Jakub Dawidek/*- 3af71f40aSPawel Jakub Dawidek * Copyright (c) 2015 Pawel Jakub Dawidek <pawel@dawidek.net> 4af71f40aSPawel Jakub Dawidek * All rights reserved. 5af71f40aSPawel Jakub Dawidek * 6af71f40aSPawel Jakub Dawidek * Redistribution and use in source and binary forms, with or without 7af71f40aSPawel Jakub Dawidek * modification, are permitted provided that the following conditions 8af71f40aSPawel Jakub Dawidek * are met: 9af71f40aSPawel Jakub Dawidek * 1. Redistributions of source code must retain the above copyright 10af71f40aSPawel Jakub Dawidek * notice, this list of conditions and the following disclaimer. 11af71f40aSPawel Jakub Dawidek * 2. Redistributions in binary form must reproduce the above copyright 12af71f40aSPawel Jakub Dawidek * notice, this list of conditions and the following disclaimer in the 13af71f40aSPawel Jakub Dawidek * documentation and/or other materials provided with the distribution. 14af71f40aSPawel Jakub Dawidek * 15af71f40aSPawel Jakub Dawidek * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 16af71f40aSPawel Jakub Dawidek * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17af71f40aSPawel Jakub Dawidek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18af71f40aSPawel Jakub Dawidek * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 19af71f40aSPawel Jakub Dawidek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20af71f40aSPawel Jakub Dawidek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21af71f40aSPawel Jakub Dawidek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22af71f40aSPawel Jakub Dawidek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23af71f40aSPawel Jakub Dawidek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24af71f40aSPawel Jakub Dawidek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25af71f40aSPawel Jakub Dawidek * SUCH DAMAGE. 26af71f40aSPawel Jakub Dawidek * 27af71f40aSPawel Jakub Dawidek * This little script is for use with programs that use event loop and should 28af71f40aSPawel Jakub Dawidek * sleep only when waiting for events (eg. via kevent(2)). When a program is 29af71f40aSPawel Jakub Dawidek * going to sleep in the kernel, the script will show its name, PID, kernel 30af71f40aSPawel Jakub Dawidek * stack trace and userland stack trace. Sleeping in kevent(2) is ignored. 31af71f40aSPawel Jakub Dawidek * 32af71f40aSPawel Jakub Dawidek * usage: blocking <execname> 33af71f40aSPawel Jakub Dawidek */ 34af71f40aSPawel Jakub Dawidek 35af71f40aSPawel Jakub Dawidek#pragma D option quiet 36af71f40aSPawel Jakub Dawidek 37af71f40aSPawel Jakub Dawideksyscall::kevent:entry 38af71f40aSPawel Jakub Dawidek/execname == $$1/ 39af71f40aSPawel Jakub Dawidek{ 40af71f40aSPawel Jakub Dawidek self->inkevent = 1; 41af71f40aSPawel Jakub Dawidek} 42af71f40aSPawel Jakub Dawidek 43af71f40aSPawel Jakub Dawidekfbt::sleepq_add:entry 44af71f40aSPawel Jakub Dawidek/!self->inkevent && execname == $$1/ 45af71f40aSPawel Jakub Dawidek{ 46af71f40aSPawel Jakub Dawidek printf("\n%s(%d) is blocking...\n", execname, pid); 47af71f40aSPawel Jakub Dawidek stack(); 48af71f40aSPawel Jakub Dawidek ustack(); 49af71f40aSPawel Jakub Dawidek} 50af71f40aSPawel Jakub Dawidek 51af71f40aSPawel Jakub Dawideksyscall::kevent:return 52af71f40aSPawel Jakub Dawidek/execname == $$1/ 53af71f40aSPawel Jakub Dawidek{ 54af71f40aSPawel Jakub Dawidek self->inkevent = 0; 55af71f40aSPawel Jakub Dawidek} 56