I'm trying to understand how
int getrusage(int who, struct rusage* usage)
works in order to calculate the running time of one my program.
I red the man page, 10 times maybe, and still can't get it. Tried to find something on the web, but nothing but the man page about this function is found.
What is unclear to me is what is stored inside the rusage struct - the man page isn't very clear - so I tried to run it with a debugger and directly see what's inside, but Still do not understand it, particularly how the two structs - timeval ru_utime and timeval ru_stime - work.
What's inside them assume different values, sometime 0, other times 2000 etc.
I ran a simple program with a for loop that allocates and frees memory continually. I used a stopwatch to actually see how many time it takes, it took 5.23 secs. But what I see in those structs seems to be completely unrelated:
Before loop:
ru_utime = { tv_sec = 0, tv_usec = 1000}, ru_stime = { tv_sec = 0, tv_usec = 1000}
After loop:
ru_utime = { tv_sec = 4, tv_usec = 677000}, ru_stime = { tv_sec = 0, tv_usec = 2000}
so, Can anybody explain this to me or give some good link where this is explained?
I shall be very grateful.
Before loop:
ru_utime = { tv_sec = 0, tv_usec = 1000}, ru_stime = { tv_sec = 0, tv_usec = 1000}
after loop
{ tv_sec = 4, tv_usec = 677000}, ru_stime = { tv_sec = 0, tv_usec = 2000} – Root149 Dec 21 '14 at 01:58