From owner-freebsd-dtrace@freebsd.org Sun Jul 12 14:11:22 2015 Return-Path: Delivered-To: freebsd-dtrace@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 71EC4999968 for ; Sun, 12 Jul 2015 14:11:22 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: from mail-ig0-x229.google.com (mail-ig0-x229.google.com [IPv6:2607:f8b0:4001:c05::229]) (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 378CA1E1A; Sun, 12 Jul 2015 14:11:22 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: by igbij6 with SMTP id ij6so5643455igb.1; Sun, 12 Jul 2015 07:11:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=eLEnDAdx4F5Ax1fUM0JM6fd2z+QuQqxpz8um+MPASCI=; b=em8cucvhWJXYtP5cxSWHb5dDzoOEgOoYbdglqyvW8nilPEBcsWdxO4upWXDOGkNDMj ymo0PlCF2iCemHjQQnT8u84IuvWs/y6vasFsSi0r20KulMmmcN6Hc7in6XqesTnwAViq e3Gt9cMX3zBW0DKjEjUECDXnjtYEsinmTz8864Gwylgjt7e+35sRIVpKWrbLloT0+iOx gjxACi7aHekjy1xF/L5ZnXUodN+mJqxf/GNbvUSeAacshuV9+vOfZ5kU60Rlp3juxSVL HrakxbJzAhhPCVTe/RwByfhwbBaogR4NKslSMh511zgQe23DcUFU+mGQ12PIcPvgmaWw 69VA== MIME-Version: 1.0 X-Received: by 10.50.49.116 with SMTP id t20mr7789520ign.70.1436710281645; Sun, 12 Jul 2015 07:11:21 -0700 (PDT) Received: by 10.107.145.68 with HTTP; Sun, 12 Jul 2015 07:11:21 -0700 (PDT) In-Reply-To: References: <20150705233202.GA70385@raichu> Date: Sun, 12 Jul 2015 10:11:21 -0400 Message-ID: Subject: Re: Regarding schedgraph.d From: Ryan Stone To: abhishek kulkarni Cc: Mark Johnston , Ryan Stone , "freebsd-dtrace@freebsd.org" Content-Type: text/plain; charset=UTF-8 X-Content-Filtered-By: Mailman/MimeDel 2.1.20 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: Sun, 12 Jul 2015 14:11:22 -0000 Yes, this is easy to achieve using an aggregation: http://dtrace.org/guide/chp-aggs.html In the on-cpu probe, you would gather that data like this: @off_cpu[execname, curthread->td_tid] = sum(timestamp - self->offcpu_timestamp); Then you can use the printa function to print the data. If you do this from a tick-1s probe then the data will be printed every second. On Thu, Jul 9, 2015 at 3:38 PM, abhishek kulkarni wrote: > Hello, > > I got some very good inputs from you for writing a script that gives the > total running time for a particular thread as well as the total time that > the particular thread was off cpu. That script is working fine. Now, I want > to extend that script for a system wide performance. I need the "running > times" and the " off cpu times" for each thread. So, the script should > summarize the results at the end of the script for each thread. Is it > possible to achieve that using Dtrace and if yes, how. If no, would it need > a python like script to summarize the results threadwise. Please find the > attached script for a single thread. > > Regards > Abhishek Kulkarni > > On Sun, Jul 5, 2015 at 5:48 PM, abhishek kulkarni > wrote: > >> Thanks mark. I will go through all the references mentioned. your answer >> gives a clear picture of how the sched provider differs for FreeBSD. >> >> Thanks and Regards >> Abhishek Kulkarni >> >> On Sun, Jul 5, 2015 at 4:32 PM, Mark Johnston wrote: >> >>> On Thu, Jul 02, 2015 at 07:40:21PM -0400, Ryan Stone wrote: >>> > The best that I can offer right now is the Illumos documentation: >>> > >>> > http://dtrace.org/guide/chp-sched.html >>> >>> I wrote and committed some DTrace provider man pages a little while ago. >>> The page for the sched provider is here: >>> >>> https://www.freebsd.org/cgi/man.cgi?query=dtrace-sched&sektion=4&apropos=0&manpath=FreeBSD+11-current >>> >>> > >>> > The caveat is that the types documented there are not implemented in >>> > FreeBSD. Where illumos uses a lwpsinfo_t, FreeBSD uses a struct >>> thread: >>> > >>> > >>> https://svnweb.freebsd.org/base/head/sys/sys/proc.h?revision=284215&view=markup#l206 >>> > >>> > psinfo_t is replaced by struct proc. >>> > >>> > >>> https://svnweb.freebsd.org/base/head/sys/sys/proc.h?revision=284215&view=markup#l495 >>> > >>> > cpuinfo_t* arguments are not implemented and passed as NULL. You can >>> > access the current cpu number using the "cpu" variable. >>> > >>> > >>> > Finally, the schedctl-* probes don't apply to the FreeBSD scheduler and >>> > therefore are unimplemented. >>> >>> I removed them in r281702: our sched provider uses FreeBSD types and >>> thus is already incompatible with the Solaris/illumos sched provider, so >>> it didn't make much sense to me to keep them around. >>> >>> > >>> > >>> > On Thu, Jul 2, 2015 at 12:30 PM, abhishek kulkarni >> > >>> > wrote: >>> > >>> > > Thanks Ryan. Those are some very useful tips. Ill get on with trying >>> all >>> > > of those and get back If I have some more concerns. Also, could you >>> be >>> > > having some document which has some logical description about the >>> "sched" >>> > > probes for FreeBSD, which could give details like when is the >>> particular >>> > > probe fired, the probe's arguments etc. Thanks again. >>> > > >>> > > Regards >>> > > Abhishek Kulkarni >>> > > >>> > > On Wed, Jul 1, 2015 at 1:51 PM, Ryan Stone >>> wrote: >>> > > >>> > >> On Tue, Jun 30, 2015 at 7:11 PM, abhishek kulkarni < >>> abhya007@gmail.com> >>> > >> wrote: >>> > >> >>> > >>> Hello Ryan, >>> > >>> >>> > >>> I was looking to schedgraph.d . I need to modify the script for a >>> > >>> single, particular thread. I atleast need to know the thread >>> transitions, >>> > >>> as in the context switches for the particular thread and also the >>> different >>> > >>> states for a single thread. Could you please help with the filters >>> that I >>> > >>> need to add in order to use the script for a single thread or else >>> suggest >>> > >>> me just the nexessary probes that I could use for writing a new >>> script for >>> > >>> a single thread . >>> > >>> >>> > >>> Regards >>> > >>> Abhishek Kulkarni >>> > >>> >>> > >> >>> > >> There are a couple of things that you could filter on, depending on >>> what >>> > >> you know about the thread of interest. The "execname" variable >>> gives the >>> > >> name of the current process. If you're interesting in tracing a >>> > >> single-threaded process, that would be an option. Another variable >>> of >>> > >> interest would be the "curthread" variable. This gives a pointer >>> to the >>> > >> "struct thread" for the current thread. One field that you could >>> trace on >>> > >> would be curthread->td_tid. You can use ps to find your thread id >>> and then >>> > >> run the script as: >>> > >> >>> > >> dtrace -s script.d >>> > >> >>> > >> And in the script, filter with / curthread->td_tid == $1 /. Another >>> > >> field that you could use would be curthread->td_name, which >>> contains the >>> > >> name of the current thread. If your application names threads with >>> > >> "pthreads_set_name_np()", then that name will appear in td_name and >>> you can >>> > >> filter based off of that. >>> > >> >>> > >> An alternative approach would be to use a thread-local variable. >>> If you >>> > >> know that your thread is the only thread that might hit a probe, >>> you can >>> > >> set a thread local variable in that probe and filter on it later >>> on. For >>> > >> example, if your thread is the only thread that will call a >>> function called >>> > >> foobar() in the kernel, you could do this: >>> > >> >>> > >> fbt::foobar:entry >>> > >> { >>> > >> self->interesting = 1; >>> > >> } >>> > >> >>> > >> sched:::off-cpu >>> > >> / self->interesting / >>> > >> { >>> > >> /* trace interesting data here */ >>> > >> } >>> > >> >>> > >> >>> > > >>> > _______________________________________________ >>> > freebsd-dtrace@freebsd.org mailing list >>> > https://lists.freebsd.org/mailman/listinfo/freebsd-dtrace >>> > To unsubscribe, send any mail to " >>> freebsd-dtrace-unsubscribe@freebsd.org" >>> >> >> >