[DTrace-devel] [PATCH v2 0/4] ELF note-based USDT support

Alan Maguire alan.maguire at oracle.com
Wed Jan 29 14:55:18 UTC 2025


This series adds support (patch 1) for ELF-note defined USDT
probes in binaries and libraries; patches 2-4 add tests.

Basic pid-specific USDT support is added; i.e. it is necessary
to specify the target pid in the provider name such as
"example1234" ; future work could add pid wildcarding.

ELF note defined probes are defined by including sys/sdt.h
from the systemtap-sdt-devel package, and are defined in
C programs via

DTRACE_PROBEn(provider, probe, [args...])

See the tests for concrete examples.

For python, go, etc, USDT probes can be added via libstapsdt [1]
and associated language-specific bindings.  This allows users
of those languages to add USDT probes too.  For example, the
following example program adds a "pythonapp" probe "firstProbe"
using the python-specific libstapsdt binding:

#!/usr/bin/python3
from time import sleep
import stapsdt
provider = stapsdt.Provider("pythonapp")
probe = provider.add_probe(
"firstProbe", stapsdt.ArgTypes.uint64, stapsdt.ArgTypes.int32)
provider.load()
while True:
    print("Firing probe...")
    if probe.fire("My little probe", 42):
        print("Probe fired!")
    sleep(1)

We can then trace this via dtrace:

# dtrace -n 'pythonapp503211:::* { printf("args %s, %d\n", copyinstr(arg0), arg1); }'

dtrace: description 'pythonapp503211:::* ' matched 1 probe
CPU     ID                    FUNCTION:NAME
  6 286628                      :firstProbe args My little probe, 42

[1] https://github.com/linux-usdt/libstapsdt

Alan Maguire (4):
  USDT: support ELF-note-defined probes
  selftests/usdt: add test for USDT note-defined probe firing, args
  selftests/usdt: add test for USDT notes in shared library
  selftests/usdt: add test covering different forms of USDT note args

 include/dtrace/pid.h                      |  29 ++
 libdtrace/dt_cg.c                         |  47 ++
 libdtrace/dt_cg.h                         |   1 +
 libdtrace/dt_pid.c                        | 466 ++++++++++++++++++++
 libdtrace/dt_prov_uprobe.c                |  19 +-
 test/unittest/usdt/sdt_notes.h            | 504 ++++++++++++++++++++++
 test/unittest/usdt/tst.usdt-notes-args.r  |   2 +
 test/unittest/usdt/tst.usdt-notes-args.sh |  51 +++
 test/unittest/usdt/tst.usdt-notes-lib.r   |  14 +
 test/unittest/usdt/tst.usdt-notes-lib.sh  | 145 +++++++
 test/unittest/usdt/tst.usdt-notes.r       |  14 +
 test/unittest/usdt/tst.usdt-notes.sh      | 121 ++++++
 12 files changed, 1406 insertions(+), 7 deletions(-)
 create mode 100644 test/unittest/usdt/sdt_notes.h
 create mode 100644 test/unittest/usdt/tst.usdt-notes-args.r
 create mode 100755 test/unittest/usdt/tst.usdt-notes-args.sh
 create mode 100644 test/unittest/usdt/tst.usdt-notes-lib.r
 create mode 100755 test/unittest/usdt/tst.usdt-notes-lib.sh
 create mode 100644 test/unittest/usdt/tst.usdt-notes.r
 create mode 100755 test/unittest/usdt/tst.usdt-notes.sh

-- 
2.43.5




More information about the DTrace-devel mailing list