views:

76

answers:

3

Hi,

I'm working on linux and am using the values in /proc//stat to log performance data. I am currently logging process user time and process system time. The problem that I have run into is that the code puts out correct values on ubuntu 10.04 but seems to be wrong under fedora 13.

Under fedora it looks like the counter for process user time jiffies just stops dead after a while, even though the process is pulling hefty cpu usage. My suspicion is that perhaps some of the values have been moved about but it is hard to confirm.

What I am looking for is a method of getting a system time/user time breakdown from the command line. Without resorting to reading the /proc//stat file (as it can't be trusted). I have been trying to use ps but the only place I can see an option for this is the 'obsolete bsd sorting method' that I can't get to work.

Is there a way of getting values for process user time and process system time from the command line?

Or is there a better way of extracting performance values in C++ via API functions that I am not aware of?

A: 

what about

time ./program
Guillaume Massé
that's an okayish solution, but it would be great if there was something that could give me the instantaneous (ratio in the last second, or something similar) reading
radman
+1  A: 

If you want to know CPU time from the process itself (or a parent), you can use times():

clock_t times(struct tms *buf);

struct tms {
    clock_t tms_utime;  /* user time */
    clock_t tms_stime;  /* system time */
    clock_t tms_cutime; /* user time of children */
    clock_t tms_cstime; /* system time of children */
};

See the man page for more details of the usage.

caf
that did the trick, thanks!
radman
A: 

In addition to times(), as suggested by caf, you can get more detailed information from getrusage().

http://www.kernel.org/doc/man-pages/online/pages/man2/getrusage.2.html

Bowie Owens