From 451f9f9d6cd066f792c5600ed8852dddcbb18234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Dejean?= Date: Mon, 12 Dec 2005 13:32:06 +0000 Subject: Improved so that it doesn't stat(2) every /proc//. * proclist.c: (glibtop_get_proclist_s): Improved so that it doesn't stat(2) every /proc//. --- sysdeps/linux/ChangeLog | 6 ++++++ sysdeps/linux/proclist.c | 13 ++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'sysdeps/linux') diff --git a/sysdeps/linux/ChangeLog b/sysdeps/linux/ChangeLog index 3c3d7e6a..3ff090dc 100644 --- a/sysdeps/linux/ChangeLog +++ b/sysdeps/linux/ChangeLog @@ -1,3 +1,9 @@ +2005-12-12 Benoît Dejean + + * proclist.c: (glibtop_get_proclist_s): + + Improved so that it doesn't stat(2) every /proc//. + 2005-12-07 Benoît Dejean * procmap.c: (glibtop_get_proc_map_s): diff --git a/sysdeps/linux/proclist.c b/sysdeps/linux/proclist.c index 34bb72c0..6e5f48ab 100644 --- a/sysdeps/linux/proclist.c +++ b/sysdeps/linux/proclist.c @@ -82,18 +82,13 @@ glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf, /* read every every entry in /proc */ while((entry = readdir (proc))) { - char buffer [64]; /* enough to hold "/proc/%ld" */ unsigned pid; - char *end; - pid = strtoul(entry->d_name, &end, 0); - if(*end != '\0') continue; - - /* is it really a directory? */ - sprintf (buffer, "/proc/%u", pid); - if (stat (buffer, &statb)) continue; - if (!S_ISDIR (statb.st_mode)) continue; + if (entry->d_type != DT_DIR) + continue; + if (!(pid = strtoul(entry->d_name, NULL, 10))) + continue; switch (which & GLIBTOP_KERN_PROC_MASK) { case GLIBTOP_KERN_PROC_ALL: -- cgit v1.2.1