]> granicus.if.org Git - python/commitdiff
Patch #657889: Implement posix.getloadavg.
authorMartin v. Löwis <martin@v.loewis.de>
Fri, 27 Dec 2002 10:16:42 +0000 (10:16 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Fri, 27 Dec 2002 10:16:42 +0000 (10:16 +0000)
Doc/lib/libos.tex
Modules/posixmodule.c
configure
configure.in
pyconfig.h.in

index 6674e8828f78eeef9cf49abce5fa746695fb3864..2e0f8ae646dfcf30600d8cbd1495c392b28a0cd1 100644 (file)
@@ -1431,6 +1431,14 @@ This can be used to determine the set of names known to the system.
 Availability: \UNIX.
 \end{datadesc}
 
+\begin{funcdesc}{getloadavg}{}
+Return the number of processes in the system run queue averaged over
+the last 1, 5, and 15 minutes or raises OSError if the load average
+was unobtainable.
+
+\versionadded{2.3}
+\end{funcdesc}
+
 \begin{funcdesc}{sysconf}{name}
 Return integer-valued system configuration values.
 If the configuration value specified by \var{name} isn't defined,
index b8475af17a0598584a2f4196db12e83343436cfc..1d8697e50396c4f5c1b202ef957a6aac2e6a9356 100644 (file)
@@ -7135,6 +7135,28 @@ win32_startfile(PyObject *self, PyObject *args)
 }
 #endif
 
+#ifdef HAVE_GETLOADAVG
+PyDoc_STRVAR(posix_getloadavg__doc__,
+"getloadavg() -> (float, float, float)\n\n\
+Return the number of processes in the system run queue averaged over\n\
+the last 1, 5, and 15 minutes or raises OSError if the load average\n\
+was unobtainable");
+
+static PyObject *
+posix_getloadavg(PyObject *self, PyObject *args)
+{
+    double loadavg[3];
+    if (!PyArg_ParseTuple(args, ":getloadavg"))
+        return NULL;
+    if (getloadavg(loadavg, 3)!=3) {
+        PyErr_SetString(PyExc_OSError, "Load averages are unobtainable");
+        return NULL;
+    } else
+        return Py_BuildValue("ddd", loadavg[0], loadavg[1], loadavg[2]);
+}
+#endif
+
+
 static PyMethodDef posix_methods[] = {
        {"access",      posix_access, METH_VARARGS, posix_access__doc__},
 #ifdef HAVE_TTYNAME
@@ -7408,6 +7430,9 @@ static PyMethodDef posix_methods[] = {
        {"abort",       posix_abort, METH_VARARGS, posix_abort__doc__},
 #ifdef MS_WINDOWS
        {"_getfullpathname",    posix__getfullpathname, METH_VARARGS, NULL},
+#endif
+#ifdef HAVE_GETLOADAVG
+       {"getloadavg",  posix_getloadavg, METH_VARARGS, posix_getloadavg__doc__},
 #endif
        {NULL,          NULL}            /* Sentinel */
 };
index 0103ba18293f705aa1aae106289ff4a70527bb05..207eddfc34d78ced8abcc6e47565a16995afccf0 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 1.377 .
+# From configure.in Revision: 1.378 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.53 for python 2.3.
 #
@@ -12007,11 +12007,13 @@ echo "${ECHO_T}MACHDEP_OBJS" >&6
 
 
 
+
 
 
 for ac_func in alarm chown clock confstr ctermid execv \
  fchdir flock fork fsync fdatasync fpathconf ftime ftruncate \
- gai_strerror getgroups getlogin getpeername getpgid getpid getpwent getwd \
+ gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
+ getpriority getpwent getwd \
  hstrerror inet_pton kill killpg lchown lstat mkfifo mknod mktime \
  mremap nice pathconf pause plock poll pthread_init \
  putenv readlink \
@@ -12019,7 +12021,7 @@ for ac_func in alarm chown clock confstr ctermid execv \
  setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \
  sigaction siginterrupt sigrelse strftime strptime \
  sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
- truncate uname unsetenv utimes waitpid wcscoll _getpty getpriority
+ truncate uname unsetenv utimes waitpid wcscoll _getpty
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
 echo "$as_me:$LINENO: checking for $ac_func" >&5
index b6a266d018cd39f54519e4797a1b2e702a4eeb44..b4bbdb649ad0168fb88dbdbebc4b7e1134b04ebd 100644 (file)
@@ -1762,7 +1762,8 @@ AC_MSG_RESULT(MACHDEP_OBJS)
 # checks for library functions
 AC_CHECK_FUNCS(alarm chown clock confstr ctermid execv \
  fchdir flock fork fsync fdatasync fpathconf ftime ftruncate \
- gai_strerror getgroups getlogin getpeername getpgid getpid getpwent getwd \
+ gai_strerror getgroups getlogin getloadavg getpeername getpgid getpid \
+ getpriority getpwent getwd \
  hstrerror inet_pton kill killpg lchown lstat mkfifo mknod mktime \
  mremap nice pathconf pause plock poll pthread_init \
  putenv readlink \
@@ -1770,7 +1771,7 @@ AC_CHECK_FUNCS(alarm chown clock confstr ctermid execv \
  setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \
  sigaction siginterrupt sigrelse strftime strptime \
  sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
- truncate uname unsetenv utimes waitpid wcscoll _getpty getpriority)
+ truncate uname unsetenv utimes waitpid wcscoll _getpty)
 
 # For some functions, having a definition is not sufficient, since
 # we want to take their address.
index d63c36c380c6b2b4bf121d3c6592bec5dd7af98d..dd52efb315267924d203f2c0b290e9043ea1aaed 100644 (file)
 /* Define this if you have the 6-arg version of gethostbyname_r(). */
 #undef HAVE_GETHOSTBYNAME_R_6_ARG
 
+/* Define to 1 if you have the `getloadavg' function. */
+#undef HAVE_GETLOADAVG
+
 /* Define to 1 if you have the `getlogin' function. */
 #undef HAVE_GETLOGIN