because of the variability of whose "time" you get and so forth, i gave up and 
wrote a linux-specific
function to do this. there are of course pros and cons, but take this if you 
want:

#include        "basic.h"
#include        "libng.h"
#include        "libw.h"
#include        <asm-i386/param.h>

void
resource_summary(FILE *fp)
{
        char buf[4096];
        FILE *mp;
        int r_tps, r_rss, r_sp, r_text, r_lib,  r_data, r_dt, r_pid;
        unsigned long r_utime, r_stime, r_vsize;
        long r_nthread;

        sprintf(buf, "/proc/%d/statm", getpid());
        if((mp = fopen(buf, "r")) == NULL){
                perror(buf);
                return;
        }
        if(fscanf(mp, "%d %d %d %d %d %d %d", &r_tps, &r_rss, &r_sp, &r_text, 
&r_lib, &r_data, &r_dt) != 7){
                fprintf(stderr, "bad format statm\n");
                fclose(mp);
                return;
        }
        fclose(mp);
        sprintf(buf, "/proc/%d/stat", getpid());
        if((mp = fopen(buf, "r")) == NULL){
                perror(buf);
                return;
        }
        if(fscanf(mp, "%d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu \
                        %lu %*d %*d %*d %*d %ld %*u %*u %lu %*u %*u %*u %*u %*u 
\
                        %*u %*u %*u %*u %*u %*u %*u %*u %*d %*d %*u %*u %*u %*u 
%*d ",
                        &r_pid, &r_utime, &r_stime, &r_nthread, &r_vsize) != 5){
                fprintf(stderr, "bad format stat\n");
                fclose(mp);
                return;
        }
        fclose(mp);
        fprintf(fp, "tps=%d rss=%d sp=%d text=%d lib=%d data=%d pid=%d 
utime=%.1fs stime=%.1fs nthr=%ld vs=%.1fMB\n",
                r_tps, r_rss, r_sp, r_text, r_lib, r_data, r_pid, 
r_utime/(double)HZ, r_stime/(double)HZ, r_nthread, r_vsize/(1024*1024.0));
}

of course, its only doing what i was interested in but it may be a useful start.

On Jun 19, 2012, at 10:27 AM, [email protected] wrote:

> /usr/bin/time will provide a lot of stats, take a look and see how close it 
> comes to what you want.
> 
> David Lang
> 
> On Tue, 19 Jun 2012, Christopher R Webber wrote:
> 
>> Date: Tue, 19 Jun 2012 05:34:14 -0700
>> From: Christopher R Webber <[email protected]>
>> To: [email protected]
>> Subject: [lopsa-tech] Job/Process Profiling
>> All,
>> 
>> I have students and postdocs that write software as part of their research 
>> and occasionally they want to answer questions like:
>> - How much memory does this take?
>> - How much time does this take?
>> - What does CPU utilization look like?
>> 
>> To add to the list above, I would love to see I/O statistics as well. Any 
>> suggestions on a command line profiling tool for linux that will do this? 
>> While most of my users are savy enough to use the command line, I would like 
>> to see something where you don't have to understand a whole lot of details 
>> to get some basic info.
>> 
>> Ideas?
>> 
>> Thanks.
>> 
>> -- cwebber
>> 
>> Christopher Webber - Systems Administrator
>> Bioinformatics - University of California, Riverside
>> 
>> Twitter: @cwebber
>> Tel: 951.867.7108
>> http://cwebber.ucr.edu
>> 
> _______________________________________________
> Tech mailing list
> [email protected]
> https://lists.lopsa.org/cgi-bin/mailman/listinfo/tech
> This list provided by the League of Professional System Administrators
> http://lopsa.org/
> _______________________________________________
> Tech mailing list
> [email protected]
> https://lists.lopsa.org/cgi-bin/mailman/listinfo/tech
> This list provided by the League of Professional System Administrators
> http://lopsa.org/


------------------
Andrew Hume  (best -> Telework) +1 623-551-2845
[email protected]  (Work) +1 973-236-2014
AT&T Labs - Research; member of USENIX and LOPSA




_______________________________________________
Tech mailing list
[email protected]
https://lists.lopsa.org/cgi-bin/mailman/listinfo/tech
This list provided by the League of Professional System Administrators
 http://lopsa.org/

Reply via email to