From owner-freebsd-hackers@FreeBSD.ORG Wed Jan 23 00:03:24 2013 Return-Path: Delivered-To: hackers@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 390FACCA for ; Wed, 23 Jan 2013 00:03:24 +0000 (UTC) (envelope-from rysto32@gmail.com) Received: from mail-ob0-f171.google.com (mail-ob0-f171.google.com [209.85.214.171]) by mx1.freebsd.org (Postfix) with ESMTP id 08657E14 for ; Wed, 23 Jan 2013 00:03:23 +0000 (UTC) Received: by mail-ob0-f171.google.com with SMTP id lz20so2133851obb.2 for ; Tue, 22 Jan 2013 16:03:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=yj3koOrup0X2nVpWcTvq8mj5JbKLk9vCBffsWhGvRDU=; b=S/L9cJznI98Im4hMQi3oxkTGcE1HVTAmouDjBnRwV+Eb7fF1OmgBgAVDXOluxgZxbi 67OJJ2agP6GmpEt4HXSLJoBxtNKQmsLRzqt8sBkyb4KjPXVq9SvasmUFiEphP/rtkfBC LOC79elK0QGLCIvNY91oqWKsUyZydsvsgYY2dxZ06LQrVG1WBkPcrpj89bcRQdC3abmE yVQ9LIjaDeZi4htt4eLPaaQx/XMNNwxvF7Dskc/vUyQO6LAb8jxuFx303tWnBIOJDhSa zAjRozfVOS6TtUg2S86+namMsRCPLmA8HwPzuz5CmW3/ijF6/6GLxEbByW+OhtltDGTN x2KA== MIME-Version: 1.0 X-Received: by 10.182.194.2 with SMTP id hs2mr18208707obc.97.1358899396836; Tue, 22 Jan 2013 16:03:16 -0800 (PST) Received: by 10.76.128.68 with HTTP; Tue, 22 Jan 2013 16:03:16 -0800 (PST) In-Reply-To: <50FEEB6C.7090303@rawbw.com> References: <50FEEB6C.7090303@rawbw.com> Date: Tue, 22 Jan 2013 19:03:16 -0500 Message-ID: Subject: Re: Why DTrace sensor is listed but not called? From: Ryan Stone To: Yuri Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: FreeBSD Hackers X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Jan 2013 00:03:24 -0000 On Tue, Jan 22, 2013 at 2:41 PM, Yuri wrote: > I tried to create my own DTrace sensors (for debugging purposes) through > adding of the simple function like this: > static u_int > xxx_my_trace(int arg) { > return 1; > } > > It is listed in dtrace -l with its entry and return sensors. > 8143 fbt kernel xxx_my_trace entry > 8144 fbt kernel xxx_my_trace return > This function is called, I know for sure because it is called from another > procedure which does get traced by DTrace. > However, these sensors are never triggered when run through dtrace(1M) > #!/usr/sbin/dtrace -s > ::xxx_my_trace:entry > { > printf("xxx_my_trace"); > } > It does print the following, but nothing else: > dtrace: script './dt.d' matched 1 probe > > Adding __attribute__((noinline)) doesn't help. > > What is the problem? Why dtrace sensors aren't invoked? > Offhand, I can't of why this isn't working. However there is already a way to add new DTrace probes to the kernel, and it's quite simple, so you could try it: /* The headers that you need to include. */ #include "opt_kdtrace.h" #include #include /* Declare a DTrace provider */ SDT_PROVIDER_DEFINE(your_provider); /* * Declare the DTrace probe your_provider:your_module:your_function:your_probe. You may * leave your_module or your_function blank. Most Solaris probes do, like sched:::dequeue. * We declare this probe to take 1 argument (DEFINE1) of type int. * * probe_uniquifier can be chosen arbitrarily if you like, but convention is to make it the same * as your_probe. The exception is if your-probe contains a character that is not valid in a C * (like a -, as in sched:::on-cpu). In that case the invalid character is usually replaced with an * underscore. */ SDT_PROBE_DEFINE1(your_provider, your_module, your_function, probe_uniquifier, your_probe, "int"); To call a probe: SDT_PROBE1(your_provider, your_module, your_function, probe_uniquifier, my_int_arg); (There is a wiki page on this, but it is out of date. I will clean it up). Your D script would look like: #!/usr/sbin/dtrace -s your_provider:your_module:your_function:your_probe { printf("xxx_my_trace"); }