From patchwork Thu Apr 24 21:47:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serhei Makarov X-Patchwork-Id: 110969 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A8CB3858D35 for ; Thu, 24 Apr 2025 21:51:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A8CB3858D35 Authentication-Results: sourceware.org; dkim=temperror header.d=serhei.io header.i=@serhei.io header.a=rsa-sha256 header.s=fm3 header.b=mFrFc1L8; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=BIF7NeE4 X-Original-To: elfutils-devel@sourceware.org Delivered-To: elfutils-devel@sourceware.org Received: from fout-b6-smtp.messagingengine.com (fout-b6-smtp.messagingengine.com [202.12.124.149]) by sourceware.org (Postfix) with ESMTPS id A58643858D37 for ; Thu, 24 Apr 2025 21:48:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A58643858D37 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=serhei.io Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=serhei.io ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A58643858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=202.12.124.149 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745531335; cv=none; b=f3LCDQgMw5/nhKAzbADtzwWgior70TpESsblSo89fcnFPN9fQudHdkjE/ruChDGkjYcXTZxSS25hybEMZRkgoLe8JA4qqzIeaNs1kfS7jclvqBRCnTL7GaUz7YCwSa6pUTe+mY8P4/Fb4Il6jx20IgmDCQT29PPpZSdcftfxv1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1745531335; c=relaxed/simple; bh=u8VEBjo5VY4fWfws3/Pw7o0xsNlICzHxw6a3MriS1z8=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=bpXPOEvHLm6swzlFEBgVofWsDdkLum5Sa12/sXvVZM/nmDphA0SHYfSRPpM3m49st+hc8rqCCK+GNjs2N/fMF9hUVwpuyX8zdSXXnOCZIubtEfH6AAiOG7XNJJaYGnOsk4VnXBG5tGQUoyF4MeMIaT04sltCvQ6ZwwCYLbMSEU8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A58643858D37 Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfout.stl.internal (Postfix) with ESMTP id 351C011401ED; Thu, 24 Apr 2025 17:48:55 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-07.internal (MEProxy); Thu, 24 Apr 2025 17:48:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=serhei.io; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1745531335; x= 1745617735; bh=0fIR9ko7AvCdSiOE3brmLQD/8LR1HtTRgBTO2CwlYKI=; b=m FrFc1L8aRsNwy2wh+VVHORY8Kxx8yXjxuahsX/oVzsljXD9mDbERDB0HFzcu5XYP 6Hqcm3OlfsY0i6yFJOwuAJz4byWMKYBBWnDsuyfBgNp2sgy+8rQaOLmbbyDlPD1Q LSVKbGlpmoj2SquyOIcepYsCyzTvoXy8lUUAzBkcYqLrP67Frj6RniapGfdf2lBd 2yrMGs/Dly+Qrs7gHumbOtCwdzjYrhkAyS6TVF78bUBgyLPnGpMsFDhwbFhzUpM/ vZW5iTOXn3ZDFt3Pw7CvYAk0S8KwAR5LCLdWexjD9ckTngIWKQc4U4zunGKqk8q5 gsZOL124m0pWf0Hwqmjfw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1745531335; x=1745617735; bh=0 fIR9ko7AvCdSiOE3brmLQD/8LR1HtTRgBTO2CwlYKI=; b=BIF7NeE4bbapU+Yp+ LFjUcWAaY3Z/mYpMrrIuJacCoUPFbXomA2KTxFQFoolRBrutBrFWKzM00Uxn3EGa xGtY7aE9eqlM3Wjp+f0pI6AYrHLlSoepxm/h+lo8IJSClLNiyE0Hy/QCcT2mQxHa YdMitxF81K1RauBq1bDoZz3aYOuuE+IAuasC9btbAJLB7NW1LjpYULSqWO/2B0h2 46ru9nJA+C6zX573O0In6XlHN/PjQrqBFXB5EVZMr/7BbogBGYNj9PSgDMImJiP/ dXNh9DeJOvHMdXe5A+hFuZ0WxcEdQhD8vYwQS52IggpWTk0BtEwahhdpok3FXEc7 yN4Tg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvhedtheelucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefuvghrhhgvihcuofgrkhgr rhhovhcuoehsvghrhhgvihesshgvrhhhvghirdhioheqnecuggftrfgrthhtvghrnheptd euudfftdehgfetheehlefghefffeegieekheefgfdufefgudeifefhvefgudeknecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepshgvrhhhvghise hsvghrhhgvihdrihhopdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdp rhgtphhtthhopegvlhhfuhhtihhlshdquggvvhgvlhesshhouhhrtggvfigrrhgvrdhorh hgpdhrtghpthhtohepshgvrhhhvghisehsvghrhhgvihdrihho X-ME-Proxy: Feedback-ID: i572946fc:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 24 Apr 2025 17:48:54 -0400 (EDT) From: Serhei Makarov To: elfutils-devel@sourceware.org Cc: Serhei Makarov Subject: [PATCH v5 10/12] eu-stacktrace [10/12]: use dwflst_tracker_find_pid Date: Thu, 24 Apr 2025 17:47:13 -0400 Message-ID: <20250424214715.306147-11-serhei@serhei.io> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20250424214715.306147-1-serhei@serhei.io> References: <20250424214715.306147-1-serhei@serhei.io> MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: elfutils-devel-bounces~patchwork=sourceware.org@sourceware.org Changes for v4: - Separate out libdwfl_stacktrace, as requested. * * * Initial minimal change to ensure dwflst_tracker_find_pid is tested. For now, we keep the additional dwfltab implementation in stacktrace.c, since it's being used to track statistics. In future follow-ups, it will be good to switch to storing eu-stacktrace statistics e.g. in dwfl->process->callbacks_arg. This requires some additional design to keep the statistics from being lost when a pid is reused and the corresponding processtracker table entry is replaced. * src/stacktrace.c (sysprof_init_dwfl): New function. (sysprof_find_dwfl): Rename the existing sysprof_init_dwfl. Also use dwflst_tracker_find_pid with callback. (sysprof_unwind_cb): Rename the existing sysprof_init_dwfl. --- src/stacktrace.c | 63 +++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/src/stacktrace.c b/src/stacktrace.c index c0c9929d..dd58ef3b 100644 --- a/src/stacktrace.c +++ b/src/stacktrace.c @@ -96,7 +96,7 @@ #include ELFUTILS_HEADER(ebl) /* #include ELFUTILS_HEADER(dwfl) */ #include "../libdwfl/libdwflP.h" -/* XXX: Private header needed for find_procfile, sysprof_init_dwfl, +/* XXX: Private header needed for find_procfile, sysprof_find_dwfl, sample_set_initial_registers. */ #include ELFUTILS_HEADER(dwfl_stacktrace) @@ -1014,7 +1014,34 @@ find_procfile (Dwfl *dwfl, pid_t *pid, Elf **elf, int *elf_fd) } Dwfl * -sysprof_init_dwfl (struct sysprof_unwind_info *sui, +sysprof_init_dwfl (Dwflst_Process_Tracker *cb_tracker, + pid_t pid, + void *arg __attribute__ ((unused))) +{ + Dwfl *dwfl = dwflst_tracker_dwfl_begin (cb_tracker); + + int err = dwfl_linux_proc_report (dwfl, pid); + if (err < 0) + { + if (show_failures) + fprintf(stderr, "dwfl_linux_proc_report pid %lld: %s", + (long long) pid, dwfl_errmsg (-1)); + return NULL; + } + err = dwfl_report_end (dwfl, NULL, NULL); + if (err != 0) + { + if (show_failures) + fprintf(stderr, "dwfl_report_end pid %lld: %s", + (long long) pid, dwfl_errmsg (-1)); + return NULL; + } + + return dwfl; +} + +Dwfl * +sysprof_find_dwfl (struct sysprof_unwind_info *sui, SysprofCaptureStackUser *ev, SysprofCaptureUserRegs *regs) { @@ -1027,42 +1054,24 @@ sysprof_init_dwfl (struct sysprof_unwind_info *sui, if (regs->n_regs < EXPECTED_REGS) /* XXX expecting everything except FLAGS */ { if (show_failures) - fprintf(stderr, N_("sysprof_init_dwfl: n_regs=%d, expected %d\n"), + fprintf(stderr, N_("sysprof_find_dwfl: n_regs=%d, expected %d\n"), regs->n_regs, EXPECTED_REGS); return NULL; } - Dwfl *dwfl = pid_find_dwfl(pid); + Dwfl *dwfl = dwflst_tracker_find_pid (tracker, pid, sysprof_init_dwfl, NULL); struct __sample_arg *sample_arg; bool cached = false; - if (dwfl != NULL) + if (dwfl != NULL && dwfl->process != NULL) { sample_arg = dwfl->process->callbacks_arg; /* XXX requires libdwflP.h */ cached = true; goto reuse; } - dwfl = dwflst_tracker_dwfl_begin (tracker); - - int err = dwfl_linux_proc_report (dwfl, pid); - if (err < 0) - { - if (show_failures) - fprintf(stderr, "dwfl_linux_proc_report pid %lld: %s", - (long long) pid, dwfl_errmsg (-1)); - return NULL; - } - err = dwfl_report_end (dwfl, NULL, NULL); - if (err != 0) - { - if (show_failures) - fprintf(stderr, "dwfl_report_end pid %lld: %s", - (long long) pid, dwfl_errmsg (-1)); - return NULL; - } Elf *elf = NULL; int elf_fd = -1; - err = find_procfile (dwfl, &pid, &elf, &elf_fd); + int err = find_procfile (dwfl, &pid, &elf, &elf_fd); if (err < 0) { if (show_failures) @@ -1099,7 +1108,7 @@ sysprof_init_dwfl (struct sysprof_unwind_info *sui, if (show_frames) { bool is_abi32 = (sample_arg->abi == PERF_SAMPLE_REGS_ABI_32); - fprintf(stderr, "sysprof_init_dwfl pid %lld%s: size=%ld%s pc=%lx sp=%lx+(%lx)\n", + fprintf(stderr, "sysprof_find_dwfl pid %lld%s: size=%ld%s pc=%lx sp=%lx+(%lx)\n", (long long) pid, cached ? " (cached)" : "", sample_arg->size, is_abi32 ? " (32-bit)" : "", sample_arg->pc, sample_arg->base_addr, @@ -1260,7 +1269,7 @@ sysprof_unwind_cb (SysprofCaptureFrame *frame, void *arg) SysprofCaptureUserRegs *regs = (SysprofCaptureUserRegs *)tail_ptr; if (show_frames) fprintf(stderr, "\n"); /* extra newline for padding */ - Dwfl *dwfl = sysprof_init_dwfl (sui, ev, regs); + Dwfl *dwfl = sysprof_find_dwfl (sui, ev, regs); if (dwfl == NULL) { if (show_summary) @@ -1270,7 +1279,7 @@ sysprof_unwind_cb (SysprofCaptureFrame *frame, void *arg) dwfl_ent->lost_samples++; } if (show_failures) - fprintf(stderr, "sysprof_init_dwfl pid %lld (%s) (failed)\n", + fprintf(stderr, "sysprof_find_dwfl pid %lld (%s) (failed)\n", (long long)frame->pid, comm); return SYSPROF_CB_OK; }