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 *inlinedintwodifferentplaces,meaningthateachUSDTwillhave *atleast2differentplacestobeattachedto.Thisverifiesthat *bpf_program__attach_usdt()handlesthisproperlyandattachesto *allpossibleplacesofUSDTinvocation.
*/
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 *manyslotsforspecs.It'simportantthateachSTAP_PROBE2()invocation *(afteruntolling)getsdifferentargspecduetocompilerinliningias *aconstant
*/ 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 *argumentlocation,solibbpf'sspecstringdeduplicationlogicshouldkeep *speccountuseverysmallandsoweshouldbeabletoattachtoall400 *callsites
*/
__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'svalidatethatallofthemareproperlyattachedtoand *handledfromBPFside
*/
trigger_100_usdts();
/* Stress test free spec ID tracking. By default libbpf allows up to *256specstobeused,soifwedon'treturnfreespecIDsback *afterfewdetachmentsandre-attachmentsweshouldrunoutof *availablespecIDs.
*/ 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 *256attachpointswithdifferentspecsforeach. *Notethatweneedtrigger_300_usdts()onlytoactuallyhave300 *USDTcallsites,wearenotgoingtoactuallytracethem.
*/
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 *forusdt_300callsites.
*/ #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 *topartialsuccessoftheabovetest:usdt_300attachment
*/
f300(777); /* this is 301st instance of usdt_300 */
/* This time we have USDT with 400 inlined invocations, but arg specs *shouldbethesameacrossallsites,solibbpfwillonlyneedto *useonespecandthuswe'llbeabletoattach400uprobes *successfully. * *Again,wearereusingusdt_100BPFprogram.
*/
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 */);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet am 2026-10-12)
¤
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.