Skip to content

Commit

Permalink
Edit perf_event cc and python tests with pid argument
Browse files Browse the repository at this point in the history
  • Loading branch information
0x161e-swei authored and yonghong-song committed Jul 30, 2023
1 parent 3360c79 commit 612399d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tests/cc/test_perf_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ TEST_CASE("test read perf event", "[bpf_perf_event]") {
BPF_PROGRAM,
{"-DNUM_CPUS=" + std::to_string(sysconf(_SC_NPROCESSORS_ONLN))}, {});
REQUIRE(res.ok());
int pid = getpid();
res =
bpf.open_perf_event("cnt", PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK);
bpf.open_perf_event("cnt", PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK, pid);
REQUIRE(res.ok());
std::string getuid_fnname = bpf.get_syscall_fnname("getuid");
res = bpf.attach_kprobe(getuid_fnname, "on_sys_getuid");
Expand Down
4 changes: 3 additions & 1 deletion tests/python/test_perf_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ def test_cycles(self):
return 0;
}
"""
mypid = os.getpid()
b = bcc.BPF(text=text, debug=0,
cflags=["-DNUM_CPUS=%d" % multiprocessing.cpu_count()])
event_name = b.get_syscall_fnname(b"getuid")
b.attach_kprobe(event=event_name, fn_name=b"do_sys_getuid")
b.attach_kretprobe(event=event_name, fn_name=b"do_ret_sys_getuid")
cnt1 = b[b"cnt1"]
try:
cnt1.open_perf_event(bcc.PerfType.HARDWARE, bcc.PerfHWConfig.CPU_CYCLES)
cnt1.open_perf_event(bcc.PerfType.HARDWARE,
bcc.PerfHWConfig.CPU_CYCLES, pid=mypid)
except:
if ctypes.get_errno() == 2:
raise self.skipTest("hardware events unsupported")
Expand Down

0 comments on commit 612399d

Please sign in to comment.