Add support for RAM detection in NetBSD

Squashed commit of the following:

commit e11e3cbbd04c9c693d6e48f72e9ea99b64a83556
Author: Lucien Cartier-Tilet <lucien@phundrak.com>
Date:   Sun Dec 19 18:34:09 2021 +0100

    Multiply by 2014 to go from Kilobytes to Bytes

commit 786c9bbfdfd8a1fc6d6b21ea92ac8252b9dd0a50
Author: Lucien Cartier-Tilet <lucien@phundrak.com>
Date:   Sun Dec 19 18:23:21 2021 +0100

    Read in /proc/meminfo to get used/available memory

    Apparently NetBSD doesn’t properly implement hw.usermem.
    Also it needs to read hw.physmem64 instead of hw.physmem with sysctl

commit c9e7b8cadfcbfb877f180a9c89ee9d87f271d17c
Author: Lucien Cartier-Tilet <lucien@phundrak.com>
Date:   Sun Dec 19 17:50:24 2021 +0100

    Why doesn’t `last' return the last /element/?

commit f2248810132813191ebdd11f739d24bcc49f3165
Author: Lucien Cartier-Tilet <lucien@phundrak.com>
Date:   Sun Dec 19 17:46:33 2021 +0100

    Fix RAM detection on NetBSD
This commit is contained in:
Lucien Cartier-Tilet 2021-12-19 18:35:59 +01:00
parent a2f24e4633
commit 382bb55064
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
1 changed files with 26 additions and 7 deletions

View File

@ -457,13 +457,32 @@ Compatible with Darwin and FreeBSD at least."
(let* ((command-to-mem (lambda (command)
(string-to-number
(s-trim
(cadr
(split-string (eshell-info-banner--shell-command-to-string command)
" "
t)))))))
`(("RAM"
,(apply command-to-mem '("sysctl hw.physmem"))
,(apply command-to-mem '("sysctl hw.usermem"))))))
(car (last
(split-string (eshell-info-banner--shell-command-to-string command)
" "
t)))))))
(netbsdp (and (equal system-type 'berkeley-unix)
(string-match-p "NetBSD" (eshell-info-banner--shell-command-to-string "uname"))))
(total (apply command-to-mem `(,(if netbsdp "sysctl hw.physmem64" "sysctl hw.physmem"))))
(used (if netbsdp
(- total
(* 1024 (string-to-number
(s-trim
(with-temp-buffer
(insert-file-contents-literally "/proc/meminfo")
(save-match-data
(string-match (rx bol
"MemFree:"
(* blank)
(group (+ digit))
(* blank)
"kB")
(buffer-string))
(substring-no-properties (buffer-string)
(match-beginning 1)
(match-end 1))))))))
(apply command-to-mem '("sysctl hw.usermem")))))
`(("RAM" ,total ,used))))
(defun eshell-info-banner--get-memory-windows ()
"Get memory usage for Window."