Subject: Re: bug#59272: [PATCH] Make Memory Human Readable in proced Buffers

From: Laurence Warne <[email-masked]>
Date: Wed, 16 Nov 2022 08:56:42 +0000

Alright, I've had a look at sysdep.c, and it looks like bytes are divided
by 1024 to convert to kilobytes.

I've attached an updated patch using Juri's suggestion.
From 9ef79917565bfd36dc67c124d3656376ea48d48b Mon Sep 17 00:00:00 2001
From: Laurence Warne <[email-masked]>
Date: Sun, 13 Nov 2022 19:53:17 +0000
Subject: [PATCH] Make vsize and rss human readable in proced buffers

* lisp/proced.el (proced-format-memory): new function
(proced-grammar-alist): use proced-format-memory to format vsize and rss
---
 lisp/proced.el | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/proced.el b/lisp/proced.el
index a774f2dd1e..a6f1a71778 100644
--- a/lisp/proced.el
+++ b/lisp/proced.el
@@ -140,8 +140,8 @@ proced-grammar-alist
     (nice    "Ni"      "%3d" 3 proced-< t (nice pid) (t t nil))
     (thcount "THCount" "%d" right proced-< t (thcount pid) (nil t t))
     (start   "Start"   proced-format-start 6 proced-time-lessp nil (start pid) (t t nil))
-    (vsize   "VSize"   "%d" right proced-< t (vsize pid) (nil t t))
-    (rss     "RSS"     "%d" right proced-< t (rss pid) (nil t t))
+    (vsize   "VSize"   proced-format-memory right proced-< t (vsize pid) (nil t t))
+    (rss     "RSS"     proced-format-memory right proced-< t (rss pid) (nil t t))
     (etime   "ETime"   proced-format-time right proced-time-lessp t (etime pid) (nil t t))
     (pcpu    "%CPU"    "%.1f" right proced-< t (pcpu pid) (nil t t))
     (pmem    "%Mem"    "%.1f" right proced-< t (pmem pid) (nil t t))
@@ -1425,6 +1425,10 @@ proced-format-args
 Replace newline characters by \"^J\" (two characters)."
   (string-replace "\n" "^J" args))
 
+(defun proced-format-memory (kilobytes)
+  "Format KILOBYTES in a human readable format."
+  (funcall byte-count-to-string-function (* 1024 kilobytes)))
+
 (defun proced-format (process-alist format)
   "Display PROCESS-ALIST using FORMAT."
   (if (symbolp format)
-- 
2.30.2