1 |
/* Get the system load averages. |
/* Get the system load averages. |
2 |
Copyright (C) 1985, 86, 87, 88, 89, 91, 92, 93, 1994, 1995, 1997 |
Copyright (C) 1985, 86, 87, 88, 89, 91, 92, 93, 1994, 1995, 1997, 2003 |
3 |
Free Software Foundation, Inc. |
Free Software Foundation, Inc. |
4 |
|
|
5 |
|
NOTE: The canonical source of this file is maintained with gnulib. |
6 |
|
Bugs can be reported to bug-gnulib@gnu.org. |
7 |
|
|
8 |
This program is free software; you can redistribute it and/or modify |
This program is free software; you can redistribute it and/or modify |
9 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
10 |
the Free Software Foundation; either version 2, or (at your option) |
the Free Software Foundation; either version 2, or (at your option) |
40 |
apollo, DGUX, NeXT, or UMAX is defined; |
apollo, DGUX, NeXT, or UMAX is defined; |
41 |
or we have libkstat; |
or we have libkstat; |
42 |
otherwise, no load average is available. |
otherwise, no load average is available. |
43 |
|
HAVE_NLIST_H nlist.h is available. NLIST_STRUCT defaults |
44 |
|
to this. |
45 |
NLIST_STRUCT Include nlist.h, not a.out.h, and |
NLIST_STRUCT Include nlist.h, not a.out.h, and |
46 |
the nlist n_name element is a pointer, |
the nlist n_name element is a pointer, |
47 |
not an array. |
not an array. |
48 |
NLIST_NAME_UNION struct nlist has an n_un member, not n_name. |
HAVE_STRUCT_NLIST_N_UN_N_NAME `n_un.n_name' is member of `struct nlist'. |
49 |
LINUX_LDAV_FILE [__linux__]: File containing load averages. |
LINUX_LDAV_FILE [__linux__]: File containing load averages. |
50 |
|
HAVE_LOCALE_H locale.h is available. |
51 |
|
HAVE_SETLOCALE The `setlocale' function is available. |
52 |
|
|
53 |
Specific system predefines this file uses, aside from setting |
Specific system predefines this file uses, aside from setting |
54 |
default values if not emacs: |
default values if not emacs: |
106 |
extern int errno; |
extern int errno; |
107 |
#endif |
#endif |
108 |
|
|
109 |
#ifndef HAVE_GETLOADAVG |
#ifdef HAVE_LOCALE_H |
110 |
|
# include <locale.h> |
111 |
|
#endif |
112 |
|
#ifndef HAVE_SETLOCALE |
113 |
|
# define setlocale(Category, Locale) /* empty */ |
114 |
|
#endif |
115 |
|
|
116 |
|
#ifndef HAVE_GETLOADAVG |
117 |
|
|
118 |
/* The existing Emacs configuration files define a macro called |
/* The existing Emacs configuration files define a macro called |
119 |
LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and |
LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and |
301 |
/* Sometimes both MIPS and sgi are defined, so FSCALE was just defined |
/* Sometimes both MIPS and sgi are defined, so FSCALE was just defined |
302 |
above under #ifdef MIPS. But we want the sgi value. */ |
above under #ifdef MIPS. But we want the sgi value. */ |
303 |
# undef FSCALE |
# undef FSCALE |
304 |
# define FSCALE 1000.0 |
# define FSCALE 1000.0 |
305 |
# endif |
# endif |
306 |
|
|
307 |
# if defined (ardent) && defined (titan) |
# if defined (ardent) && defined (titan) |
319 |
# endif /* Not FSCALE. */ |
# endif /* Not FSCALE. */ |
320 |
|
|
321 |
# if !defined (LDAV_CVT) && defined (FSCALE) |
# if !defined (LDAV_CVT) && defined (FSCALE) |
322 |
# define LDAV_CVT(n) (((double) (n)) / FSCALE) |
# define LDAV_CVT(n) (((double) (n)) / FSCALE) |
323 |
# endif |
# endif |
324 |
|
|
325 |
|
# ifndef NLIST_STRUCT |
326 |
|
# if HAVE_NLIST_H |
327 |
|
# define NLIST_STRUCT |
328 |
|
# endif |
329 |
|
# endif |
330 |
|
|
331 |
# if defined(sgi) || (defined(mips) && !defined(BSD)) |
# if defined(sgi) || (defined(mips) && !defined(BSD)) |
332 |
# define FIXUP_KERNEL_SYMBOL_ADDR(nl) ((nl)[0].n_value &= ~(1 << 31)) |
# define FIXUP_KERNEL_SYMBOL_ADDR(nl) ((nl)[0].n_value &= ~(1 << 31)) |
464 |
# include <sys/file.h> |
# include <sys/file.h> |
465 |
# endif |
# endif |
466 |
|
|
|
|
|
467 |
/* Avoid static vars inside a function since in HPUX they dump as pure. */ |
/* Avoid static vars inside a function since in HPUX they dump as pure. */ |
468 |
|
|
469 |
# ifdef NeXT |
# ifdef NeXT |
488 |
/* Offset in kmem to seek to read load average, or 0 means invalid. */ |
/* Offset in kmem to seek to read load average, or 0 means invalid. */ |
489 |
static long offset; |
static long offset; |
490 |
|
|
491 |
#if !defined(VMS) && !defined(sgi) && !defined(__linux__) |
# if !defined(VMS) && !defined(sgi) && !defined(__linux__) |
492 |
static struct nlist nl[2]; |
static struct nlist nl[2]; |
493 |
#endif /* Not VMS or sgi */ |
# endif /* Not VMS or sgi */ |
494 |
|
|
495 |
#ifdef SUNOS_5 |
# ifdef SUNOS_5 |
496 |
static kvm_t *kd; |
static kvm_t *kd; |
497 |
#endif /* SUNOS_5 */ |
# endif /* SUNOS_5 */ |
498 |
|
|
499 |
#endif /* LOAD_AVE_TYPE && !HAVE_LIBKSTAT */ |
#endif /* LOAD_AVE_TYPE && !HAVE_LIBKSTAT */ |
500 |
|
|
602 |
if (count <= 0) |
if (count <= 0) |
603 |
return -1; |
return -1; |
604 |
|
|
605 |
|
/* The following sscanf must use the C locale. */ |
606 |
|
setlocale (LC_NUMERIC, "C"); |
607 |
count = sscanf (ldavgbuf, "%lf %lf %lf", |
count = sscanf (ldavgbuf, "%lf %lf %lf", |
608 |
&load_ave[0], &load_ave[1], &load_ave[2]); |
&load_ave[0], &load_ave[1], &load_ave[2]); |
609 |
|
setlocale (LC_NUMERIC, ""); |
610 |
if (count < 1) |
if (count < 1) |
611 |
return -1; |
return -1; |
612 |
|
|
882 |
strcpy (nl[0].n_name, LDAV_SYMBOL); |
strcpy (nl[0].n_name, LDAV_SYMBOL); |
883 |
strcpy (nl[1].n_name, ""); |
strcpy (nl[1].n_name, ""); |
884 |
# else /* NLIST_STRUCT */ |
# else /* NLIST_STRUCT */ |
885 |
# ifdef NLIST_NAME_UNION |
# ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME |
886 |
nl[0].n_un.n_name = LDAV_SYMBOL; |
nl[0].n_un.n_name = LDAV_SYMBOL; |
887 |
nl[1].n_un.n_name = 0; |
nl[1].n_un.n_name = 0; |
888 |
# else /* not NLIST_NAME_UNION */ |
# else /* not HAVE_STRUCT_NLIST_N_UN_N_NAME */ |
889 |
nl[0].n_name = LDAV_SYMBOL; |
nl[0].n_name = LDAV_SYMBOL; |
890 |
nl[1].n_name = 0; |
nl[1].n_name = 0; |
891 |
# endif /* not NLIST_NAME_UNION */ |
# endif /* not HAVE_STRUCT_NLIST_N_UN_N_NAME */ |
892 |
# endif /* NLIST_STRUCT */ |
# endif /* NLIST_STRUCT */ |
893 |
|
|
894 |
# ifndef SUNOS_5 |
# ifndef SUNOS_5 |
997 |
#endif /* ! HAVE_GETLOADAVG */ |
#endif /* ! HAVE_GETLOADAVG */ |
998 |
|
|
999 |
#ifdef TEST |
#ifdef TEST |
1000 |
int |
void |
1001 |
main (argc, argv) |
main (argc, argv) |
1002 |
int argc; |
int argc; |
1003 |
char **argv; |
char **argv; |