/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1987, 1991 by John E. Lloyd and Mike Parker.	    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
/*---------McGill-Computer-Vision-and-Robotics-Laboratory--C-Module---------
 *		
 * NAME:	cputime, int_cputime
 *
 *
 * USAGE:
 *		time = cputime (option);
 *		  double time;
 *		  enum cputime_option;
 *
 * DESCRIPTION: Returns the time consumed by a process. The options are as
 *		follows:
 *
 *		  System  : Time spent executing system calls for the process.
 *		  User    : Time spent executing the processes own code.
 *		  All	  : All time spent executing for the process.
 * 
 * NOTES:
 *
 * AUTHOR/DATE: John Lloyd and Mike Parker, September 1984
 *
 * UPDATES:
 *
 *-------------McGill-Computer-Vision-and-Robotics-Laboratory--------------*/

#include <sys/time.h>
#include <sys/resource.h>
#include "useful.h"

double cputime(option)
enum cputime_option option;
{
 static struct rusage ru;
 double result;

 getrusage(RUSAGE_SELF,&ru);
 
 result = 0;

 if (option == System || option == All)
    result = ru.ru_stime.tv_sec + (ru.ru_stime.tv_usec/1000000.);

 if (option == User || option == All)
    result = ru.ru_utime.tv_sec + (ru.ru_utime.tv_usec/1000000.);
    
 return (result);
}
