From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Joe Buehler Newsgroups: gmane.emacs.devel Subject: portable implementation of load-average Date: Wed, 22 Sep 2004 08:34:47 -0400 Organization: Spirent Communications, Inc. Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Message-ID: Reply-To: jbuehler@hekimian.com NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1095856538 29552 80.91.229.6 (22 Sep 2004 12:35:38 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 22 Sep 2004 12:35:38 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Sep 22 14:35:27 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CA6LH-0007HZ-00 for ; Wed, 22 Sep 2004 14:35:27 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CA6RF-0006Dl-W8 for ged-emacs-devel@m.gmane.org; Wed, 22 Sep 2004 08:41:38 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CA6R0-0006Ax-8c for emacs-devel@gnu.org; Wed, 22 Sep 2004 08:41:22 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CA6Qy-0006AH-SY for emacs-devel@gnu.org; Wed, 22 Sep 2004 08:41:21 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CA6Qy-0006AE-Pb for emacs-devel@gnu.org; Wed, 22 Sep 2004 08:41:20 -0400 Original-Received: from [80.91.229.2] (helo=main.gmane.org) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CA6Ki-0005rI-7n for emacs-devel@gnu.org; Wed, 22 Sep 2004 08:34:52 -0400 Original-Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1CA6Kh-00011D-00 for ; Wed, 22 Sep 2004 14:34:51 +0200 Original-Received: from 64.47.34.180 ([64.47.34.180]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 22 Sep 2004 14:34:51 +0200 Original-Received: from jbuehler by 64.47.34.180 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 22 Sep 2004 14:34:51 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-To: emacs-devel@gnu.org Original-Lines: 50 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 64.47.34.180 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040803 X-Accept-Language: en-us, en X-Enigmail-Version: 0.85.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:27432 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:27432 My AIX 4.3 boxes did not support load average in the modeline (emacs 21.2 if it matters) so I fixed it. Looking at this, it appears to be because /dev/kmem needs to be read for the information, and setting emacs setgid to group 0 would be a big security hole. Attached is a portable implementation in LISP that uses the "uptime" program. Please consider adding this to emacs. You should have a copyright assignment on file for me for emacs. The "uptime" program provides compatible output formats (and so the below works) on AIX 4.3, AIX 5.2, Solaris 8, HPUX 11, HPUX 11i, RedHat 9 -- all the machines to which I have access. I'm not a LISP programmer -- feel free to do whatever with my implementation if you don't like it. -- Joe Buehler ;; supply a portable definition of load-average if the emacs one does not work (condition-case nil (load-average) (error (defun load-average (&optional wantfloat) "get load average" (let ((uptime (shell-command-to-string "/usr/bin/uptime"))) (if (string-match "load average: \\([0-9.]+\\), \\([0-9.]+\\), \\([0-9.]+\\)" uptime) (if wantfloat (list (string-to-number (match-string 1 uptime)) (string-to-number (match-string 2 uptime)) (string-to-number (match-string 3 uptime)) ) (list (truncate (* 100 (string-to-number (match-string 1 uptime)))) (truncate (* 100 (string-to-number (match-string 2 uptime)))) (truncate (* 100 (string-to-number (match-string 3 uptime)))) ) ) (if wantfloat (list 0.0 0.0 0.0) (list 0 0 0) ) ) ) ) )) ;;;;;; the end