Skip to content

Commit 3106151

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 <[email protected]>
1 parent 458514b commit 3106151

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

Lines changed: 40 additions & 0 deletions
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

@@ -196,6 +198,42 @@ static void test_link_api(void)
196198
free(offsets);
197199
}
198200

201+
static void test_bench_attach_uprobe(void)
202+
{
203+
long attach_start_ns, attach_end_ns = 0;
204+
struct uprobe_multi_bench *skel = NULL;
205+
long detach_start_ns, detach_end_ns;
206+
double attach_delta, detach_delta;
207+
int err;
208+
209+
skel = uprobe_multi_bench__open_and_load();
210+
if (!ASSERT_OK_PTR(skel, "uprobe_multi__open"))
211+
goto cleanup;
212+
213+
attach_start_ns = get_time_ns();
214+
215+
err = uprobe_multi_bench__attach(skel);
216+
if (!ASSERT_OK(err, "uprobe_multi__attach"))
217+
goto cleanup;
218+
219+
attach_end_ns = get_time_ns();
220+
221+
system("./uprobe_multi bench");
222+
223+
ASSERT_EQ(skel->bss->count, 50000, "uprobes_count");
224+
225+
cleanup:
226+
detach_start_ns = get_time_ns();
227+
uprobe_multi_bench__destroy(skel);
228+
detach_end_ns = get_time_ns();
229+
230+
attach_delta = (attach_end_ns - attach_start_ns) / 1000000000.0;
231+
detach_delta = (detach_end_ns - detach_start_ns) / 1000000000.0;
232+
233+
printf("%s: attached in %7.3lfs\n", __func__, attach_delta);
234+
printf("%s: detached in %7.3lfs\n", __func__, detach_delta);
235+
}
236+
199237
void test_uprobe_multi_test(void)
200238
{
201239
if (test__start_subtest("skel_api"))
@@ -206,4 +244,6 @@ void test_uprobe_multi_test(void)
206244
test_attach_api_syms();
207245
if (test__start_subtest("link_api"))
208246
test_link_api();
247+
if (test__start_subtest("bench_uprobe"))
248+
test_bench_attach_uprobe();
209249
}
Lines changed: 15 additions & 0 deletions
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)