Skip to content

Commit

Permalink
add attribute readers to class USDT (C++ API)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfx authored and yonghong-song committed Apr 19, 2020
1 parent 7a38543 commit f8f230c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cc/api/BPF.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions tests/cc/test_usdt_probes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit f8f230c

Please sign in to comment.