From f8f230c8162e59202987fb46f2d3d867a5cbef1d Mon Sep 17 00:00:00 2001 From: Fuji Goro Date: Mon, 13 Apr 2020 05:05:21 +0000 Subject: [PATCH] add attribute readers to class USDT (C++ API) --- src/cc/api/BPF.h | 6 ++++++ tests/cc/test_usdt_probes.cc | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/cc/api/BPF.h b/src/cc/api/BPF.h index 85962fa65eb0..9bf31c224f10 100644 --- a/src/cc/api/BPF.h +++ b/src/cc/api/BPF.h @@ -330,6 +330,12 @@ class USDT { USDT(const USDT& usdt); USDT(USDT&& usdt) noexcept; + const std::string &binary_path() const { return binary_path_; } + pid_t pid() const { return pid_; } + const std::string &provider() const { return provider_; } + const std::string &name() const { return name_; } + const std::string &probe_func() const { return probe_func_; } + StatusTuple init(); bool operator==(const USDT& other) const; diff --git a/tests/cc/test_usdt_probes.cc b/tests/cc/test_usdt_probes.cc index 2eb4a94adf84..5652b43f6b1e 100644 --- a/tests/cc/test_usdt_probes.cc +++ b/tests/cc/test_usdt_probes.cc @@ -62,6 +62,16 @@ TEST_CASE("test finding a probe in our own process", "[usdt]") { } } +TEST_CASE("test probe's attributes with C++ API", "[usdt]") { + const ebpf::USDT u("/proc/self/exe", "libbcc_test", "sample_probe_1", "on_event"); + + REQUIRE(u.binary_path() == "/proc/self/exe"); + REQUIRE(u.pid() == -1); + REQUIRE(u.provider() == "libbcc_test"); + REQUIRE(u.name() == "sample_probe_1"); + REQUIRE(u.probe_func() == "on_event"); +} + TEST_CASE("test fine a probe in our own binary with C++ API", "[usdt]") { ebpf::BPF bpf; ebpf::USDT u("/proc/self/exe", "libbcc_test", "sample_probe_1", "on_event");