unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#59272: [PATCH] Make Memory Human Readable in proced Buffers
@ 2022-11-14 10:19 Laurence Warne
  2022-11-15  3:28 ` Visuwesh
  0 siblings, 1 reply; 8+ messages in thread
From: Laurence Warne @ 2022-11-14 10:19 UTC (permalink / raw)
  To: 59272


[-- 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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#59272: [PATCH] Make Memory Human Readable in proced Buffers
  2022-11-14 10:19 bug#59272: [PATCH] Make Memory Human Readable in proced Buffers Laurence Warne
@ 2022-11-15  3:28 ` Visuwesh
  2022-11-15  3:40   ` Stefan Kangas
  0 siblings, 1 reply; 8+ messages in thread
From: Visuwesh @ 2022-11-15  3:28 UTC (permalink / raw)
  To: Laurence Warne; +Cc: 59272

[திங்கள் நவம்பர் 14, 2022] Laurence Warne wrote:

> 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.

We can leave this to the user to decide by...

> +(defun proced-format-memory (kilobytes)
> +  "Format KILOBYTES in a human readable format."

... using `file-size-human-readable' instead.

> +  (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)





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#59272: [PATCH] Make Memory Human Readable in proced Buffers
  2022-11-15  3:28 ` Visuwesh
@ 2022-11-15  3:40   ` Stefan Kangas
  2022-11-15  8:06     ` Juri Linkov
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Kangas @ 2022-11-15  3:40 UTC (permalink / raw)
  To: Visuwesh, Laurence Warne; +Cc: 59272

Visuwesh <visuweshm@gmail.com> writes:

> [திங்கள் நவம்பர் 14, 2022] Laurence Warne wrote:
>
>> 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.
>
> We can leave this to the user to decide by...
>
>> +(defun proced-format-memory (kilobytes)
>> +  "Format KILOBYTES in a human readable format."
>
> ... using `file-size-human-readable' instead.

Yes, we could do something like

(defcustom  proced-format-memory-function #'file-size-human-readable
  "..."
  )

Where one of the options is #'identity, which means not to use human
readable sizes, and then funcall that.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#59272: [PATCH] Make Memory Human Readable in proced Buffers
  2022-11-15  3:40   ` Stefan Kangas
@ 2022-11-15  8:06     ` Juri Linkov
  2022-11-15  8:59       ` Stefan Kangas
  0 siblings, 1 reply; 8+ messages in thread
From: Juri Linkov @ 2022-11-15  8:06 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 59272, Laurence Warne, Visuwesh

>> We can leave this to the user to decide by...
>>
>>> +(defun proced-format-memory (kilobytes)
>>> +  "Format KILOBYTES in a human readable format."
>>
>> ... using `file-size-human-readable' instead.
>
> Yes, we could do something like
>
> (defcustom  proced-format-memory-function #'file-size-human-readable
>   "..."
>   )
>
> Where one of the options is #'identity, which means not to use human
> readable sizes, and then funcall that.

Maybe the default should be the same as in byte-count-to-string-function?





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#59272: [PATCH] Make Memory Human Readable in proced Buffers
  2022-11-15  8:06     ` Juri Linkov
@ 2022-11-15  8:59       ` Stefan Kangas
  2022-11-15  9:51         ` Laurence Warne
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Kangas @ 2022-11-15  8:59 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 59272, Laurence Warne, Visuwesh

Juri Linkov <juri@linkov.net> writes:

> Maybe the default should be the same as in byte-count-to-string-function?

Make sense to me.  Or maybe we should just use that variable?





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#59272: [PATCH] Make Memory Human Readable in proced Buffers
  2022-11-15  8:59       ` Stefan Kangas
@ 2022-11-15  9:51         ` Laurence Warne
  2022-11-16  8:56           ` Laurence Warne
  0 siblings, 1 reply; 8+ messages in thread
From: Laurence Warne @ 2022-11-15  9:51 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 59272, Visuwesh, Juri Linkov

[-- Attachment #1: Type: text/plain, Size: 752 bytes --]

I think the suggestion to use a custom variable (or just use
byte-count-to-string) is a good one, but AFAICS the argument to
file-size-human-readable should be bytes, but proced gets rss and vsize
from 'process-attributes' which uses kilobytes.  So we're still stuck with
having to choose one of:

(funcall #'byte-count-to-string-function (* 1000 kilobytes))
(funcall #'byte-count-to-string-function (* 1024 kilobytes))

I'm not really familiar with c, so I can't tell from process.c

On Tue, Nov 15, 2022 at 8:59 AM Stefan Kangas <stefankangas@gmail.com>
wrote:

> Juri Linkov <juri@linkov.net> writes:
>
> > Maybe the default should be the same as in byte-count-to-string-function?
>
> Make sense to me.  Or maybe we should just use that variable?
>

[-- Attachment #2: Type: text/html, Size: 1218 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#59272: [PATCH] Make Memory Human Readable in proced Buffers
  2022-11-15  9:51         ` Laurence Warne
@ 2022-11-16  8:56           ` Laurence Warne
  2022-11-17  9:55             ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Laurence Warne @ 2022-11-16  8:56 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 59272, Visuwesh, Juri Linkov


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

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.

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

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

From 9ef79917565bfd36dc67c124d3656376ea48d48b 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 | 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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#59272: [PATCH] Make Memory Human Readable in proced Buffers
  2022-11-16  8:56           ` Laurence Warne
@ 2022-11-17  9:55             ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2022-11-17  9:55 UTC (permalink / raw)
  To: Laurence Warne; +Cc: 59272-done, juri, stefankangas, visuweshm

> Cc: 59272@debbugs.gnu.org, Visuwesh <visuweshm@gmail.com>,
>  Juri Linkov <juri@linkov.net>
> From: Laurence Warne <laurencewarne@gmail.com>
> 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.

Thanks, installed, and closing the bug.





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-11-17  9:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-14 10:19 bug#59272: [PATCH] Make Memory Human Readable in proced Buffers Laurence Warne
2022-11-15  3:28 ` 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

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).