diff options
author | Benoît Dejean <bdejean@src.gnome.org> | 2005-12-12 13:32:06 +0000 |
---|---|---|
committer | Benoît Dejean <bdejean@src.gnome.org> | 2005-12-12 13:32:06 +0000 |
commit | 451f9f9d6cd066f792c5600ed8852dddcbb18234 (patch) | |
tree | 8a2957e82822b64b76be8fd6269d72552b8ad348 | |
parent | 52fa57a39bf5d46cff7e0a53047bce5892eab85e (diff) | |
download | libgtop-451f9f9d6cd066f792c5600ed8852dddcbb18234.tar.gz |
Improved so that it doesn't stat(2) every /proc/<PID>/.
* proclist.c: (glibtop_get_proclist_s):
Improved so that it doesn't stat(2) every /proc/<PID>/.
-rw-r--r-- | sysdeps/linux/ChangeLog | 6 | ||||
-rw-r--r-- | sysdeps/linux/proclist.c | 13 |
2 files changed, 10 insertions, 9 deletions
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 <benoit@placenet.org> + + * proclist.c: (glibtop_get_proclist_s): + + Improved so that it doesn't stat(2) every /proc/<PID>/. + 2005-12-07 Benoît Dejean <benoit@placenet.org> * 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: |