Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Re: Strange system time values through *getrusage* system call.
  1995-12-01  5:00 Strange system time values through *getrusage* system call Pranab Banerjee
@ 1995-12-01  5:00 ` Mike Iglesias
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Iglesias @ 1995-12-01  5:00 UTC (permalink / raw)


In article <49ni24$ek0@tako.info.ucla.edu>,
Pranab Banerjee <pbanerje@anima.ucla.edu> wrote:
>Can anyone explain the following results that I am getting from "getrusage" 
>system function call on a DEC Alphastation running OSF1 V3.2.
> [snip]
> long sys_time_1, sys_time_2 ;
> [snip]
>  sys_time_1 = r_usage->ru_stime.tv_usec ;

tv_usec is an int on an Alpha, not a long.  Your code would probably work
ok on a Sun, but you should change sys_time_1 and sys_time_2 to be int on
the Alpha.


-- 
Mike Iglesias                        Internet:    iglesias@draco.acs.uci.edu
University of California, Irvine     phone:       (714) 824-6926
Office of Academic Computing         FAX:         (714) 824-2069




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Strange system time values through *getrusage* system call.
@ 1995-12-01  5:00 Pranab Banerjee
  1995-12-01  5:00 ` Mike Iglesias
  0 siblings, 1 reply; 2+ messages in thread
From: Pranab Banerjee @ 1995-12-01  5:00 UTC (permalink / raw)


Can anyone explain the following results that I am getting from "getrusage" 
system function call on a DEC Alphastation running OSF1 V3.2.

I am trying to find the CPU time used to compute a function that does not
do any I/O at all inside it. It essentially scales a 2D image (floating point
array) by interpolation. 

Here is the relevant code segment:

/**********************************************************/

#include <stdio.h>
#include <malloc.h>
#include <math.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/resource.h>

extern void my_func() ;

void main()
{
 long sys_time_1, sys_time_2 ;
 struct rusage *r_usage ;

 r_usage = (struct rusage *)malloc(sizeof(struct rusage)) ;
 	.
	.
	.

 /* find the system time used so far and save it in sys_time_1 */
 if ( (status = getrusage(RUSAGE_SELF, r_usage)) != 0 )
 {
  perror("getrusage error") ;
 }
 else
 {
  sys_time_1 = r_usage->ru_stime.tv_usec ;
 }

 /* compute the function now */
 my_func(...) ;

 /* find the system time used till now and save it in sys_time_2 */

 if ( (status = getrusage(RUSAGE_SELF, r_usage)) != 0 )
 {
  perror("getrusage error") ;
 }
 else
 {
  sys_time_2 = r_usage->ru_stime.tv_usec ;
 }

 /* Find the system time used by the function as (sys_time_2 - sys_tine_1) */ 
 printf("System time used for interpolation = %d\n", (sys_time_2 - sys_time_1) ) ;

        .
	.
	.
}

/**********************************************************/

I was assuming that this would give me the actual CPU time used for the
computation of the function "my_func" in microseconds. But I seem to get
all sorts of values ranging from 3904 to as high as 11712 when I 
ran the code 50 times. 

Isn't this number supposed to be the same every time if it is truly
giving me the "system time" ( in terms of {(CPU cycles)/(clock freq)} ) ? 
Or am I missing something?

Also, when I look at the manpage for "clock" system function, it says

"The clock() function is made obsolete by the getrusage() function; however,
 it is included for compatibility with older BSD programs." 

I thought this meant I could still use "clock" instead of "getrusage" 
and would get similar results (in microseconds - according to the man page). 
But if I change the two lines (in the above block):

 sys_time_1 = r_usage->ru_stime.tv_usec ;
and 
 sys_time_2 = r_usage->ru_stime.tv_usec ;

to 

 sys_time_1 = clock() ;
and 
 sys_time_2 = clock() ;

and then run the code, I get very different numbers ranging from 183326
to 216658! Much larger than the CPU times I got through "getrusage".

Any clarifications/suggestions/explanations would be highly appreciated.

Thank you.

It will very helpful if you please send me a copy of your reply at my direct
e-mail address : <pbanerjee@mail.nuc.ucla.edu> along with your public reply 
on the newsgroup.

Thank you.

Sincerely,


-Pranab K. Banerjee
 Crump Institute for Biological Imaging
 University of California, Los Angeles
 e-mail: pbanerjee@mail.nuc.ucla.edu



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1995-12-01  5:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-12-01  5:00 Strange system time values through *getrusage* system call Pranab Banerjee
1995-12-01  5:00 ` Mike Iglesias

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox