diff options
Diffstat (limited to 'gl/getloadavg.c')
| -rw-r--r-- | gl/getloadavg.c | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/gl/getloadavg.c b/gl/getloadavg.c index cfa62735..5faa8faa 100644 --- a/gl/getloadavg.c +++ b/gl/getloadavg.c | |||
| @@ -1,16 +1,16 @@ | |||
| 1 | /* Get the system load averages. | 1 | /* Get the system load averages. |
| 2 | 2 | ||
| 3 | Copyright (C) 1985, 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994, | 3 | Copyright (C) 1985, 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994, |
| 4 | 1995, 1997, 1999, 2000, 2003, 2004, 2005, 2006 Free Software | 4 | 1995, 1997, 1999, 2000, 2003, 2004, 2005, 2006, 2007 Free Software |
| 5 | Foundation, Inc. | 5 | Foundation, Inc. |
| 6 | 6 | ||
| 7 | NOTE: The canonical source of this file is maintained with gnulib. | 7 | NOTE: The canonical source of this file is maintained with gnulib. |
| 8 | Bugs can be reported to bug-gnulib@gnu.org. | 8 | Bugs can be reported to bug-gnulib@gnu.org. |
| 9 | 9 | ||
| 10 | This program is free software; you can redistribute it and/or modify | 10 | This program is free software: you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by | 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation; either version 2, or (at your option) | 12 | the Free Software Foundation; either version 3 of the License, or |
| 13 | any later version. | 13 | (at your option) any later version. |
| 14 | 14 | ||
| 15 | This program is distributed in the hope that it will be useful, | 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| @@ -18,9 +18,7 @@ | |||
| 18 | GNU General Public License for more details. | 18 | GNU General Public License for more details. |
| 19 | 19 | ||
| 20 | You should have received a copy of the GNU General Public License | 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program; if not, write to the Free Software | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 22 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | ||
| 23 | USA. */ | ||
| 24 | 22 | ||
| 25 | /* Compile-time symbols that this file uses: | 23 | /* Compile-time symbols that this file uses: |
| 26 | 24 | ||
| @@ -32,6 +30,8 @@ | |||
| 32 | If that isn't an option, then just put | 30 | If that isn't an option, then just put |
| 33 | AC_CHECK_FUNCS(pstat_getdynamic) in your | 31 | AC_CHECK_FUNCS(pstat_getdynamic) in your |
| 34 | configure.in file. | 32 | configure.in file. |
| 33 | HAVE_LIBPERFSTAT Define this if your system has the | ||
| 34 | perfstat_cpu_total function in libperfstat (AIX). | ||
| 35 | FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist. | 35 | FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist. |
| 36 | KERNEL_FILE Name of the kernel file to nlist. | 36 | KERNEL_FILE Name of the kernel file to nlist. |
| 37 | LDAV_CVT() Scale the load average from the kernel. | 37 | LDAV_CVT() Scale the load average from the kernel. |
| @@ -188,6 +188,8 @@ | |||
| 188 | # include <sys/socket.h> | 188 | # include <sys/socket.h> |
| 189 | # include <net/route.h> | 189 | # include <net/route.h> |
| 190 | # include <sys/table.h> | 190 | # include <sys/table.h> |
| 191 | /* Tru64 4.0D's table.h redefines sys */ | ||
| 192 | # undef sys | ||
| 191 | # endif | 193 | # endif |
| 192 | 194 | ||
| 193 | # if defined (__osf__) && (defined (mips) || defined (__mips__)) | 195 | # if defined (__osf__) && (defined (mips) || defined (__mips__)) |
| @@ -254,7 +256,7 @@ | |||
| 254 | # define LOAD_AVE_TYPE long | 256 | # define LOAD_AVE_TYPE long |
| 255 | # endif | 257 | # endif |
| 256 | 258 | ||
| 257 | # ifdef _AIX | 259 | # if defined _AIX && ! defined HAVE_LIBPERFSTAT |
| 258 | # define LOAD_AVE_TYPE long | 260 | # define LOAD_AVE_TYPE long |
| 259 | # endif | 261 | # endif |
| 260 | 262 | ||
| @@ -309,7 +311,7 @@ | |||
| 309 | # define FSCALE 100.0 | 311 | # define FSCALE 100.0 |
| 310 | # endif | 312 | # endif |
| 311 | 313 | ||
| 312 | # ifdef _AIX | 314 | # if defined _AIX && !defined HAVE_LIBPERFSTAT |
| 313 | # define FSCALE 65536.0 | 315 | # define FSCALE 65536.0 |
| 314 | # endif | 316 | # endif |
| 315 | 317 | ||
| @@ -347,7 +349,7 @@ | |||
| 347 | # define LDAV_SYMBOL "_Loadavg" | 349 | # define LDAV_SYMBOL "_Loadavg" |
| 348 | # endif | 350 | # endif |
| 349 | 351 | ||
| 350 | # if !defined (LDAV_SYMBOL) && ((defined (hpux) && !defined (hp9000s300)) || defined (_SEQUENT_) || defined (SVR4) || defined (ISC) || defined (sgi) || (defined (ardent) && defined (titan)) || defined (_AIX)) | 352 | # if !defined (LDAV_SYMBOL) && ((defined (hpux) && !defined (hp9000s300)) || defined (_SEQUENT_) || defined (SVR4) || defined (ISC) || defined (sgi) || (defined (ardent) && defined (titan)) || (defined (_AIX) && !defined(HAVE_LIBPERFSTAT))) |
| 351 | # define LDAV_SYMBOL "avenrun" | 353 | # define LDAV_SYMBOL "avenrun" |
| 352 | # endif | 354 | # endif |
| 353 | 355 | ||
| @@ -404,6 +406,14 @@ | |||
| 404 | 406 | ||
| 405 | # endif /* LOAD_AVE_TYPE */ | 407 | # endif /* LOAD_AVE_TYPE */ |
| 406 | 408 | ||
| 409 | # if defined HAVE_LIBPERFSTAT | ||
| 410 | # include <libperfstat.h> | ||
| 411 | # include <sys/proc.h> | ||
| 412 | # ifndef SBITS | ||
| 413 | # define SBITS 16 | ||
| 414 | # endif | ||
| 415 | # endif | ||
| 416 | |||
| 407 | # if defined (__GNU__) && !defined (NeXT) | 417 | # if defined (__GNU__) && !defined (NeXT) |
| 408 | /* Note that NeXT Openstep defines __GNU__ even though it should not. */ | 418 | /* Note that NeXT Openstep defines __GNU__ even though it should not. */ |
| 409 | /* GNU system acts much like NeXT, for load average purposes, | 419 | /* GNU system acts much like NeXT, for load average purposes, |
| @@ -568,6 +578,22 @@ getloadavg (double loadavg[], int nelem) | |||
| 568 | 578 | ||
| 569 | # endif /* hpux && HAVE_PSTAT_GETDYNAMIC */ | 579 | # endif /* hpux && HAVE_PSTAT_GETDYNAMIC */ |
| 570 | 580 | ||
| 581 | # if ! defined LDAV_DONE && defined HAVE_LIBPERFSTAT | ||
| 582 | # define LDAV_DONE | ||
| 583 | # undef LOAD_AVE_TYPE | ||
| 584 | /* Use perfstat_cpu_total because we don't have to be root. */ | ||
| 585 | { | ||
| 586 | perfstat_cpu_total_t cpu_stats; | ||
| 587 | int result = perfstat_cpu_total (NULL, &cpu_stats, sizeof cpu_stats, 1); | ||
| 588 | if (result == -1) | ||
| 589 | return result; | ||
| 590 | loadavg[0] = cpu_stats.loadavg[0] / (double)(1 << SBITS); | ||
| 591 | loadavg[1] = cpu_stats.loadavg[1] / (double)(1 << SBITS); | ||
| 592 | loadavg[2] = cpu_stats.loadavg[2] / (double)(1 << SBITS); | ||
| 593 | elem = 3; | ||
| 594 | } | ||
| 595 | # endif | ||
| 596 | |||
| 571 | # if !defined (LDAV_DONE) && (defined (__linux__) || defined (__CYGWIN__)) | 597 | # if !defined (LDAV_DONE) && (defined (__linux__) || defined (__CYGWIN__)) |
| 572 | # define LDAV_DONE | 598 | # define LDAV_DONE |
| 573 | # undef LOAD_AVE_TYPE | 599 | # undef LOAD_AVE_TYPE |
