staticvoid __always_inline trigger_func(int x) { long y = 42;
if (test_usdt0_semaphore)
STAP_PROBE(test, usdt0); if (test_usdt3_semaphore)
STAP_PROBE3(test, usdt3, x, y, &bla); if (test_usdt12_semaphore) {
STAP_PROBE12(test, usdt12,
x, x + 1, y, x + y, 5,
y / 7, bla, &bla, -9, nums[x],
nums[idx], t1.y);
}
}
for (i = 0; i < 12; i++)
ASSERT_EQ(bss->usdt12_arg_sizes[i], usdt12_expected_arg_sizes[i], "usdt12_arg_size");
/* trigger_func() is marked __always_inline, so USDT invocations will be * inlined in two different places, meaning that each USDT will have * at least 2 different places to be attached to. This verifies that * bpf_program__attach_usdt() handles this properly and attaches to * all possible places of USDT invocation.
*/
trigger_func(2);
/* carefully control that we get exactly 100 inlines by preventing inlining */ staticvoid __always_inline f100(int x)
{
STAP_PROBE1(test, usdt_100, x);
}
/* we shouldn't be able to attach to test:usdt2_300 USDT as we don't have as * many slots for specs. It's important that each STAP_PROBE2() invocation * (after untolling) gets different arg spec due to compiler inlining i as * a constant
*/ staticvoid __always_inline f300(int x)
{
STAP_PROBE1(test, usdt_300, x);
}
staticvoid __always_inline f400(int x __attribute__((unused)))
{
STAP_PROBE1(test, usdt_400, 400);
}
/* this time we have 400 different USDT call sites, but they have uniform * argument location, so libbpf's spec string deduplication logic should keep * spec count use very small and so we should be able to attach to all 400 * call sites
*/
__weak void trigger_400_usdts(void)
{
R100(f400, 0);
R100(f400, 100);
R100(f400, 200);
R100(f400, 300);
}
skel = test_usdt__open_and_load(); if (!ASSERT_OK_PTR(skel, "skel_open")) return;
bss = skel->bss;
bss->my_pid = getpid();
err = test_usdt__attach(skel); if (!ASSERT_OK(err, "skel_attach")) goto cleanup;
/* usdt_100 is auto-attached and there are 100 inlined call sites, * let's validate that all of them are properly attached to and * handled from BPF side
*/
trigger_100_usdts();
/* Stress test free spec ID tracking. By default libbpf allows up to * 256 specs to be used, so if we don't return free spec IDs back * after few detachments and re-attachments we should run out of * available spec IDs.
*/ for (i = 0; i < 2; i++) {
bpf_link__destroy(skel->links.usdt_100);
/* Now let's step it up and try to attach USDT that requires more than * 256 attach points with different specs for each. * Note that we need trigger_300_usdts() only to actually have 300 * USDT call sites, we are not going to actually trace them.
*/
trigger_300_usdts();
bpf_link__destroy(skel->links.usdt_100);
bss->usdt_100_called = 0;
bss->usdt_100_sum = 0;
/* If built with arm64/clang, there will be much less number of specs * for usdt_300 call sites.
*/ #if !defined(__aarch64__) || !defined(__clang__) /* we'll reuse usdt_100 BPF program for usdt_300 test */
skel->links.usdt_100 = bpf_program__attach_usdt(skel->progs.usdt_100, -1, "/proc/self/exe", "test", "usdt_300", NULL);
err = -errno; if (!ASSERT_ERR_PTR(skel->links.usdt_100, "usdt_300_bad_attach")) goto cleanup;
ASSERT_EQ(err, -E2BIG, "usdt_300_attach_err");
/* let's check that there are no "dangling" BPF programs attached due * to partial success of the above test:usdt_300 attachment
*/
f300(777); /* this is 301st instance of usdt_300 */
/* This time we have USDT with 400 inlined invocations, but arg specs * should be the same across all sites, so libbpf will only need to * use one spec and thus we'll be able to attach 400 uprobes * successfully. * * Again, we are reusing usdt_100 BPF program.
*/
skel->links.usdt_100 = bpf_program__attach_usdt(skel->progs.usdt_100, -1, "/proc/self/exe", "test", "usdt_400", NULL); if (!ASSERT_OK_PTR(skel->links.usdt_100, "usdt_400_attach")) goto cleanup;
cleanup: if (urand_pipe)
pclose(urand_pipe);
test_urandom_usdt__destroy(skel);
}
void test_usdt(void)
{ if (test__start_subtest("basic"))
subtest_basic_usdt(); if (test__start_subtest("multispec"))
subtest_multispec_usdt(); if (test__start_subtest("urand_auto_attach"))
subtest_urandom_usdt(true/* auto_attach */); if (test__start_subtest("urand_pid_attach"))
subtest_urandom_usdt(false/* auto_attach */);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.