Skip to content

Commit bb70f76

Browse files
olsajiriKernel Patches Daemon
authored and
Kernel Patches Daemon
committed
selftests/bpf: Add uprobe_multi bench test
Adding test that attaches 50k uprobes in uprobe_multi binary. After the attach is done we run the binary and make sure we get proper amount of hits. The resulting attach/detach times on my setup: test_bench_attach_uprobe:PASS:uprobe_multi__open 0 nsec test_bench_attach_uprobe:PASS:uprobe_multi__attach 0 nsec test_bench_attach_uprobe:PASS:uprobes_count 0 nsec test_bench_attach_uprobe: attached in 0.346s test_bench_attach_uprobe: detached in 0.419s #262/5 uprobe_multi_test/bench_uprobe:OK Signed-off-by: Jiri Olsa <jolsa@kernel.org>
1 parent 1206770 commit bb70f76

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

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

+40
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include <unistd.h>
44
#include <test_progs.h>
55
#include "uprobe_multi.skel.h"
6+
#include "uprobe_multi_bench.skel.h"
67
#include "bpf/libbpf_internal.h"
8+
#include "testing_helpers.h"
79

810
static char test_data[] = "test_data";
911

@@ -197,6 +199,42 @@ static void test_link_api(void)
197199
free(offsets);
198200
}
199201

202+
static void test_bench_attach_uprobe(void)
203+
{
204+
long attach_start_ns = 0, attach_end_ns = 0;
205+
struct uprobe_multi_bench *skel = NULL;
206+
long detach_start_ns, detach_end_ns;
207+
double attach_delta, detach_delta;
208+
int err;
209+
210+
skel = uprobe_multi_bench__open_and_load();
211+
if (!ASSERT_OK_PTR(skel, "uprobe_multi_bench__open_and_load"))
212+
goto cleanup;
213+
214+
attach_start_ns = get_time_ns();
215+
216+
err = uprobe_multi_bench__attach(skel);
217+
if (!ASSERT_OK(err, "uprobe_multi_bench__attach"))
218+
goto cleanup;
219+
220+
attach_end_ns = get_time_ns();
221+
222+
system("./uprobe_multi bench");
223+
224+
ASSERT_EQ(skel->bss->count, 50000, "uprobes_count");
225+
226+
cleanup:
227+
detach_start_ns = get_time_ns();
228+
uprobe_multi_bench__destroy(skel);
229+
detach_end_ns = get_time_ns();
230+
231+
attach_delta = (attach_end_ns - attach_start_ns) / 1000000000.0;
232+
detach_delta = (detach_end_ns - detach_start_ns) / 1000000000.0;
233+
234+
printf("%s: attached in %7.3lfs\n", __func__, attach_delta);
235+
printf("%s: detached in %7.3lfs\n", __func__, detach_delta);
236+
}
237+
200238
void test_uprobe_multi_test(void)
201239
{
202240
if (test__start_subtest("skel_api"))
@@ -207,4 +245,6 @@ void test_uprobe_multi_test(void)
207245
test_attach_api_syms();
208246
if (test__start_subtest("link_api"))
209247
test_link_api();
248+
if (test__start_subtest("bench_uprobe"))
249+
test_bench_attach_uprobe();
210250
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
#include <linux/bpf.h>
3+
#include <bpf/bpf_helpers.h>
4+
#include <bpf/bpf_tracing.h>
5+
6+
char _license[] SEC("license") = "GPL";
7+
8+
int count;
9+
10+
SEC("uprobe.multi/./uprobe_multi:uprobe_multi_func_*")
11+
int uprobe_bench(struct pt_regs *ctx)
12+
{
13+
count++;
14+
return 0;
15+
}

0 commit comments

Comments
 (0)