From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Vasilij Schneidermann Newsgroups: gmane.emacs.bugs Subject: bug#22114: 24.5; [PATCH] Allow profiler.el to display reports after stopping Date: Mon, 14 Dec 2015 09:28:36 +0100 Message-ID: <20151214082836.GA806@odonien.fritz.box> References: <83bna0di5k.fsf@gnu.org> <20151208163208.GA1080@odonien.bevuta.com> <837fkodf3e.fsf@gnu.org> <83zixkbyoj.fsf@gnu.org> <20151213203323.GB1296@odonien.fritz.box> <20151213221825.GC1296@odonien.fritz.box> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="9jxsPFA5p3P2qPhR" X-Trace: ger.gmane.org 1450081816 22470 80.91.229.3 (14 Dec 2015 08:30:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 14 Dec 2015 08:30:16 +0000 (UTC) Cc: John Wiegley , Paul Eggert , 22114@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Dec 14 09:30:05 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1a8OWC-0000kj-K6 for geb-bug-gnu-emacs@m.gmane.org; Mon, 14 Dec 2015 09:30:04 +0100 Original-Received: from localhost ([::1]:58422 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8OWC-0000cl-26 for geb-bug-gnu-emacs@m.gmane.org; Mon, 14 Dec 2015 03:30:04 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52027) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8OVG-0007na-SH for bug-gnu-emacs@gnu.org; Mon, 14 Dec 2015 03:29:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a8OVC-0007R7-Rm for bug-gnu-emacs@gnu.org; Mon, 14 Dec 2015 03:29:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43273) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a8OVC-0007R3-OX for bug-gnu-emacs@gnu.org; Mon, 14 Dec 2015 03:29:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1a8OVC-0006PI-Ei for bug-gnu-emacs@gnu.org; Mon, 14 Dec 2015 03:29:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Vasilij Schneidermann Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 14 Dec 2015 08:29:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22114 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 22114-submit@debbugs.gnu.org id=B22114.145008173124611 (code B ref 22114); Mon, 14 Dec 2015 08:29:02 +0000 Original-Received: (at 22114) by debbugs.gnu.org; 14 Dec 2015 08:28:51 +0000 Original-Received: from localhost ([127.0.0.1]:50875 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a8OV0-0006Ot-M7 for submit@debbugs.gnu.org; Mon, 14 Dec 2015 03:28:50 -0500 Original-Received: from mail-wm0-f50.google.com ([74.125.82.50]:34978) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1a8OUy-0006Of-Nh for 22114@debbugs.gnu.org; Mon, 14 Dec 2015 03:28:49 -0500 Original-Received: by mail-wm0-f50.google.com with SMTP id p66so32569062wmp.0 for <22114@debbugs.gnu.org>; Mon, 14 Dec 2015 00:28:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=6w6GBa9ozj+TBNfUhxGRAmSwoOL3/5q5yxBvOUwyXTU=; b=xAVSG03FyGmAcbCwHZuwgmPChgtmeCvNMckijP2PI5NpH2rdKhWn61a66vWMJlS1Vp P5QXbkFhT/4z/TN2dj3JNHbghjS/lOjYQQeWzeRwWFFXgvaqCKq/3AW0GdGgIjv/v7W0 KbdaIyjONf+Gcj9qEHn04NNqQsD+EjXvg+vqLLdlCejMZZc9WPx4yy62nSQGKxdlZP8b B2b2KQw70geMgc6GiMTp9ib4424M1xfapIF4Dm7a7ctpJO0brhp3rYS6EneGdbxQgmbt HFIVmV9l44dq3qHfxB7V3Y5/aBG6f8KBrOF6ZMG9JXOIQ8AYF54ZAj3n9VwqQ/HV8+2j BLhQ== X-Received: by 10.194.179.71 with SMTP id de7mr35224649wjc.119.1450081723172; Mon, 14 Dec 2015 00:28:43 -0800 (PST) Original-Received: from localhost ([89.204.139.24]) by smtp.gmail.com with ESMTPSA id m67sm14844277wmf.16.2015.12.14.00.28.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Dec 2015 00:28:42 -0800 (PST) Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:109969 Archived-At: --9jxsPFA5p3P2qPhR Content-Type: text/plain; charset=utf-8 Content-Disposition: inline > Your testing was too superficial. IIRC The problem to which the comments > refer can only show up if you modify the hash-table. > > The problem is corner-case, but real. And there's no reason not to plug > that hole. I see, I can trigger this by removing a key from the log. I haven't thought about that possibility yet, because, why would you do that? Nevertheless, if I'd want to fix this, I'd just need to use `copy-hash-table` on the log and return its result? > E.g. I don't think you need to the C-side changes to get the Elisp > side to provide the functionality you're looking for. I've initially provided an elisp-only patch that works around the profiler resetting the log with an extra level of indirection: Before stopping the profiler or accessing the log while it's still running, the log is saved to a variable, the other code just accesses that variable instead of retrieving the log directly. I'm not really happy with it though as it does need more code than the other variant and does only fix the UI aspect of viewing a report after the profiler has been stopped. In case you haven't seen it yet, I'll attach it to this message. --9jxsPFA5p3P2qPhR Content-Type: text/x-diff; charset=utf-8 Content-Disposition: attachment; filename="0001-Allow-for-retrieving-profiler-logs-after-stopping.patch" >From 3464446b83151ad894ff4ee7f62ed1cb7852b1b6 Mon Sep 17 00:00:00 2001 From: Vasilij Schneidermann Date: Tue, 8 Dec 2015 09:01:15 +0100 Subject: [PATCH] Allow for retrieving profiler logs after stopping --- lisp/profiler.el | 59 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/lisp/profiler.el b/lisp/profiler.el index f28bbfe..10cdcfb 100644 --- a/lisp/profiler.el +++ b/lisp/profiler.el @@ -214,21 +214,23 @@ Optional argument MODE means only check for the specified mode (cpu or mem)." (t (or (profiler-running-p 'cpu) (profiler-running-p 'mem))))) +(defvar profiler-cpu-log nil) + +(defvar profiler-memory-log nil) + (defun profiler-cpu-profile () "Return CPU profile." - (when (profiler-running-p 'cpu) - (profiler-make-profile - :type 'cpu - :timestamp (current-time) - :log (profiler-cpu-log)))) + (profiler-make-profile + :type 'cpu + :timestamp (current-time) + :log profiler-cpu-log)) (defun profiler-memory-profile () "Return memory profile." - (when (profiler-memory-running-p) - (profiler-make-profile - :type 'memory - :timestamp (current-time) - :log (profiler-memory-log)))) + (profiler-make-profile + :type 'memory + :timestamp (current-time) + :log profiler-memory-log)) ;;; Calltrees @@ -828,7 +830,11 @@ Also, if MODE is `mem' or `cpu+mem', then memory profiler will be started." (defun profiler-stop () "Stop started profilers. Profiler logs will be kept." (interactive) - (let ((cpu (if (fboundp 'profiler-cpu-stop) (profiler-cpu-stop))) + (when (and (fboundp 'profiler-cpu-running-p) (profiler-cpu-running-p)) + (setq profiler-cpu-log (profiler-cpu-log))) + (when (profiler-memory-running-p) + (setq profiler-memory-log (profiler-memory-log))) + (let ((cpu (when (fboundp 'profiler-cpu-stop) (profiler-cpu-stop))) (mem (profiler-memory-stop))) (message "%s profiler stopped" (cond ((and mem cpu) "CPU and memory") @@ -839,26 +845,31 @@ Also, if MODE is `mem' or `cpu+mem', then memory profiler will be started." (defun profiler-reset () "Reset profiler logs." (interactive) - (when (fboundp 'profiler-cpu-log) - (ignore (profiler-cpu-log))) - (ignore (profiler-memory-log)) - t) + (when (and (fboundp 'profiler-cpu-running-p) (profiler-cpu-running-p)) + (profiler-cpu-stop)) + (when (profiler-memory-running-p) + (profiler-memory-stop)) + (setq profiler-cpu-log nil + profiler-memory-log nil)) (defun profiler-report-cpu () - (let ((profile (profiler-cpu-profile))) - (when profile - (profiler-report-profile-other-window profile)))) + (when profiler-cpu-log + (profiler-report-profile-other-window (profiler-cpu-profile)))) (defun profiler-report-memory () - (let ((profile (profiler-memory-profile))) - (when profile - (profiler-report-profile-other-window profile)))) + (when profiler-memory-log + (profiler-report-profile-other-window (profiler-memory-profile)))) (defun profiler-report () "Report profiling results." - (interactive) - (profiler-report-cpu) - (profiler-report-memory)) + (when (and (fboundp 'profiler-cpu-running-p) (profiler-cpu-running-p)) + (setq profiler-cpu-log (profiler-cpu-log))) + (when (profiler-memory-running-p) + (setq profiler-memory-log (profiler-memory-log))) + (if (and (not profiler-cpu-log) (not profiler-memory-log)) + (user-error "No profiler run recorded") + (profiler-report-cpu) + (profiler-report-memory))) ;;;###autoload (defun profiler-find-profile (filename) -- 2.6.2 --9jxsPFA5p3P2qPhR--