all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Laurence Warne <laurencewarne@gmail.com>
To: 59272@debbugs.gnu.org
Subject: bug#59272: [PATCH] Make Memory Human Readable in proced Buffers
Date: Mon, 14 Nov 2022 10:19:51 +0000	[thread overview]
Message-ID: <CAE2oLqgn_QOsYj7a8nrYsN+FJGdo3zRnyL1Q_92UAn+6=0dVDg@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 351 bytes --]

Hi, this patch makes vsize and rss human readable in proced buffers by
formatting them as megabytes or gigabytes according to their size, similar
as the -h flag for ls and du.

The current behaviour is to show them always as kilobytes, though I'm
unsure if this meant as 1000 bytes or 1024 bytes, this patch assumes the
former case.

Thanks, Laurence

[-- Attachment #1.2: Type: text/html, Size: 440 bytes --]

[-- Attachment #2: 0001-Make-vsize-and-rss-human-readable-in-proced-buffers.patch --]
[-- Type: text/x-patch, Size: 2086 bytes --]

From 704b2c3c56a9900c5f71ca1f08d7744515ab95aa Mon Sep 17 00:00:00 2001
From: Laurence Warne <laurencewarne@gmail.com>
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 | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/lisp/proced.el b/lisp/proced.el
index a774f2dd1e..4107744bbd 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,16 @@ 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."
+  (let* ((mb 1000)
+         (gb (* 1000 mb)))
+    (cond ((< kilobytes 100) (format "%.1fK" kilobytes))
+          ((< kilobytes mb) (format "%dK" kilobytes))
+          ((< kilobytes (* 100 mb)) (format "%.1fM" (/ kilobytes (float mb))))
+          ((< kilobytes gb) (format "%dM" (/ kilobytes mb)))
+          (t (format "%.1fG" (/ kilobytes (float gb)))))))
+
 (defun proced-format (process-alist format)
   "Display PROCESS-ALIST using FORMAT."
   (if (symbolp format)
-- 
2.30.2


             reply	other threads:[~2022-11-14 10:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-14 10:19 Laurence Warne [this message]
2022-11-15  3:28 ` bug#59272: [PATCH] Make Memory Human Readable in proced Buffers Visuwesh
2022-11-15  3:40   ` Stefan Kangas
2022-11-15  8:06     ` Juri Linkov
2022-11-15  8:59       ` Stefan Kangas
2022-11-15  9:51         ` Laurence Warne
2022-11-16  8:56           ` Laurence Warne
2022-11-17  9:55             ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAE2oLqgn_QOsYj7a8nrYsN+FJGdo3zRnyL1Q_92UAn+6=0dVDg@mail.gmail.com' \
    --to=laurencewarne@gmail.com \
    --cc=59272@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.