emacs-diffs
[Top][All Lists]
Advanced

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

scratch/memrep 3db4752: Add image cache data


From: Lars Ingebrigtsen
Subject: scratch/memrep 3db4752: Add image cache data
Date: Thu, 10 Dec 2020 05:58:55 -0500 (EST)

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

    Add image cache data
---
 lisp/emacs-lisp/memory-report.el |  9 ++++++++-
 src/image.c                      | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/memory-report.el b/lisp/emacs-lisp/memory-report.el
index 4c69c53..b738fc3 100644
--- a/lisp/emacs-lisp/memory-report.el
+++ b/lisp/emacs-lisp/memory-report.el
@@ -32,9 +32,11 @@
   (pop-to-buffer "*Memory-Report*")
   (erase-buffer)
   (memory-report--garbage-collect)
+  (memory-report--image-cache)
   (memory-report--buffers)
   (memory-report--total-variables)
-  (memory-report--largest-variables))
+  (memory-report--largest-variables)
+  (goto-char (point-min)))
 
 (defvar memory-report--type-size (make-hash-table))
 
@@ -226,6 +228,11 @@
        (memory-report--variable-size (make-hash-table :test #'eq)
                                      (overlay-lists)))))
 
+(defun memory-report--image-cache ()
+  (insert "Total Image Cache Size: "
+          (memory-report--format (image-cache-size))
+          "\n\n"))
+
 (provide 'memory-report)
 
 ;;; memory-report.el ends here
diff --git a/src/image.c b/src/image.c
index 522a4cf..4917808 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1792,6 +1792,39 @@ which is then usually a filename.  */)
   return Qnil;
 }
 
+static int
+image_frame_cache_size (struct frame *f)
+{
+  struct image_cache *c = FRAME_IMAGE_CACHE (f);
+  int total = 0;
+
+  if (!c)
+    return 0;
+
+  for (ptrdiff_t i = 0; i < c->used; ++i)
+    {
+      struct image *img = c->images[i];
+
+      total += img->pixmap->width * img->pixmap->height  *
+       img->pixmap->bits_per_pixel / 8;
+    }
+  return total;
+}
+
+DEFUN ("image-cache-size", Fimage_cache_size, Simage_cache_size, 0, 0, 0,
+       doc: /* Return the size of the image cache.  */)
+  (void)
+{
+  Lisp_Object tail, frame;
+  int total = 0;
+
+  FOR_EACH_FRAME (tail, frame)
+    if (FRAME_WINDOW_P (XFRAME (frame)))
+      total += image_frame_cache_size (XFRAME (frame));
+
+  return make_int (total);
+}
+
 
 DEFUN ("image-flush", Fimage_flush, Simage_flush,
        1, 2, 0,
@@ -10703,6 +10736,7 @@ non-numeric, there is no explicit limit on the size of 
images.  */);
   defsubr (&Simage_size);
   defsubr (&Simage_mask_p);
   defsubr (&Simage_metadata);
+  defsubr (&Simage_cache_size);
 
 #ifdef GLYPH_DEBUG
   defsubr (&Simagep);



reply via email to

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