Skip to content

Commit c5fbdad

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 d5c64e4 commit c5fbdad

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <test_progs.h>
55
#include "uprobe_multi.skel.h"
66
#include "bpf/libbpf_internal.h"
7+
#include "uprobe_multi_usdt.skel.h"
78

89
static char test_data[] = "test_data";
910

@@ -256,6 +257,53 @@ static void test_bench_attach_uprobe(void)
256257
printf("%s: detached in %7.3lfs\n", __func__, detach_delta);
257258
}
258259

260+
static void test_bench_attach_usdt(void)
261+
{
262+
struct uprobe_multi_usdt *skel = NULL;
263+
long attach_start_ns, attach_end_ns;
264+
long detach_start_ns, detach_end_ns;
265+
double attach_delta, detach_delta;
266+
struct bpf_program *prog;
267+
int err;
268+
269+
skel = uprobe_multi_usdt__open();
270+
if (!ASSERT_OK_PTR(skel, "uprobe_multi__open"))
271+
goto cleanup;
272+
273+
bpf_object__for_each_program(prog, skel->obj)
274+
bpf_program__set_autoload(prog, false);
275+
276+
bpf_program__set_autoload(skel->progs.usdt0, true);
277+
278+
err = uprobe_multi_usdt__load(skel);
279+
if (!ASSERT_EQ(err, 0, "uprobe_multi_usdt__load"))
280+
goto cleanup;
281+
282+
attach_start_ns = get_time_ns();
283+
284+
skel->links.usdt0 = bpf_program__attach_usdt(skel->progs.usdt0, -1, "./usdt_multi",
285+
"test", "usdt", NULL);
286+
if (!ASSERT_OK_PTR(skel->links.usdt0, "bpf_program__attach_usdt"))
287+
goto cleanup;
288+
289+
attach_end_ns = get_time_ns();
290+
291+
system("./usdt_multi");
292+
293+
ASSERT_EQ(skel->bss->count, 50000, "usdt_count");
294+
295+
cleanup:
296+
detach_start_ns = get_time_ns();
297+
uprobe_multi_usdt__destroy(skel);
298+
detach_end_ns = get_time_ns();
299+
300+
attach_delta = (attach_end_ns - attach_start_ns) / 1000000000.0;
301+
detach_delta = (detach_end_ns - detach_start_ns) / 1000000000.0;
302+
303+
printf("%s: attached in %7.3lfs\n", __func__, attach_delta);
304+
printf("%s: detached in %7.3lfs\n", __func__, detach_delta);
305+
}
306+
259307
void test_uprobe_multi_test(void)
260308
{
261309
if (test__start_subtest("skel_api"))
@@ -268,4 +316,6 @@ void test_uprobe_multi_test(void)
268316
test_link_api();
269317
if (test__start_subtest("bench_uprobe"))
270318
test_bench_attach_uprobe();
319+
if (test__start_subtest("bench_usdt"))
320+
test_bench_attach_usdt();
271321
}
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)