#!/usr/sbin/dtrace -s

inline int userwait[string wmesg] =
    wmesg == "kqread" ? 1 :
    wmesg == "wait" ? 1 :
    wmesg == "pause" ? 1 :
    wmesg == "nanslp" ? 1 :
    wmesg == "usem" ? 1 :
    wmesg == "uwait" ? 1 :
    wmesg == "umtxn" ? 1 :
    wmesg == "umtxpp" ? 1 :
    wmesg == "piperd" ? 1 :
    wmesg == "pipdww" ? 1 :
    wmesg == "pipdwc" ? 1 :
    wmesg == "pipdwt" ? 1 :
    wmesg == "pipdww" ? 1 :
    wmesg == "pipewr" ? 1 :
    wmesg == "select" ? 1 : 0;

inline int pausing[void *wchan] = 
    (uintptr_t)wchan >= (uintptr_t)&`pause_wchan[0] &&
    (uintptr_t)wchan <= (uintptr_t)&`pause_wchan[255];

sched:::sleep
/!pausing[curthread->td_wchan] && (curthread->td_blocked != NULL || !userwait[curthread->td_wmesg])/
{
	@[stack()] = count();
}

/*
sched:::on-cpu
/self->trace/
{
	self->trace = 0;
	@[stack()] = count();
}
*/
