From unknown Mon Jun 16 23:50:13 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#78762 <78762@debbugs.gnu.org> To: bug#78762 <78762@debbugs.gnu.org> Subject: Status: [PATCH] Fix segfault in profiler-cpu-log and profiler-memory-log Reply-To: bug#78762 <78762@debbugs.gnu.org> Date: Tue, 17 Jun 2025 06:50:13 +0000 retitle 78762 [PATCH] Fix segfault in profiler-cpu-log and profiler-memory-= log reassign 78762 emacs submitter 78762 Zach Shaftel severity 78762 normal tag 78762 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Wed Jun 11 16:03:40 2025 Received: (at submit) by debbugs.gnu.org; 11 Jun 2025 20:03:40 +0000 Received: from localhost ([127.0.0.1]:51841 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uPRfg-0006X4-4T for submit@debbugs.gnu.org; Wed, 11 Jun 2025 16:03:40 -0400 Received: from lists.gnu.org ([2001:470:142::17]:56112) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uPRfd-0006Wp-1J for submit@debbugs.gnu.org; Wed, 11 Jun 2025 16:03:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPRfV-0007bX-G2 for bug-gnu-emacs@gnu.org; Wed, 11 Jun 2025 16:03:30 -0400 Received: from smtp.forwardemail.net ([121.127.44.73]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1uPRfR-0005Lj-S4 for bug-gnu-emacs@gnu.org; Wed, 11 Jun 2025 16:03:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shaf.tel; h=Content-Type: MIME-Version: Message-ID: Date: Subject: To: From; q=dns/txt; s=fe-acc5b42812; t=1749672199; bh=cq47yB3ruDnE6qu3+MTj426muv/zuldOT2DwQ28JkLM=; b=JbM3/FofjjB6R2ONKA73RErk4oEDjW2R8L0Mh4wpxvM0KL7J63gwnmYRHI0mj1UxhgErn3NXk rEGX0/DQ0/ckyYE/PtfOLWIIrjBxM2wAEJZvmDmren5nag1la/HCrX5O641EhNGBLtqTk/HBJru f7i086GM/jYGKT+oO6JL42Y= X-Forward-Email-ID: 6849e10475444c2c8fae6b1d X-Forward-Email-Sender: rfc822; zach@shaf.tel, smtp.forwardemail.net, 121.127.44.73 X-Forward-Email-Version: 1.0.3 X-Forward-Email-Website: https://forwardemail.net X-Complaints-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Report-Abuse-To: abuse@forwardemail.net From: Zach Shaftel To: bug-gnu-emacs@gnu.org Subject: [PATCH] Fix segfault in profiler-cpu-log and profiler-memory-log User-Agent: mu4e 1.12.10; emacs 31.0.50 X-Debbugs-Cc: Date: Wed, 11 Jun 2025 16:03:12 -0400 Message-ID: <87v7p2xczj.fsf@shaf.tel> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=121.127.44.73; envelope-from=SRS0=ba03=Y3=shaf.tel=zach@fe-bounces.shaf.tel; helo=smtp.forwardemail.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 0.9 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.1 (/) --=-=-= Content-Type: text/plain Tags: patch a simple NULL dereference fix. the profiler log would be null if profiler-*-log is called without a profiler-*-start before it, or if a previous profiler-*-log call had flushed the log and the profiler wasn't restarted since then. then export_log would try to read the NULL log and segfault. to reproduce the bug: emacs --batch -f profiler-cpu-log this patch causes profiler-cpu-log and profiler-memory-log to just return nil if the log is null. In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.49, cairo version 1.18.4) of 2025-06-04 built on bigbox Repository revision: 680fa61b5989b84c0e19ac568be012afd8345f0c Repository branch: master System Description: Arch Linux Configured using: 'configure --with-modules --without-xwidgets --with-native-compilation --with-tree-sitter --without-gsettings --without-gconf --without-gpm --with-pgtk --without-compress-install 'CFLAGS=-mtune=native -march=native -O2 -g -fuse-ld=mold'' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Fix-segfault-in-profiler-cpu-log-and-profiler-memory.patch >From 2c1b3bc8b020acbef496dd991bd08bc0f5505528 Mon Sep 17 00:00:00 2001 From: Zach Shaftel Date: Wed, 11 Jun 2025 15:37:31 -0400 Subject: [PATCH] Fix segfault in profiler-cpu-log and profiler-memory-log * src/profiler.c (export_log): Check if a log has been allocated first, and return nil if it hasn't. (Fprofiler_cpu_log, Fprofiler_memory_log): Mention the possibly nil result. --- src/profiler.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/profiler.c b/src/profiler.c index 12d75012c79..816864e940e 100644 --- a/src/profiler.c +++ b/src/profiler.c @@ -534,7 +534,11 @@ DEFUN ("profiler-cpu-log", Fprofiler_cpu_log, Sprofiler_cpu_log, The log is a hash-table mapping backtraces to counters which represent the amount of time spent at those points. Every backtrace is a vector of functions, where the last few elements may be nil. -Before returning, a new log is allocated for future samples. */) + +If the profiler has not run since the last invocation of +`profiler-cpu-log' (or was never run at all), nil is returned. If the +profiler is currently running, a new log is allocated for future samples +before returning. */) (void) { /* Temporarily stop profiling to avoid it interfering with our data @@ -556,6 +560,9 @@ DEFUN ("profiler-cpu-log", Fprofiler_cpu_log, Sprofiler_cpu_log, static Lisp_Object export_log (struct profiler_log *plog) { + if (plog->log == NULL) + /* We haven't collected any new data, so return nil. */ + return Qnil; log_t *log = plog->log; /* The returned hash table uses `equal' as key equivalence predicate which is more discriminating than the `function-equal' used by @@ -639,7 +646,11 @@ DEFUN ("profiler-memory-log", The log is a hash-table mapping backtraces to counters which represent the amount of memory allocated at those points. Every backtrace is a vector of functions, where the last few elements may be nil. -Before returning, a new log is allocated for future samples. */) + +If the profiler has not run since the last invocation of +`profiler-memory-log' (or was never run at all), nil is returned. If +the profiler is currently running, a new log is allocated for future +samples before returning. */) (void) { bool prof_mem = profiler_memory_running; -- 2.49.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Thu Jun 12 01:03:29 2025 Received: (at 78762) by debbugs.gnu.org; 12 Jun 2025 05:03:29 +0000 Received: from localhost ([127.0.0.1]:55061 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uPa64-0002bs-1g for submit@debbugs.gnu.org; Thu, 12 Jun 2025 01:03:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35648) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uPa61-0002bS-2W for 78762@debbugs.gnu.org; Thu, 12 Jun 2025 01:03:25 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPa5v-000620-9d; Thu, 12 Jun 2025 01:03:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=fdAVT4dcncrpcDTlUhvGoGmhEk+DL3OBQOLTscmJyJE=; b=G8AYZXcgc7Ej 0Z9lZvdNloVqTw0uie3a1B4/AWyV8/UG6zwyJGs1PTGesD537g9POnlfVY9W4cdxN0HPsq8FvY+Ie AV9aoKlkYBZuHDNXRj1Tks8aBXCFz6h+kjcEg03itMlnT8KgBylDGRDZ0xvqidT4fMdtKbSsmm70Z z5FIHXNWDfM0NvXCrA0WKHwathz1kmKJahxfpDkgPQECXHk6LQItjlGICisGSbY59aK9Mk+8dG1zz Iy2iWoyiZfoUothZ/uXp4dhMXJKl+zJF7M+OgjXAWs11GwneC37ntfo0Tfwx7Bw0seZIt+jGxyfUs fUJ27rmA8+6m3UhHfmVtvg==; Date: Thu, 12 Jun 2025 08:03:10 +0300 Message-Id: <86ikl1h7qp.fsf@gnu.org> From: Eli Zaretskii To: Zach Shaftel In-Reply-To: <87v7p2xczj.fsf@shaf.tel> (bug-gnu-emacs@gnu.org) Subject: Re: bug#78762: [PATCH] Fix segfault in profiler-cpu-log and profiler-memory-log References: <87v7p2xczj.fsf@shaf.tel> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 78762 Cc: 78762@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Date: Wed, 11 Jun 2025 16:03:12 -0400 > From: Zach Shaftel via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" > > a simple NULL dereference fix. the profiler log would be null if > profiler-*-log is called without a profiler-*-start before it, or if a > previous profiler-*-log call had flushed the log and the profiler wasn't > restarted since then. then export_log would try to read the NULL log and > segfault. > > to reproduce the bug: > emacs --batch -f profiler-cpu-log > > this patch causes profiler-cpu-log and profiler-memory-log to just > return nil if the log is null. Thanks, please see a few minor comments below. > >From 2c1b3bc8b020acbef496dd991bd08bc0f5505528 Mon Sep 17 00:00:00 2001 > From: Zach Shaftel > Date: Wed, 11 Jun 2025 15:37:31 -0400 > Subject: [PATCH] Fix segfault in profiler-cpu-log and profiler-memory-log > > * src/profiler.c (export_log): Check if a log has been allocated first, > and return nil if it hasn't. > (Fprofiler_cpu_log, Fprofiler_memory_log): Mention the possibly nil > result. The last sentence should say "...in the doc string." Or just "Doc fix" should be enough, since the nature of the change is clear from the diffs. Also, in the next revisions of the patch mention the bug number in the commit log message, since you now know its number. > @@ -534,7 +534,11 @@ DEFUN ("profiler-cpu-log", Fprofiler_cpu_log, Sprofiler_cpu_log, > The log is a hash-table mapping backtraces to counters which represent > the amount of time spent at those points. Every backtrace is a vector > of functions, where the last few elements may be nil. > -Before returning, a new log is allocated for future samples. */) > + > +If the profiler has not run since the last invocation of > +`profiler-cpu-log' (or was never run at all), nil is returned. If the > +profiler is currently running, a new log is allocated for future samples > +before returning. */) Please avoid passive tense as much as possible. Here, "return nil" and "allocate a new log" is shorter and more clear. > + if (plog->log == NULL) We usually prefer the C style: if (!plog->log) > + /* We haven't collected any new data, so return nil. */ > + return Qnil; No need to add comments that just describe what the code already says. Comments which explain what the code does should tell something that isn't clear by just looking at the code. > @@ -639,7 +646,11 @@ DEFUN ("profiler-memory-log", > The log is a hash-table mapping backtraces to counters which represent > the amount of memory allocated at those points. Every backtrace is a vector > of functions, where the last few elements may be nil. > -Before returning, a new log is allocated for future samples. */) > + > +If the profiler has not run since the last invocation of > +`profiler-memory-log' (or was never run at all), nil is returned. If > +the profiler is currently running, a new log is allocated for future > +samples before returning. */) Same comment as above for the other doc string. Also, can you add a test for this? Finally, the same problem exists on the emacs-30 release branch, so could you please post your next revision of the patch relative to the release branch? From debbugs-submit-bounces@debbugs.gnu.org Thu Jun 12 01:07:45 2025 Received: (at control) by debbugs.gnu.org; 12 Jun 2025 05:07:45 +0000 Received: from localhost ([127.0.0.1]:55085 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uPaAD-00030y-81 for submit@debbugs.gnu.org; Thu, 12 Jun 2025 01:07:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47988) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uPaAA-00030P-1o; Thu, 12 Jun 2025 01:07:42 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uPaA4-0006dh-FM; Thu, 12 Jun 2025 01:07:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=DSkDdp6nKrlwigBZ0J/21ClShcJNq7Y/4YNB9Wr+dAQ=; b=Jc4uvYFIS32G vBWElBPV35184CNM4NxA003QHHiS+6DBJQY7JIt+D+wr/icvwYbswYtTIvir9urAB57EXjWKyr8jd 6aGo7TIaS8BufwuRJc7xZPTar2W/GqidkqZzTintTnvpg+sGmU8MNSMkO7HcIFO/rmCqqj1TOJFiw gS7QoBeh4oTaRxZ9qilu8d883lhZDH6ZPqJ39BiDoUP6BHxjT1B3bz0yjUnznK34fGbtZanb/k2eL Ss4jVFhY3ynEXsohl73RBk6S7ImqSfcFf/D2KkuW3yu5sPczou7s+DJVBlp3ni+ifQJ/MbADh91lm HMI/+mhoEwYCtWGsUyAwpg==; Date: Thu, 12 Jun 2025 08:07:32 +0300 Message-Id: <86h60lh7jf.fsf@gnu.org> From: Eli Zaretskii To: Aaron Zeng , Zach Shaftel In-Reply-To: (bug-gnu-emacs@gnu.org) Subject: Re: bug#78763: 30.0.50; Calling (profiler-cpu-log) segfaults Emacs if profiler is not running References: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: control Cc: app-emacs-dev@janestreet.com, 78763@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) merge 78763 78762 thanks > Cc: app-emacs-dev@janestreet.com > Date: Wed, 11 Jun 2025 17:03:04 -0400 > From: Aaron Zeng via "Bug reports for GNU Emacs, > the Swiss army knife of text editors" > > As of commit 22201dde773e5404f80baa1f59768e88d97a322a, calling > (profiler-cpu-log) while the CPU profiler is not running causes Emacs to > crash with a segfault. I have confirmed this issue also appears at > f69b822fb0e804a13ff7a4eb55fc2ae618e0de72, which was the tip of the > master branch at the time of writing. > > To reproduce, simply run: > $ emacs -Q --batch --eval '(profiler-cpu-log)' > > The gdb backtrace is attached to this email. Thanks, this is the same problem as in bug#78762, so I've merged them. From debbugs-submit-bounces@debbugs.gnu.org Thu Jun 12 22:11:56 2025 Received: (at 78762) by debbugs.gnu.org; 13 Jun 2025 02:11:56 +0000 Received: from localhost ([127.0.0.1]:34004 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uPttZ-0002tK-GW for submit@debbugs.gnu.org; Thu, 12 Jun 2025 22:11:56 -0400 Received: from smtp.forwardemail.net ([149.28.215.223]:20691) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1uPttU-0002rJ-56 for 78762@debbugs.gnu.org; Thu, 12 Jun 2025 22:11:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shaf.tel; h=Content-Type: MIME-Version: Message-ID: Date: References: In-Reply-To: Subject: Cc: To: From; q=dns/txt; s=fe-acc5b42812; t=1749780704; bh=32xxm1LI8qEy9MxST7SIgefSTqMD8ABdsWeYCSRjxeI=; b=EFDVfIORO/70j5P0LM5ZPJo+gGEqZ/XaRHB6ZTrMCo/7k/1fUmYx9qWT+UZU7vsSXZvytSTgH PTRM4Qn0ydYgB6yB+vU88+TdTRRG68mNSJZNo++fr26/irqo6GafBxUyk9GK+c2X2hGNwJV6asV uYk4xKJfNwaeTAm9dwi3oaM= X-Forward-Email-ID: 684b88dce8fc3b2af7a2b941 X-Forward-Email-Sender: rfc822; zach@shaf.tel, smtp.forwardemail.net, 149.28.215.223 X-Forward-Email-Version: 1.0.3 X-Forward-Email-Website: https://forwardemail.net X-Complaints-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Report-Abuse-To: abuse@forwardemail.net From: zach shaftel To: Eli Zaretskii Subject: Re: bug#78762: [PATCH] Fix segfault in profiler-cpu-log and profiler-memory-log In-Reply-To: <86ikl1h7qp.fsf@gnu.org> References: <87v7p2xczj.fsf@shaf.tel> <86ikl1h7qp.fsf@gnu.org> User-Agent: mu4e 1.12.10; emacs 31.0.50 Date: Thu, 12 Jun 2025 22:11:36 -0400 Message-ID: <87zfecpezr.fsf@shaf.tel> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 78762 Cc: 78762@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain thank you for the feedback, a new patch is attached. let me know if i missed anything. - zach --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Fix-segfault-in-profiler-cpu-log-and-profiler-memory.patch >From b90a79d7b9845cf39a124648cc860bd7f48d858d Mon Sep 17 00:00:00 2001 From: Zach Shaftel Date: Wed, 11 Jun 2025 15:37:31 -0400 Subject: [PATCH] Fix segfault in profiler-cpu-log and profiler-memory-log (bug#78763) * src/profiler.c (export_log): Check if a log has been allocated first, and return nil if it hasn't. (Fprofiler_cpu_log, Fprofiler_memory_log): Doc fix. * test/src/profiler-tests.el (profiler-tests-cpu-profiler) (profiler-tests-memory-profiler): New tests. --- src/profiler.c | 13 +++++++-- test/src/profiler-tests.el | 58 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 test/src/profiler-tests.el diff --git a/src/profiler.c b/src/profiler.c index 4c88f676fbd..f3a8db69f78 100644 --- a/src/profiler.c +++ b/src/profiler.c @@ -534,7 +534,11 @@ DEFUN ("profiler-cpu-log", Fprofiler_cpu_log, Sprofiler_cpu_log, The log is a hash-table mapping backtraces to counters which represent the amount of time spent at those points. Every backtrace is a vector of functions, where the last few elements may be nil. -Before returning, a new log is allocated for future samples. */) + +If the profiler has not run since the last invocation of +`profiler-cpu-log' (or was never run at all), return nil. If the +profiler is currently running, allocate a new log for future samples +before returning. */) (void) { /* Temporarily stop profiling to avoid it interfering with our data @@ -556,6 +560,7 @@ DEFUN ("profiler-cpu-log", Fprofiler_cpu_log, Sprofiler_cpu_log, static Lisp_Object export_log (struct profiler_log *plog) { + if (!plog->log) return Qnil; log_t *log = plog->log; /* The returned hash table uses `equal' as key equivalence predicate which is more discriminating than the `function-equal' used by @@ -639,7 +644,11 @@ DEFUN ("profiler-memory-log", The log is a hash-table mapping backtraces to counters which represent the amount of memory allocated at those points. Every backtrace is a vector of functions, where the last few elements may be nil. -Before returning, a new log is allocated for future samples. */) + +If the profiler has not run since the last invocation of +`profiler-memory-log' (or was never run at all), return nil. If the +profiler is currently running, allocate a new log for future samples +before returning. */) (void) { bool prof_mem = profiler_memory_running; diff --git a/test/src/profiler-tests.el b/test/src/profiler-tests.el new file mode 100644 index 00000000000..fe50de713e2 --- /dev/null +++ b/test/src/profiler-tests.el @@ -0,0 +1,58 @@ +;;; profiler-tests.el --- tests for src/profiler.c -*- lexical-binding:t -*- + +;; Copyright (C) 2025 Free Software Foundation, Inc. + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: + +;;; Code: + +(require 'ert) + +(ert-deftest profiler-tests-memory-profiler () + (let ((was-running (profiler-memory-running-p))) + ;; do this first in case the profiler was already running + (should (eq was-running (profiler-memory-stop))) + (profiler-memory-start) + (should-error (profiler-memory-start)) + (should (profiler-memory-running-p)) + (should (hash-table-p (profiler-memory-log))) + ;; `profiler-memory-log' shouldn't terminate profiling. + (should (profiler-memory-running-p)) + (profiler-memory-stop) + (profiler-memory-log) ;flush the log + (should-not (profiler-memory-log)) + (when was-running (profiler-memory-start)))) + +(defconst profiler-tests-cpu-sampling-interval 1000000) + +(ert-deftest profiler-tests-cpu-profiler () + (skip-unless (fboundp 'profiler-cpu-start)) + (let ((was-running (profiler-cpu-running-p))) + (should (eq was-running (profiler-cpu-stop))) + (profiler-cpu-start profiler-tests-cpu-sampling-interval) + (should-error (profiler-cpu-start profiler-tests-cpu-sampling-interval)) + (should (hash-table-p (profiler-cpu-log))) + (should (profiler-cpu-running-p)) + (profiler-cpu-stop) + (profiler-cpu-log) + (should-not (profiler-cpu-log)) + (when was-running + (profiler-cpu-start (or (bound-and-true-p profiler-sampling-interval) + profiler-tests-cpu-sampling-interval))))) + +;;; profiler-tests.el ends here -- 2.49.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Jun 14 10:57:10 2025 Received: (at 78762-done) by debbugs.gnu.org; 14 Jun 2025 14:57:10 +0000 Received: from localhost ([127.0.0.1]:40225 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uQSJg-00017b-K1 for submit@debbugs.gnu.org; Sat, 14 Jun 2025 10:57:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47690) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uQSJc-000168-KY for 78762-done@debbugs.gnu.org; Sat, 14 Jun 2025 10:57:05 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uQSJW-0002re-UX; Sat, 14 Jun 2025 10:56:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=GN9eDE7gq6iS/1mXOTgU2gAGnYP2B/SU+2JqhVc3fdQ=; b=DcL6Tkd4CY0g phFCBP0vL1jTnDBE6SCLRVHVocyT1vISGJv2SavsDxbUx49HGlYjkY8W5FGOTIrXEGGc6NEAq7r96 DewJ6JY77Kn9hON8b4cly7R9ewnDHt24PTqa29cxdLTJmtsumxZCBO3k4YQLldvHJGooJ+N1rWTNN uLrp760Ki5Srw21WaFO2xDJjtKST4tFU9LzbYysm7VCGrmFFZZiLLxKp3qlprRcCiK7gCMkzH5+G1 upb0i6ML5vTWgtlYxi59w1VrVyc5ZGJGlTVOp0YzJzydH74h4uz215UuVNLxKZUTN9miWKOp0fsXM QP7UGy52pJtoU45qEdi76Q==; Date: Sat, 14 Jun 2025 17:56:58 +0300 Message-Id: <86v7oyqslh.fsf@gnu.org> From: Eli Zaretskii To: zach shaftel In-Reply-To: <87zfecpezr.fsf@shaf.tel> (message from zach shaftel on Thu, 12 Jun 2025 22:11:36 -0400) Subject: Re: bug#78762: [PATCH] Fix segfault in profiler-cpu-log and profiler-memory-log References: <87v7p2xczj.fsf@shaf.tel> <86ikl1h7qp.fsf@gnu.org> <87zfecpezr.fsf@shaf.tel> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 78762-done Cc: 78762-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: zach shaftel > Cc: 78762@debbugs.gnu.org > Date: Thu, 12 Jun 2025 22:11:36 -0400 > > thank you for the feedback, a new patch is attached. let me know if i > missed anything. Thanks, installed on master, and closing the bug. From debbugs-submit-bounces@debbugs.gnu.org Mon Jun 16 14:57:37 2025 Received: (at 78762) by debbugs.gnu.org; 16 Jun 2025 18:57:38 +0000 Received: from localhost ([127.0.0.1]:48818 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1uRF1T-0003MF-L2 for submit@debbugs.gnu.org; Mon, 16 Jun 2025 14:57:37 -0400 Received: from mxout5.mail.janestreet.com ([64.215.233.18]:41647) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1uRF1P-0003Kz-LE for 78762@debbugs.gnu.org; Mon, 16 Jun 2025 14:57:32 -0400 From: Spencer Baugh To: help-debbugs@gnu.org (GNU bug Tracking System) Subject: Re: bug#78762: closed (Re: bug#78762: [PATCH] Fix segfault in profiler-cpu-log and profiler-memory-log), Re: bug#78762: [PATCH] Fix segfault in profiler-cpu-log and profiler-memory-log, [PATCH] Fix segfault in profiler-cpu-log and profiler-memory-log In-Reply-To: (GNU bug Tracking System's message of "Sat, 14 Jun 2025 14:58:02 +0000") References: <86v7oyqslh.fsf@gnu.org> <87v7p2xczj.fsf@shaf.tel> Date: Mon, 16 Jun 2025 14:57:26 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1750100246; bh=MdWN2IA0BcpZ0iQ/ppJx27Pl1QTXwVmI0NyRsldDzJI=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=B0C4X+XNY+5SykEFt+5dI5Bd4VqRyH/UUFRycyN9U9AVvT7gbu/vTRZcbedCN9Zo9 V+yJxNrWxx68uweuZLCpvt0pn0LEwEGKvFudqyiG/dKvZUOEOH6uO6qdDFZa4de382 Owjf3TbgIF5xMe83fPsb3BOg2eRm3mdNbHKunm93Xfke6Drx75a27iWnqMkq4ByA/p oBKB/+b8LhAdyuOOzG3aAR9GB6u9usoF+QeXLm+ENevqK4qMurTunAnEP00HXXi8kQ k4LAhNMTsRLXLUa70tDdRCLvPdNiQBBbEhU+NAzdFanMb817SedW6PApsmMHWT87ft a4FjRelVBBqcQ== X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 78762 Cc: Eli Zaretskii , Zach Shaftel , 78762@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) This segfault affects Emacs 30 too, so it should be backported to emacs-30.