On Feb 5, 5:28*pm, Peter Makholm <pe...@makholm.net> wrote:
> saurabh hirani <saurabh.hir...@gmail.com> writes:
> > 3. Load average I can get through /proc/loadavg, free memory through /
> > proc/meminfo. But how to obtain free disk space through proc? I am
> > talking about 2.6.x kernels on RHEL4. I want to use /proc as much as I
> > can because I would be reading from a file and not launching a shell.
>
> Using Linux::SysInfo should be even faster than reading and parsing
> two files in /proc. This module is a simple wrapper around the
> Linux-specific sysinfo()-system call.
>
> Free disk space can be detected by Filesys:
f which is a wrapper
> around the statfs() or statvfs() systemcalls. Again a wee bit faster
> than opening a file and parsing the values.
>
> Filesys:
f should be portable on POSIX systems, but Linux::SysInfo is
> linux-only. But reading anything directly from /proc/ would also be
> very linux-specific.
Thanks Peter. That was really useful. I will be using these modules -
for their speed, ease of use and options provided which might be
useful in the future. My daemon is not going to bomb update queries to
the other daemon as frequently as once a second, but these modules
really do pump up the speed from okay to burn-the-road. Just to
compare system call and Filesys:

f, I wrote a small perl program
which calls getting free disk using system call to df and using the
module. I profiled them by running them around 1000 times and this was
the output of dprofpp:
Forking df and getting the time:
Total Elapsed Time = 42.04899 Seconds
User+System Time = 5.668994 Seconds
Inclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
96.7 5.485 5.485 1000 0.0055 0.0055 main::get_freequeue
Using df from the module
Total Elapsed Time = 0.618107 Seconds
User+System Time = 0.768107 Seconds
Inclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c Name
92.1 0.013 0.708 1000 0.0000 0.0007 main::get_freequeue
90.4 0.013 0.695 1000 0.0000 0.0007 Filesys:

f::df
88.7 0.682 0.682 1000 0.0007 0.0007 Filesys:

f::_df
The difference is staggering.
Thanks again guys for your viewpoints. They really helped.
regards,
Saurabh