[comp.sys.apollo] SR10.3 source to determine load average

tonyf@bnr.ca (Tony Farrow) (02/27/91)

I have a program which needs to determine the current
load average on the system similiar to that which 
is returned by uptime. Does anyone have any code or ideas
to which they could point me ?

Currently my system is running SR10.3 but any information
would be greatly appreciated.

regards,
tony

rees@pisa.citi.umich.edu (Jim Rees) (02/28/91)

In article <1991Feb27.042254.14588@bwdls61.bnr.ca>, tonyf@bnr.ca (Tony Farrow) writes:

  I have a program which needs to determine the current
  load average on the system similiar to that which 
  is returned by uptime. Does anyone have any code or ideas
  to which they could point me ?

#include <apollo/base.h>

getla()
{
	long avenrun[3];
	status_$t status;

	proc1_$get_loadav(avenrun, &status);
}

I've added this to the FAQ file.

system@alchemy.chem.utoronto.ca (System Admin (Mike Peterson)) (02/28/91)

In article <1991Feb27.042254.14588@bwdls61.bnr.ca> tonyf@bnr.ca (Tony Farrow) writes:
>I have a program which needs to determine the current
>load average on the system similiar to that which 
>is returned by uptime. Does anyone have any code or ideas
>to which they could point me ?

Here is a routine that I got from comp.sources.unix: Volume 4, Issue 78,
which I have tested on SR10.2 and SR10.3 (and it works!):

main()
{
    float aves[3];
    
    ugetloads(aves);

    printf("And using ugetloads, the load averages are: %.2f, %.2f, %.2f\n",
	    aves[0], aves[1], aves[2]); 
}

/* ugetloads(ls)
 * float ld[3];
 *
 * Puts the 1, 5, and 15 minute load averages in the float
 * array passed to it.  This program calls upon uptime(1)
 * which could have different ways of printing ie. with bsd4.2
 * "   9:34pm  up 11 hrs,  3 users,  load average: 0.25, 0.22, 0.24  "
 *                                notice the commas -- ^ --- ^.
 * while bsd4.1 does not print commas.  The BSD41 define will 
 * take care of this if that is your system, it defaults to
 * the 4.2 version.
 *
 * Author:
 *  John Bien
 *  {ihnp4 | ucbvax | decvax}!trwrb!jsb
 *
 * This routine taken from comp.sources.unix: Volume 4, Issue 78
 */

#include <stdio.h>

FILE *popen();

ugetloads(ld)
float ld[3];
{
    FILE *stream;

    if((stream = popen("/usr/ucb/uptime","r")) == NULL)
	return(-1);

#ifdef BSD41
    fscanf(stream,"%*[^l] load average: %f %f %f", &ld[0],&ld[1],&ld[2]);
#else
    fscanf(stream,"%*[^l] load average: %f, %f, %f", &ld[0],&ld[1],&ld[2]);
#endif BSD41
    pclose(stream);
    return(NULL);
}
-- 
Mike Peterson, System Administrator, U/Toronto Department of Chemistry
E-mail: system@alchemy.chem.utoronto.ca
Tel: (416) 978-7094                  Fax: (416) 978-8775

e07@nikhefh.nikhef.nl (Eric Wassenaar) (03/01/91)

In article <501157c1.1bc5b@pisa.citi.umich.edu>, rees@pisa.citi.umich.edu (Jim Rees) writes:
> 	long avenrun[3];
> 	status_$t status;
> 	proc1_$get_loadav(avenrun, &status);

Two remarks:
a. Values need yet to be properly scaled to get them in the usual format.
b. Unlike other apollo system calls, this one does not return a status.

getload(avenrun)
double avenrun[3];
{
	int load[3];
	register int i;
	proc1_$get_loadav(load);
	for (i = 0; i < 3; i++)
		avenrun[i] = (double)load[i] / 65536.0;
}

Eric Wassenaar
-- 
Organization: NIKHEF-H, National Institute for Nuclear and High-Energy Physics
Address: Kruislaan 409, P.O. Box 41882, 1009 DB Amsterdam, the Netherlands
Phone: +31 20 592 0412, Home: +31 20 909449, Telefax: +31 20 592 5155
Internet: e07@nikhef.nl

rees@pisa.citi.umich.edu (Jim Rees) (03/03/91)

In article <1165@nikhefh.nikhef.nl>, e07@nikhefh.nikhef.nl (Eric Wassenaar) writes:

  a. Values need yet to be properly scaled to get them in the usual format.

I'm not sure there is a "usual format."  SunOS returns the numbers in the
same format as Domain/OS.  Other systems seem to return doubles, if I'm to
believe the sendmail sources.  Yet another reason why reading /dev/kmem is a
bad idea.  Why are Unix folks so reluctant to add system calls?

  b. Unlike other apollo system calls, this one does not return a status.

Right you are.  I cribbed that code out of sendmail and didn't check it for
accuracy.