emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scratch/memrep 1e78f29: Continue implementation


From: Lars Ingebrigtsen
Subject: scratch/memrep 1e78f29: Continue implementation
Date: Thu, 10 Dec 2020 03:23:32 -0500 (EST)

branch: scratch/memrep
commit 1e78f29896d0881c2b23b33e3328d29e7973191f
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Continue implementation
---
 lisp/emacs-lisp/memory-report.el | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/lisp/emacs-lisp/memory-report.el b/lisp/emacs-lisp/memory-report.el
index 30cab3c..498c677 100644
--- a/lisp/emacs-lisp/memory-report.el
+++ b/lisp/emacs-lisp/memory-report.el
@@ -30,6 +30,7 @@
   (pop-to-buffer "*Memory-Report*")
   (erase-buffer)
   (memory-report--garbage-collect)
+  (memory-report--buffers)
   (memory-report--total-variables)
   (memory-report--largest-variables))
 
@@ -186,6 +187,43 @@
   (* (nth 1 (assq type elems))
      (nth 2 (assq type elems))))
 
+(defun memory-report--buffers ()
+  (let ((buffers (mapcar (lambda (buffer)
+                           (cons buffer (memory-usage--buffer buffer)))
+                         (buffer-list))))
+    (insert "Total Memory Usage In Buffers: "
+            (memory-report--format (seq-reduce #'+ (mapcar #'cdr buffers) 0))
+            "\n\n")
+    (insert "Largest Buffers:\n\n")
+    (cl-loop for i from 1 upto 20
+             for (buffer . size) in (seq-sort (lambda (e1 e2)
+                                                (> (cdr e1) (cdr e2)))
+                                              buffers)
+             do (insert (memory-report--format size)
+                        " "
+                        (buffer-name buffer)
+                        "\n"))
+    (insert "\n")))
+
+(defun memory-report--buffer (buffer)
+  (with-current-buffer buffer
+    (+ (save-restriction
+         (widen)
+         (+ (position-bytes (point-max))
+           (- (position-bytes (point-min)))
+           (gap-size)))
+       (seq-reduce #'+ (mapcar (lambda (elem)
+                                 (if (cdr elem)
+                                     (memory-report--variable-size
+                                      (make-hash-table :test #'eq)
+                                      (cdr elem))
+                                   0))
+                               (buffer-local-variables buffer))
+                   0)
+       ;; Text properties
+       ;; Overlays
+       )))
+
 (provide 'memory-report)
 
 ;;; memory-report.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]