diff options
author | Yuuki Harano <masm+github@masm11.me> | 2021-11-11 00:39:53 +0900 |
---|---|---|
committer | Yuuki Harano <masm+github@masm11.me> | 2021-11-11 00:39:53 +0900 |
commit | 4dd1f56f29fc598a8339a345c2f8945250600602 (patch) | |
tree | af341efedffe027e533b1bcc0dbf270532e48285 /lisp/emacs-lisp/memory-report.el | |
parent | 4c49ec7f865bdad1629d2f125f71f4e506b258f2 (diff) | |
parent | 810fa21d26453f898de9747ece7205dfe6de9d08 (diff) | |
download | emacs-4dd1f56f29fc598a8339a345c2f8945250600602.tar.gz emacs-4dd1f56f29fc598a8339a345c2f8945250600602.tar.bz2 emacs-4dd1f56f29fc598a8339a345c2f8945250600602.zip |
Merge branch 'master' of git.savannah.gnu.org:/srv/git/emacs into feature/pgtk
Diffstat (limited to 'lisp/emacs-lisp/memory-report.el')
-rw-r--r-- | lisp/emacs-lisp/memory-report.el | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/lisp/emacs-lisp/memory-report.el b/lisp/emacs-lisp/memory-report.el index 1125dde4055..450cdaa7a84 100644 --- a/lisp/emacs-lisp/memory-report.el +++ b/lisp/emacs-lisp/memory-report.el @@ -29,9 +29,9 @@ (require 'seq) (require 'subr-x) -(eval-when-compile (require 'cl-lib)) +(require 'cl-lib) -(defvar memory-report--type-size (make-hash-table)) +(defvar memory-report--type-size nil) ;;;###autoload (defun memory-report () @@ -84,6 +84,7 @@ by counted more than once." (gethash 'object memory-report--type-size))) (defun memory-report--set-size (elems) + (setq memory-report--type-size (make-hash-table)) (setf (gethash 'string memory-report--type-size) (cadr (assq 'strings elems))) (setf (gethash 'cons memory-report--type-size) @@ -230,8 +231,7 @@ by counted more than once." (let ((total (+ (memory-report--size 'vector) (* (memory-report--size 'object) (length value))))) (cl-loop for elem across value - do (setf (gethash elem counted) t) - (cl-incf total (memory-report--object-size counted elem))) + do (cl-incf total (memory-report--object-size counted elem))) total)) (cl-defmethod memory-report--object-size-1 (counted (value hash-table)) @@ -239,13 +239,24 @@ by counted more than once." (* (memory-report--size 'object) (hash-table-size value))))) (maphash (lambda (key elem) - (setf (gethash key counted) t) - (setf (gethash elem counted) t) (cl-incf total (memory-report--object-size counted key)) (cl-incf total (memory-report--object-size counted elem))) 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"))) @@ -272,7 +283,7 @@ by counted more than once." buffers) do (insert (memory-report--format size) " " - (button-buttonize + (buttonize (buffer-name buffer) #'memory-report--buffer-details buffer) "\n")) |