1 | /* $Id: loadavg.c,v 1.1.1.1 2003-01-02 04:56:12 ghudson Exp $ */ |
---|
2 | |
---|
3 | /* Copyright (C) 1998-99 Martin Baulig |
---|
4 | This file is part of LibGTop 1.0. |
---|
5 | |
---|
6 | Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998. |
---|
7 | |
---|
8 | LibGTop is free software; you can redistribute it and/or modify it |
---|
9 | under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2 of the License, |
---|
11 | or (at your option) any later version. |
---|
12 | |
---|
13 | LibGTop is distributed in the hope that it will be useful, but WITHOUT |
---|
14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
15 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
16 | for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with LibGTop; see the file COPYING. If not, write to the |
---|
20 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | #include <config.h> |
---|
25 | #include <glibtop/error.h> |
---|
26 | #include <glibtop/loadavg.h> |
---|
27 | |
---|
28 | static const unsigned long _glibtop_sysdeps_loadavg = |
---|
29 | (1L << GLIBTOP_LOADAVG_LOADAVG); |
---|
30 | |
---|
31 | /* Init function. */ |
---|
32 | |
---|
33 | void |
---|
34 | glibtop_init_loadavg_s (glibtop *server) |
---|
35 | { |
---|
36 | server->sysdeps.loadavg = _glibtop_sysdeps_loadavg; |
---|
37 | } |
---|
38 | |
---|
39 | /* Provides load averange. */ |
---|
40 | |
---|
41 | void |
---|
42 | glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf) |
---|
43 | { |
---|
44 | struct tbl_loadavg loadavg; |
---|
45 | int ret; |
---|
46 | |
---|
47 | glibtop_init_s (&server, GLIBTOP_SYSDEPS_LOADAVG, 0); |
---|
48 | |
---|
49 | memset (buf, 0, sizeof (glibtop_loadavg)); |
---|
50 | |
---|
51 | ret = table (TBL_LOADAVG, 0, (char *) &loadavg, 1, |
---|
52 | sizeof (struct tbl_loadavg)); |
---|
53 | |
---|
54 | if (ret != 1) return; |
---|
55 | |
---|
56 | buf->flags = _glibtop_sysdeps_loadavg; |
---|
57 | |
---|
58 | if (loadavg.tl_lscale == 0) { |
---|
59 | buf->loadavg [0] = loadavg.tl_avenrun.d [0]; |
---|
60 | buf->loadavg [1] = loadavg.tl_avenrun.d [1]; |
---|
61 | buf->loadavg [2] = loadavg.tl_avenrun.d [2]; |
---|
62 | } else { |
---|
63 | buf->loadavg [0] = |
---|
64 | (double) loadavg.tl_avenrun.l [0] / |
---|
65 | (double) loadavg.tl_mach_factor [0]; |
---|
66 | buf->loadavg [1] = |
---|
67 | (double) loadavg.tl_avenrun.l [1] |
---|
68 | / (double) loadavg.tl_mach_factor [1]; |
---|
69 | buf->loadavg [2] = |
---|
70 | (double) loadavg.tl_avenrun.l [2] / |
---|
71 | (double) loadavg.tl_mach_factor [2]; |
---|
72 | } |
---|
73 | } |
---|