1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
/* $Id: $ */
/* Copyright (C) 1997 Sverre Hvammen Johansen,
* Department of Informatics, University of Oslo.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "cim.h"
#include "config.h"
/******************************************************************************
LONG REAL PROCEDURE CPUTIME */
#ifdef TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
#endif
#if HAVE_SYS_RESOURCE_H && HAVE_GETRESOURCE
#include<sys/resource.h>
#else
#if HAVE_SYS_TIMES_H
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#include <sys/times.h>
#endif
#endif
double
__rcputime ()
{
#if HAVE_SYS_RESOURCE_H && HAVE_GETRESOURCE
struct rusage rus;
#else
#if HAVE_SYS_TIMES_H && HAVE_TIMES
struct tms buffer;
#endif
#endif
static double old_cputime;
double cputime;
#if HAVE_GETRESOURCE
(void) getrusage (RUSAGE_SELF, &rus);
cputime = ((double) rus.ru_utime.tv_sec) + ((double) rus.ru_stime.tv_sec) +
(((double) rus.ru_utime.tv_usec) + ((double) rus.ru_stime.tv_usec)) /
1000000.0;
#else
#if HAVE_SYS_TIMES_H && HAVE_TIMES
times (&buffer);
cputime = ((double) buffer.tms_utime + (double) buffer.tms_stime) /
#ifdef CLK_TCK
(double) CLK_TCK;
#else
60.0;
#endif
#else
cputime = (double) clock () /
#if CLOCK_IN_USEC
1000000.0;
#else
#ifdef CLOCKS_PER_SEC
(double) CLOCKS_PER_SEC;
#else
(double) CLK_TCK;
#endif
#endif
#endif
#endif
if (cputime <= old_cputime)
cputime = __raddepsilon (old_cputime);
return (old_cputime = cputime);
}
|