#!/usr/sbin/dtrace -s

/*
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * When distributing Covered Code, include this comment block in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 */

/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#pragma D option dynvarsize=4m

sched:::sleep
/pid == $target && self->traced == 0/
{
	self->traced = 1;
}

sched:::off-cpu
/self->traced && self->sleep == 0/
{
	self->sleep = timestamp;
}

sched:::on-cpu
/self->sleep/
{
	@a[stack()] = sum(timestamp - self->sleep);
	self->sleep = 0;
	self->traced = 0;
}

END
{
	trunc(@a, 50);
}

