From 438b534ad0e7522cadba20cd3aec41d02b2bc09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20v=2E=20L=C3=B6wis?= Date: Fri, 27 Dec 2002 10:16:42 +0000 Subject: [PATCH] Patch #657889: Implement posix.getloadavg. --- Doc/lib/libos.tex | 8 ++++++++ Modules/posixmodule.c | 25 +++++++++++++++++++++++++ configure | 8 +++++--- configure.in | 5 +++-- pyconfig.h.in | 3 +++ 5 files changed, 44 insertions(+), 5 deletions(-) diff --git a/Doc/lib/libos.tex b/Doc/lib/libos.tex index 6674e8828f7..2e0f8ae646d 100644 --- a/Doc/lib/libos.tex +++ b/Doc/lib/libos.tex @@ -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, diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index b8475af17a0..1d8697e5039 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -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 */ }; diff --git a/configure b/configure index 0103ba18293..207eddfc34d 100755 --- 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 diff --git a/configure.in b/configure.in index b6a266d018c..b4bbdb649ad 100644 --- a/configure.in +++ b/configure.in @@ -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. diff --git a/pyconfig.h.in b/pyconfig.h.in index d63c36c380c..dd52efb3152 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -159,6 +159,9 @@ /* 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