Skip to content

Commit bb16195

Browse files
olsajiriKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
selftests/bpf: Add usdt_multi bench test
Adding test that attaches 50k usdt probes in usdt_multi binary. After the attach is done we run the binary and make sure we get proper amount of hits. With current uprobes: # perf stat --null ./test_progs -n 254/6 #254/6 uprobe_multi_test/bench_usdt:OK #254 uprobe_multi_test:OK Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED Performance counter stats for './test_progs -n 254/6': 1353.659680562 seconds time elapsed With uprobe_multi link: # perf stat --null ./test_progs -n 254/6 #254/6 uprobe_multi_test/bench_usdt:OK #254 uprobe_multi_test:OK Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED Performance counter stats for './test_progs -n 254/6': 0.322046364 seconds time elapsed Signed-off-by: Jiri Olsa <[email protected]>
1 parent e6f164c commit bb16195

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <unistd.h>
44
#include <test_progs.h>
55
#include "uprobe_multi.skel.h"
6+
#include "uprobe_multi_usdt.skel.h"
67

78
noinline void uprobe_multi_func_1(void)
89
{
@@ -217,6 +218,57 @@ void test_bench_attach_uprobe(void)
217218
printf("%s: detached in %7.3lfs\n", __func__, detach_delta);
218219
}
219220

221+
void test_bench_attach_usdt(void)
222+
{
223+
struct uprobe_multi_usdt *skel = NULL;
224+
long attach_start_ns, attach_end_ns;
225+
long detach_start_ns, detach_end_ns;
226+
double attach_delta, detach_delta;
227+
LIBBPF_OPTS(bpf_usdt_opts, opts,
228+
.uprobe_multi = true,
229+
);
230+
struct bpf_program *prog;
231+
int err;
232+
233+
skel = uprobe_multi_usdt__open();
234+
if (!ASSERT_OK_PTR(skel, "uprobe_multi__open"))
235+
goto cleanup;
236+
237+
bpf_object__for_each_program(prog, skel->obj)
238+
bpf_program__set_autoload(prog, false);
239+
240+
bpf_program__set_autoload(skel->progs.usdt0, true);
241+
bpf_program__set_expected_attach_type(skel->progs.usdt0, BPF_TRACE_UPROBE_MULTI);
242+
243+
err = uprobe_multi_usdt__load(skel);
244+
if (!ASSERT_EQ(err, 0, "strncmp_test load"))
245+
goto cleanup;
246+
247+
attach_start_ns = get_time_ns();
248+
249+
skel->links.usdt0 = bpf_program__attach_usdt(skel->progs.usdt0, -1, "./usdt_multi",
250+
"test", "usdt", &opts);
251+
if (!ASSERT_OK_PTR(skel->links.usdt0, "usdt_link"))
252+
goto cleanup;
253+
254+
attach_end_ns = get_time_ns();
255+
256+
system("./usdt_multi");
257+
258+
ASSERT_EQ(skel->bss->count, 50000, "usdt_count");
259+
260+
cleanup:
261+
detach_start_ns = get_time_ns();
262+
uprobe_multi_usdt__destroy(skel);
263+
detach_end_ns = get_time_ns();
264+
265+
attach_delta = (attach_end_ns - attach_start_ns) / 1000000000.0;
266+
detach_delta = (detach_end_ns - detach_start_ns) / 1000000000.0;
267+
268+
printf("%s: attached in %7.3lfs\n", __func__, attach_delta);
269+
printf("%s: detached in %7.3lfs\n", __func__, detach_delta);
270+
}
271+
220272
void test_uprobe_multi_test(void)
221273
{
222274
if (test__start_subtest("skel_api"))
@@ -229,4 +281,6 @@ void test_uprobe_multi_test(void)
229281
test_link_api();
230282
if (test__start_subtest("bench_uprobe"))
231283
test_bench_attach_uprobe();
284+
if (test__start_subtest("bench_usdt"))
285+
test_bench_attach_usdt();
232286
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include "vmlinux.h"
4+
#include <bpf/bpf_helpers.h>
5+
#include <bpf/usdt.bpf.h>
6+
7+
char _license[] SEC("license") = "GPL";
8+
9+
int count;
10+
11+
SEC("usdt")
12+
int usdt0(struct pt_regs *ctx)
13+
{
14+
count++;
15+
return 0;
16+
}

0 commit comments

Comments
 (0)