Mercurial > hg > xemacs-beta
comparison src/getloadavg.c @ 70:131b0175ea99 r20-0b30
Import from CVS: tag r20-0b30
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:02:59 +0200 |
parents | 56c54cf7c5b6 |
children | 6a378aca36af |
comparison
equal
deleted
inserted
replaced
69:804d1389bcd6 | 70:131b0175ea99 |
---|---|
1 /* Get the system load averages. | 1 /* Get the system load averages. |
2 Copyright (C) 1985, 86, 87, 88, 89, 91, 92, 93, 1994, 1995 | 2 Copyright (C) 1985, 86, 87, 88, 89, 91, 92, 93, 1994, 1995 |
3 Free Software Foundation, Inc. | 3 Free Software Foundation, Inc. |
4 | 4 |
5 This file is part of XEmacs. | 5 This program is free software; you can redistribute it and/or modify |
6 | 6 it under the terms of the GNU General Public License as published by |
7 XEmacs is free software; you can redistribute it and/or modify it | 7 the Free Software Foundation; either version 2, or (at your option) |
8 under the terms of the GNU General Public License as published by the | 8 any later version. |
9 Free Software Foundation; either version 2, or (at your option) any | 9 |
10 later version. | 10 This program is distributed in the hope that it will be useful, |
11 | 11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT | 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 13 GNU General Public License for more details. |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | 14 |
15 for more details. | 15 You should have received a copy of the GNU General Public License |
16 | 16 along with this program; if not, write to the Free Software |
17 You should have received a copy of the GNU General Public License | 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
18 along with XEmacs; see the file COPYING. If not, write to | 18 USA. */ |
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
20 Boston, MA 02111-1307, USA. */ | |
21 | |
22 | 19 |
23 /* Compile-time symbols that this file uses: | 20 /* Compile-time symbols that this file uses: |
24 | 21 |
25 FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist. | 22 FIXUP_KERNEL_SYMBOL_ADDR() Adjust address in returned struct nlist. |
26 KERNEL_FILE Pathname of the kernel to nlist. | 23 KERNEL_FILE Pathname of the kernel to nlist. |
96 extern int errno; | 93 extern int errno; |
97 #endif | 94 #endif |
98 | 95 |
99 #ifndef HAVE_GETLOADAVG | 96 #ifndef HAVE_GETLOADAVG |
100 | 97 |
98 | |
101 /* The existing Emacs configuration files define a macro called | 99 /* The existing Emacs configuration files define a macro called |
102 LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and | 100 LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and |
103 returns the load average multiplied by 100. What we actually want | 101 returns the load average multiplied by 100. What we actually want |
104 is a macro called LDAV_CVT, which returns the load average as an | 102 is a macro called LDAV_CVT, which returns the load average as an |
105 unmultiplied double. | 103 unmultiplied double. |
517 into the first NELEM elements of LOADAVG. | 515 into the first NELEM elements of LOADAVG. |
518 Return the number written (never more than 3, but may be less than NELEM), | 516 Return the number written (never more than 3, but may be less than NELEM), |
519 or -1 if an error occurred. */ | 517 or -1 if an error occurred. */ |
520 | 518 |
521 int | 519 int |
522 getloadavg (double loadavg[], int nelem) | 520 getloadavg (loadavg, nelem) |
521 double loadavg[]; | |
522 int nelem; | |
523 { | 523 { |
524 int elem = 0; /* Return value. */ | 524 int elem = 0; /* Return value. */ |
525 | 525 |
526 #ifdef NO_GET_LOAD_AVG | 526 #ifdef NO_GET_LOAD_AVG |
527 #define LDAV_DONE | 527 #define LDAV_DONE |
565 for (elem = 0; elem < nelem; elem++) | 565 for (elem = 0; elem < nelem; elem++) |
566 loadavg[elem] = (buf + 6 + elem)->value.ul / 256.0; | 566 loadavg[elem] = (buf + 6 + elem)->value.ul / 256.0; |
567 free(buf); | 567 free(buf); |
568 | 568 |
569 #endif /* HAVE_KSTAT_H && HAVE_LIBKSTAT */ | 569 #endif /* HAVE_KSTAT_H && HAVE_LIBKSTAT */ |
570 | |
571 #if !defined (LDAV_DONE) && defined (HAVE_SYS_PSTAT_H) | |
572 #define LDAV_DONE | |
573 /* This is totally undocumented, and is not guaranteed to work, but | |
574 mayhap it might .... If it does work, it will work only on HP-UX | |
575 8.0 or later. -- Darryl Okahata <darrylo@sr.hp.com> */ | |
576 #undef LOAD_AVE_TYPE /* Make sure these don't exist. */ | |
577 #undef LOAD_AVE_CVT | |
578 #undef LDAV_SYMBOL | |
579 struct pst_dynamic procinfo; | |
580 union pstun statbuf; | |
581 | |
582 statbuf.pst_dynamic = &procinfo; | |
583 if (pstat (PSTAT_DYNAMIC, statbuf, sizeof (struct pst_dynamic), 0, 0) == -1) | |
584 return (-1); | |
585 loadavg[elem++] = procinfo.psd_avg_1_min; | |
586 loadavg[elem++] = procinfo.psd_avg_5_min; | |
587 loadavg[elem++] = procinfo.psd_avg_15_min; | |
588 #endif /* HPUX */ | |
589 | |
590 #endif /* XEMACS */ | 570 #endif /* XEMACS */ |
591 | 571 |
592 #if !defined (LDAV_DONE) && defined (__linux__) | 572 #if !defined (LDAV_DONE) && defined (__linux__) |
593 #define LDAV_DONE | 573 #define LDAV_DONE |
594 #undef LOAD_AVE_TYPE | 574 #undef LOAD_AVE_TYPE |
888 #else /* NLIST_STRUCT */ | 868 #else /* NLIST_STRUCT */ |
889 #ifdef NLIST_NAME_UNION | 869 #ifdef NLIST_NAME_UNION |
890 nl[0].n_un.n_name = LDAV_SYMBOL; | 870 nl[0].n_un.n_name = LDAV_SYMBOL; |
891 nl[1].n_un.n_name = 0; | 871 nl[1].n_un.n_name = 0; |
892 #else /* not NLIST_NAME_UNION */ | 872 #else /* not NLIST_NAME_UNION */ |
893 nl[0].n_name = (char *) LDAV_SYMBOL; | 873 nl[0].n_name = LDAV_SYMBOL; |
894 nl[1].n_name = 0; | 874 nl[1].n_name = 0; |
895 #endif /* not NLIST_NAME_UNION */ | 875 #endif /* not NLIST_NAME_UNION */ |
896 #endif /* NLIST_STRUCT */ | 876 #endif /* NLIST_STRUCT */ |
897 | 877 |
898 #ifndef SUNOS_5 | 878 #ifndef SUNOS_5 |
1000 | 980 |
1001 #endif /* ! HAVE_GETLOADAVG */ | 981 #endif /* ! HAVE_GETLOADAVG */ |
1002 | 982 |
1003 #ifdef TEST | 983 #ifdef TEST |
1004 void | 984 void |
1005 main (int argc, char **argv) | 985 main (argc, argv) |
986 int argc; | |
987 char **argv; | |
1006 { | 988 { |
1007 int naptime = 0; | 989 int naptime = 0; |
1008 | 990 |
1009 if (argc > 1) | 991 if (argc > 1) |
1010 naptime = atoi (argv[1]); | 992 naptime = atoi (argv[1]); |