From owner-freebsd-dtrace@FreeBSD.ORG Wed Jun 17 19:50:54 2015 Return-Path: Delivered-To: freebsd-dtrace@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2C732D85 for ; Wed, 17 Jun 2015 19:50:54 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: from mail-qc0-x230.google.com (mail-qc0-x230.google.com [IPv6:2607:f8b0:400d:c01::230]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D8E9292D for ; Wed, 17 Jun 2015 19:50:53 +0000 (UTC) (envelope-from markjdb@gmail.com) Received: by qcbfz6 with SMTP id fz6so17317067qcb.0 for ; Wed, 17 Jun 2015 12:50:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=+WY8bGj/5Dq9O7K60/9oUcHzWgsywCtGBSrBQSVb3l4=; b=iuyY3+ukJR8/i/zDHYX7yT+K/a2PQoVZof1gmO8D59rZDcUhmB2rALZv09SHf+aeib Q9XBE13u1rn8Q0Bz4MUcAlwLu8fgJfcR+0/eQiY8gdP3rooaBDL4F7lvMkVh0ciQYuUE 1KvD5nvv+nZRoPMZL8mqwi0PcxJ3GOrlci49zT/WdwoQCXZEXiniYg1JD9PU19XSn14X vsJlR0CstX17lVw16YEJNBod8h4Z7VmbA/6KAKf1+N5Dm6qMWQV4MlYXHQuBNDL+/em3 97Z4WCusEZBpPd2E3KWes2rwCVUXFO5YOjPAzr4fsi7dZnbY1gNyRUnF3s8/IVg80NM/ I88w== X-Received: by 10.55.48.18 with SMTP id w18mr17072376qkw.34.1434570652833; Wed, 17 Jun 2015 12:50:52 -0700 (PDT) Received: from muskytusk ([104.236.250.12]) by mx.google.com with ESMTPSA id 63sm2695827qgx.25.2015.06.17.12.50.51 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jun 2015 12:50:51 -0700 (PDT) Sender: Mark Johnston Date: Wed, 17 Jun 2015 19:49:46 +0000 From: Mark Johnston To: abhishek kulkarni Cc: freebsd-dtrace@freebsd.org Subject: Re: Regarding a Sched Dtrace Script for FreeBSD Message-ID: <20150617194946.GA34351@muskytusk> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-BeenThere: freebsd-dtrace@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "A discussion list for developers working on DTrace in FreeBSD." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Jun 2015 19:50:54 -0000 On Tue, Jun 16, 2015 at 11:01:27AM -0700, abhishek kulkarni wrote: > Hello all, > > > > I am working on Dtrace and trying to implement a sched script for FreeBSD > 10.0 > > The script uses the probes on-cpu and off-cpu. > > The purpose is to measure the time that a CPU spends on the current thread. > > I am trying to use the aggregation function “SUM” to capture the CPU time > for the ping utility. I am doing it by opening a new putty terminal and > running the ping utility in it, and then running the Dtrace script in > another instance of the terminal. > > I am also using the time utility in order to verify the Kernel Time for a > ping. The time given by the “Time” utility and the Dtrace script do not > match. Could you please help with this . The following is the Dtrace script > we are trying out : Hello, There are a couple of problems in the script, which I've pointed out below. > > > > sched:::on-cpu > > /curthread->td_name == "ping"/ Generally, only kernel threads will have names, so this condition will never be true. You can use the execname variable to match processes named "ping", but note that this will give incorrect results if there are multiple ping processes running at the same time as the script. You can match a specific process using its PID and dtrace(1)'s -c option. For example: dtrace -n 'syscall:::entry /pid == $target/{}' -c "ping -c 3 google.com" > > { > > self->ts = timestamp; > > } > > > > sched:::off-cpu > > /self->ts != 0/ > > { > > @delta[curthread->td_name] = sum(timestamp - self->ts)/1000000; This will result in an error since the sum function doesn't return an integer. I suspect you meant "sum((timestamp - self->ts) / 1000000);"? > > self->ts =0; > > }