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

From: Visuwesh <[email-masked]>
Date: Tue, 15 Nov 2022 08:58:19 +0530

[திங்கள் நவம்பர் 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)