From c3e85cef7386f01ce20d49602a2bd77c385844cb Mon Sep 17 00:00:00 2001 From: Craig Small Date: Wed, 1 Jul 2015 21:47:30 +1000 Subject: [PATCH] library: loadavg change to procps_loadavg --- proc/libprocps.sym | 3 +-- proc/sysinfo.c | 19 +++++++++++++++---- proc/sysinfo.h | 2 +- proc/uptime.c | 2 +- tload.c | 5 ++--- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/proc/libprocps.sym b/proc/libprocps.sym index 714e786d..75a43995 100644 --- a/proc/libprocps.sym +++ b/proc/libprocps.sym @@ -1,7 +1,6 @@ LIBPROCPS_0 { global: closeproc; - cpuinfo; dev_to_tty; escape_command; escape_str; @@ -34,7 +33,6 @@ global: kb_swap_free; kb_swap_total; kb_swap_used; - loadavg; look_up_our_self; lookup_wchan; meminfo; @@ -52,6 +50,7 @@ global: procps_cpu_count; procps_hertz_get; procps_linux_version; + procps_loadavg; procps_meminfo_new; procps_meminfo_read; procps_meminfo_ref; diff --git a/proc/sysinfo.c b/proc/sysinfo.c index bcd78e87..e4b234cf 100644 --- a/proc/sysinfo.c +++ b/proc/sysinfo.c @@ -162,9 +162,20 @@ static void init_libproc(void){ page_bytes = sysconf(_SC_PAGESIZE); } - -/***********************************************************************/ -PROCPS_EXPORT int loadavg(double *restrict av1, double *restrict av5, double *restrict av15) +/* + * procps_loadavg: + * @av1: location to store 1 minute load average + * @av5: location to store 5 minute load average + * @av15: location to store 15 minute load average + * + * Find the 1,5 and 15 minute load average of the system + * + * Returns: 0 on success <0 on error + */ +PROCPS_EXPORT int procps_loadavg( + double *restrict av1, + double *restrict av5, + double *restrict av15) { double avg_1=0, avg_5=0, avg_15=0; char *savelocale; @@ -174,7 +185,7 @@ PROCPS_EXPORT int loadavg(double *restrict av1, double *restrict av5, double *re savelocale = strdup(setlocale(LC_NUMERIC, NULL)); setlocale(LC_NUMERIC, "C"); if (sscanf(buf, "%lf %lf %lf", &avg_1, &avg_5, &avg_15) < 3) { - retval = -ERANGE; + retval = -ERANGE; } setlocale(LC_NUMERIC, savelocale); free(savelocale); diff --git a/proc/sysinfo.h b/proc/sysinfo.h index 10630078..57ff0fb8 100644 --- a/proc/sysinfo.h +++ b/proc/sysinfo.h @@ -11,7 +11,7 @@ extern long page_bytes; /* this architecture's bytes per page */ extern int uptime (double *uptime_secs, double *idle_secs); extern unsigned long getbtime(void); -int loadavg(double *av1, double *av5, double *av15); +int procps_loadavg(double *av1, double *av5, double *av15); long procps_hertz_get(void); long procps_cpu_count(void); diff --git a/proc/uptime.c b/proc/uptime.c index 13693a2a..02bdf1fe 100644 --- a/proc/uptime.c +++ b/proc/uptime.c @@ -131,7 +131,7 @@ PROCPS_EXPORT char *procps_uptime_sprint(void) pos += sprintf(upbuf + pos, "%d min, ", uphours, upminutes); users = count_users(); - loadavg(&av1, &av5, &av15); + procps_loadavg(&av1, &av5, &av15); pos += sprintf(upbuf + pos, "%2d user%s, load average: %.2f, %.2f, %.2f", users, users == 1 ? "" : "s", diff --git a/tload.c b/tload.c index 6df9ef5d..a1fc03ff 100644 --- a/tload.c +++ b/tload.c @@ -24,8 +24,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "proc/version.h" -#include "proc/sysinfo.h" +#include #include "c.h" #include "fileutils.h" #include "nls.h" @@ -167,7 +166,7 @@ int main(int argc, char **argv) if (scale_fact < max_scale) scale_fact *= 2.0; /* help it drift back up. */ - loadavg(&av[0], &av[1], &av[2]); + procps_loadavg(&av[0], &av[1], &av[2]); do { lines = av[0] * scale_fact;