public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Hemant <hkshaw@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: srikar@linux.vnet.ibm.com, peterz@infradead.org, oleg@redhat.com,
	hegdevasant@linux.vnet.ibm.com, mingo@redhat.com,
	anton@redhat.com, systemtap@sourceware.org, namhyung@kernel.org,
	masami.hiramatsu.pt@hitachi.com, aravinda@linux.vnet.ibm.com
Subject: Re: [PATCH v3 0/3] Perf support to SDT markers
Date: Fri, 18 Oct 2013 20:19:18 +0530	[thread overview]
Message-ID: <52614A6E.6080609@linux.vnet.ibm.com> (raw)
In-Reply-To: <20131018143714.10452.83494.stgit@hemant-fedora>

On 10/18/2013 08:12 PM, Hemant Kumar wrote:
> This patchset helps in probing dtrace style markers(SDT) present in user space
> applications through perf. Notes/markers are placed at important places by the
> developers. They have a negligible overhead when not enabled. We can enable
> them and probe at these places and find some important information like the
> arguments' values, etc.
>
> How to add SDT markers into user applications:
> We need to have this header sys/sdt.h present.
> sys/sdt.h used is version 3.
> If not present, install systemtap-sdt-devel package (for fedora-18).
>
> A very simple example to show this :
> $ cat user_app.c
>
> #include <sys/sdt.h>
>
> void main () {
>         /* ... */
>         /*
>          * user_app is the provider name
>          * test_probe is the marker name
>          */
>         STAP_PROBE(user_app, test_mark);
>         /* ... */
> }
>
> $ gcc user_app.c
> $ perf probe -M -x ./a.out
> %user_app:test_mark
>
> A different example to show the same :
> - Create a file with .d extension and mention the probe names in it with
> provider name and marker name.
>
> $ cat probes.d
> provider user_app {
>           probe foo_start();
>               probe fun_start();
> };
>
> - Now create the probes.h and probes.o file :
> $ dtrace -C -h -s probes.d -o probes.h
> $ dtrace -C -G -s probes.d -o probes.o
>
> - A program using the markers:
>
> $ cat user_app.c
>
> #include <stdio.h>
> #include "probes.h"
>
> void foo(void)
> {
>          USER_APP_FOO_START();
>          printf("This is foo\n");
> }
>
> void fun(void)
> {
>          USER_APP_FUN_START();
>          printf("Inside fun\n");
> }
> int main(void)
> {
>          printf("In main\n");
>          foo();
>          fun();
>          return 0;
> }
>
> - Compile it and also provide probes.o file to linker:
> $ gcc user_app.c probes.o -o user_app
>
> - Now use perf to list the markers in the app:
> # perf probe --markers -x ./user_app
>
> %user_app:foo_start
> %user_app:fun_start
>
> - And  then use perf probe to add a probe point :
>
> # perf probe -x ./user_app -a '%user_app:foo_start'
>
> Added new event :
> event = foo_start      (on 0x530)
>
> You can now use it on all perf tools such as :
>
>       perf record -e probe_user:foo_start -aR sleep 1
>
> # perf record -e probe_user:foo_start -aR ./user_app
> In main
> This is foo
> Inside fun
> [ perf record: Woken up 1 times to write data ]
> [ perf record: Captured and wrote 0.235 MB perf.data (~10279 samples) ]
>
> - Then use perf tools to analyze it.
> # perf report --stdio
>
> # ========
> # captured on: Tue Sep  3 16:19:55 2013
> # hostname : hemant-fedora
> # os release : 3.11.0-rc3+
> # perf version : 3.9.4-200.fc18.x86_64
> # arch : x86_64
> # nrcpus online : 2
> # nrcpus avail : 2
> # cpudesc : QEMU Virtual CPU version 1.2.2
> # cpuid : GenuineIntel,6,2,3
> # total memory : 2051912 kBIf these are not enabled, they are present in the \
> ELF as nop.
>
> # cmdline : /usr/bin/perf record -e probe_user:foo_start -aR ./user_app
> # event : name = probe_user:foo_start, type = 2, config = 0x38e, config1
> = 0x0, config2 = 0x0, excl_usr = 0, excl_kern = 0, excl_host = 0,
> excl_guest = 1, precise_ip = 0
> # HEADER_CPU_TOPOLOGY info available, use -I to display
> # HEADER_NUMA_TOPOLOGY info available, use -I to display
> # pmu mappings: software = 1, tracepoint = 2, breakpoint = 5
> # ========
> #
> # Samples: 1  of event 'probe_user:foo_start'
> # Event count (approx.): 1
> #
> # Overhead   Command  Shared Object   Symbol
> # ........  ........  .............  .......
> #
>     100.00%  user_app  user_app       [.] foo
>
>
> #
> # (For a higher level overview, try: perf report --sort comm,dso)
> #
>
> This link shows an example of marker probing with Systemtap:
> https://sourceware.org/systemtap/wiki/AddingUserSpaceProbingToApps
>
> Also, this link provides important info regarding SDT notes:
> http://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation
>
> - Markers in binaries :
> These SDT markers are present in the ELF in the section named
> ".note.stapsdt".
> Here, the name of the marker, its provider, type, location, base
> address, semaphore address.
> We can retrieve these values using the members name_off and desc_off in
> Nhdr structure. If these are not enabled, they are present in the ELF as nop.
>
> All the above info is moved in sdt-probes.txt file present in the Documentation
> directory in tools/perf/.
>
> Changes since last version:
> - Added suggested changes by Masami and Namhyung.
> - Fixed some bugs.
> - Removed some redundancies.
> - Updated with error codes.
> - Rebased it to latest kernel tip.
>
> TODO:
> - Recognizing arguments and support to probe on them.
> ---
>
> Hemant Kumar (3):
>        SDT markers listing by perf:
>        Support for perf to probe into SDT markers:
>        Documentation regarding perf/sdt
>
>
>   tools/perf/Documentation/perf-probe.txt |   17 ++
>   tools/perf/Documentation/sdt-probes.txt |  184 ++++++++++++++++++++
>   tools/perf/builtin-probe.c              |   45 +++++
>   tools/perf/util/probe-event.c           |  134 +++++++++++++-
>   tools/perf/util/probe-event.h           |    3
>   tools/perf/util/symbol-elf.c            |  291 +++++++++++++++++++++++++++++++
>   tools/perf/util/symbol.h                |   21 ++
>   7 files changed, 681 insertions(+), 14 deletions(-)
>   create mode 100644 tools/perf/Documentation/sdt-probes.txt
>

Please ignore the previous patchset. Due to some git config issues, the 
from email id was wrong. It has been fixed in this patchset.

-- 
Thanks
Hemant


      parent reply	other threads:[~2013-10-18 14:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-18 14:42 [PATCH v3 0/3] Perf support to SDT markers Hemant Kumar
2013-10-18 14:44 ` [PATCH v3 1/3] SDT markers listing by perf: Hemant Kumar
2013-10-19 15:27   ` Masami Hiramatsu
2013-10-20  7:47     ` Hemant Kumar
2013-10-18 14:44 ` [PATCH v3 2/3] Support for perf to probe into SDT markers: Hemant Kumar
2013-10-19 15:48   ` Masami Hiramatsu
2013-10-20  7:50     ` Hemant Kumar
2013-10-18 14:45 ` [PATCH v3 3/3] Documentation regarding perf/sdt Hemant Kumar
2013-10-18 14:49 ` Hemant [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52614A6E.6080609@linux.vnet.ibm.com \
    --to=hkshaw@linux.vnet.ibm.com \
    --cc=anton@redhat.com \
    --cc=aravinda@linux.vnet.ibm.com \
    --cc=hegdevasant@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=srikar@linux.vnet.ibm.com \
    --cc=systemtap@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox