From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: yikai@z1k.dev Newsgroups: gmane.emacs.bugs Subject: bug#50301: [PATCH] memory-report: support calculating size for structures Date: Wed, 01 Sep 2021 00:11:18 +0800 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11702"; mail-complaints-to="usenet@ciao.gmane.io" To: 50301@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Aug 31 18:20:34 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mL6Uz-0002r3-3W for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 31 Aug 2021 18:20:33 +0200 Original-Received: from localhost ([::1]:42876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mL6Uy-0006AM-4B for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 31 Aug 2021 12:20:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40914) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL6UU-00066G-8S for bug-gnu-emacs@gnu.org; Tue, 31 Aug 2021 12:20:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51965) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mL6UU-0006pi-09 for bug-gnu-emacs@gnu.org; Tue, 31 Aug 2021 12:20:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mL6UT-00070u-L3 for bug-gnu-emacs@gnu.org; Tue, 31 Aug 2021 12:20:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: yikai@z1k.dev Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 31 Aug 2021 16:20:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 50301 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.163042675426892 (code B ref -1); Tue, 31 Aug 2021 16:20:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 31 Aug 2021 16:19:14 +0000 Original-Received: from localhost ([127.0.0.1]:35278 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mL6Te-0006zd-IB for submit@debbugs.gnu.org; Tue, 31 Aug 2021 12:19:14 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:35282) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mL6MD-0006lo-5o for submit@debbugs.gnu.org; Tue, 31 Aug 2021 12:11:31 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38052) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL6MB-0006oE-Pj for bug-gnu-emacs@gnu.org; Tue, 31 Aug 2021 12:11:29 -0400 Original-Received: from out2-smtp.messagingengine.com ([66.111.4.26]:57857) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mL6M9-0000ZU-Rr for bug-gnu-emacs@gnu.org; Tue, 31 Aug 2021 12:11:27 -0400 Original-Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 82EFB5C01CA; Tue, 31 Aug 2021 12:11:22 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 31 Aug 2021 12:11:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=z1k.dev; h=from :to:subject:date:message-id:mime-version:content-type; s=fm1; bh=68A9QJ/swaQ/DajS2CQm1A8krZg46v2zdlfyDuMK5Lg=; b=HHsbewciILB1 tzRnLs+8bMZXChY6kaAt0qI36tQjgsyaCofQT7MRCmYIIHhT2r43pfJKuyliygjI iXOkH1/PO+v08rV1gP6Nu8hiNy6SAxOxsI8twGn3kL+25sJ3/zfLU771JjSy8SCz z7A+Yj+hsfU2unKFwji/B+C0QJcz4aKLAI0l635srjePgFBpELz8JTHSfbMe6kE9 PC21NPG3qnAEPkf7fmPBjOJx658HHn7vWpDtWdEY62ZvVUrTx5Ve6LpRVuFsF4Zg gFT0MDuNKwuJljYbnVESAasHIYRBn4c5c6RjfBX3I5i+DQ30RIM4GARufDdtJnLn AqmdmuTGZQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=68A9QJ/swaQ/DajS2CQm1A8krZg46 v2zdlfyDuMK5Lg=; b=AYdLLITyi5gWhEf+UHJ0qLJL1KJiO1ufKbkZMFTvZgs8f qy/d1ga+d8/HMElYYFfaqozEjl9Ce+ITlBeWoK3HDooI488cevMuZlCCPw+7Sy0Z unITuBZKewQ6gPL01oEFXpsryh+vzIid0fHAsDAS7w9XudO4afUxdrKfAHNXbAPn y8uGo7KxUGbtw73dCoj5N94biHFs4j2lDKKAZr9M5C5j55luv7B43PHFBS/J4qEV vVIOXBO1Nc6J3pLavYAQaEKKp+59z6mPIxj+Er5boHbh6auk5oE4uu2zyGUtMQ4x WmxJ/LNt1/ZLBr6Of8ONX5XNjpNsfXIgT+/dmNBiw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddruddvuddgleelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkgggtsehmtderredttd dtnecuhfhrohhmpeihihhkrghiseiiudhkrdguvghvnecuggftrfgrthhtvghrnhepffeg geelffduieeghfdtudeiveeuudektdetkeevhffhtdduveekfeduffdtheefnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhephihikhgrihesiidu khdruggvvh X-ME-Proxy: Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 31 Aug 2021 12:11:21 -0400 (EDT) Received-SPF: pass client-ip=66.111.4.26; envelope-from=yikai@z1k.dev; helo=out2-smtp.messagingengine.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 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, FROM_FMBLA_NEWDOM28=0.799, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Tue, 31 Aug 2021 12:19:09 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:213108 Archived-At: --=-=-= Content-Type: text/plain Tags: patch Tags: patch (already sent to emacs-devel mailing list, re-submit using submit-emacs-patch) Here's another patch on memory-report package which fixes the object size calculation for structures (cl-defstruct types). Before this patch, memory-report--object-size will report empty size for structure objects, which results in incorrect report about "Largest Variables" in memory-report result. In GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.30, cairo version 1.17.4) of 2021-08-20 built on lilydjwg Repository revision: 657fe8b9d87dd17d9b50dd8e15bfd917c6c630b2 Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12013000 System Description: Arch Linux Configured using: 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib --localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games --with-sound=alsa --with-modules --without-gconf --without-gsettings --enable-link-time-optimization --with-native-compilation --with-x-toolkit=gtk3 --without-xaw3d --without-compress-install '--program-transform-name=s/\([ec]tags\)/\1.emacs/' 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -flto -fuse-linker-plugin' CPPFLAGS=-D_FORTIFY_SOURCE=2 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-memory-report-support-calculating-size-for-structure.patch >From 6a851e089d0bd9ef61d9209c5d3eb3932c7a7a6c Mon Sep 17 00:00:00 2001 From: Yikai Zhao Date: Sun, 29 Aug 2021 21:47:12 +0800 Subject: [PATCH] memory-report: support calculating size for structures --- lisp/emacs-lisp/memory-report.el | 16 +++++++++++++++- test/lisp/emacs-lisp/memory-report-tests.el | 8 ++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lisp/emacs-lisp/memory-report.el b/lisp/emacs-lisp/memory-report.el index aee2a0079c..cfa7010af4 100644 --- a/lisp/emacs-lisp/memory-report.el +++ b/lisp/emacs-lisp/memory-report.el @@ -29,7 +29,8 @@ (require 'seq) (require 'subr-x) -(eval-when-compile (require 'cl-lib)) +(require 'cl-lib) +(require 'cl-macs) (defvar memory-report--type-size (make-hash-table)) @@ -243,6 +244,19 @@ memory-report--object-size-1 value) total)) +;; for all cl-defstruct types +(cl-defmethod memory-report--object-size-1 (counted (value cl-structure-object)) + (let ((struct-type (type-of value))) + (apply '+ + (memory-report--size 'vector) + (mapcar (lambda (slot) + (if (eq (car slot) 'cl-tag-slot) + 0 + (memory-report--object-size + counted + (cl-struct-slot-value struct-type (car slot) value)))) + (cl-struct-slot-info struct-type))))) + (defun memory-report--format (bytes) (setq bytes (/ bytes 1024.0)) (let ((units '("KiB" "MiB" "GiB" "TiB"))) diff --git a/test/lisp/emacs-lisp/memory-report-tests.el b/test/lisp/emacs-lisp/memory-report-tests.el index 0c0297b5fc..e352dd165f 100644 --- a/test/lisp/emacs-lisp/memory-report-tests.el +++ b/test/lisp/emacs-lisp/memory-report-tests.el @@ -68,6 +68,14 @@ memory-report-sizes-vectors (vector string string)) 124)))) +(ert-deftest memory-report-sizes-structs () + (cl-defstruct memory-report-test-struct + (item0 nil) + (item1 nil)) + (let ((s (make-memory-report-test-struct :item0 "hello" :item1 "world"))) + (should (= (memory-report-object-size s) + 90)))) + (provide 'memory-report-tests) ;;; memory-report-tests.el ends here -- 2.33.0 --=-=-=--