diff options
author | Yikai Zhao <yikai@z1k.dev> | 2021-09-02 09:37:06 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2021-09-02 09:37:06 +0200 |
commit | d8d5dc45656233fdccc3709093a16e2562cd4a40 (patch) | |
tree | 50c4932d2b6c6f9778ece51be56ffb3083bdae41 /lisp/emacs-lisp | |
parent | 891be6f14065950465bf6e360013ceae0cb955bd (diff) | |
download | emacs-d8d5dc45656233fdccc3709093a16e2562cd4a40.tar.gz emacs-d8d5dc45656233fdccc3709093a16e2562cd4a40.tar.bz2 emacs-d8d5dc45656233fdccc3709093a16e2562cd4a40.zip |
memory-report: support calculating size for structures
* lisp/emacs-lisp/memory-report.el (memory-report--object-size-1): Add
support for cl-defstruct types (bug#50301).
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/memory-report.el | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/memory-report.el b/lisp/emacs-lisp/memory-report.el index aee2a0079ca..3166d33e029 100644 --- a/lisp/emacs-lisp/memory-report.el +++ b/lisp/emacs-lisp/memory-report.el @@ -29,7 +29,7 @@ (require 'seq) (require 'subr-x) -(eval-when-compile (require 'cl-lib)) +(require 'cl-lib) (defvar memory-report--type-size (make-hash-table)) @@ -243,6 +243,19 @@ by counted more than once." value) total)) +;; 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"))) |