lkml.org 
[lkml]   [2013]   [Oct]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Subject[PATCH v4 0/3] perf support to SDT markers
    From
    Date
    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 user_app:foo_start -aR sleep 1

    # perf record -e user_app: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)
    #

    We can see and probe the existing markers in libc (if present) :
    $ perf probe --markers -x /lib64/libc.so.6

    %libc:setjmp
    %libc:longjmp
    %libc:longjmp_target
    %libc:lll_futex_wake
    %libc:lll_lock_wait_private
    %libc:longjmp
    %libc:longjmp_target
    %libc:lll_futex_wake

    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:
    - The interface search_sdt_note() has been changed and 'list' argument has been
    removed.
    - list_empty() check is now done in print_sdt_note_info() and
    cleanup_sdt_note_info().
    - Some small improvements have been made.

    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 | 125 ++++++++++++-
    tools/perf/util/probe-event.h | 3
    tools/perf/util/symbol-elf.c | 309 +++++++++++++++++++++++++++++++
    tools/perf/util/symbol.h | 24 ++
    7 files changed, 693 insertions(+), 14 deletions(-)
    create mode 100644 tools/perf/Documentation/sdt-probes.txt

    --



    \
     
     \ /
      Last update: 2013-10-23 07:21    [W:0.045 / U:30.276 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site