New file.

1998-06-07  Martin Baulig  <martin@home-of-linux.org>

	* sysdeps/linux/glibtop_machine.h: New file.

	* sysdeps/linux/*.c: Performance optimizations. We now use
	`open' and `read' instead of `fopen' and `fscanf'.
This commit is contained in:
Martin Baulig
1998-06-07 20:38:02 +00:00
committed by Martin Baulig
parent c84923132a
commit 9c9ad03d60
13 changed files with 456 additions and 199 deletions

View File

@@ -20,17 +20,21 @@
Boston, MA 02111-1307, USA. */
#include <config.h>
#include <glibtop/error.h>
#include <glibtop/uptime.h>
static unsigned long _glibtop_sysdeps_uptime =
(1 << GLIBTOP_UPTIME_UPTIME) + (1 << GLIBTOP_UPTIME_IDLETIME);
#define FILENAME "/proc/uptime"
/* Provides uptime and idle time. */
void
glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
{
FILE *f;
int fd, ret;
char buffer [BUFSIZ];
glibtop_init_r (&server, 0, 0);
@@ -38,10 +42,17 @@ glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
buf->flags = _glibtop_sysdeps_uptime;
f = fopen ("/proc/uptime", "r");
if (!f) return;
fd = open (FILENAME, O_RDONLY);
if (fd == -1)
glibtop_error_r (server, "open (%s): %s",
FILENAME, strerror (errno));
fscanf (f, "%lf %lf\n", &buf->uptime, &buf->idletime);
ret = read (fd, buffer, BUFSIZ);
if (ret == -1)
glibtop_error_r (server, "read (%s): %s",
FILENAME, strerror (errno));
fclose (f);
sscanf (buffer, "%lf %lf\n", &buf->uptime, &buf->idletime);
close (fd);
}