File: resource.c

package info (click to toggle)
inn2 2.4.5-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 8,912 kB
  • ctags: 7,860
  • sloc: ansic: 85,104; perl: 11,427; sh: 9,863; makefile: 2,498; yacc: 1,563; python: 298; lex: 252; tcl: 7
file content (52 lines) | stat: -rw-r--r-- 1,050 bytes parent folder | download
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
/*  $Id: resource.c 6135 2003-01-19 01:15:40Z rra $
**
*/

#include "config.h"
#include "clibrary.h"
#include "libinn.h"

#ifdef HAVE_GETRUSAGE

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

#define TIMEVALasDOUBLE(t)	\
    ((double)(t).tv_sec + ((double)(t).tv_usec) / 1000000.0)

int getrusage(int who, struct rusage *rusage);

int GetResourceUsage(double *usertime, double *systime)
{
    struct rusage	R;

    if (getrusage(RUSAGE_SELF, &R) < 0)
	return -1;
    *usertime = TIMEVALasDOUBLE(R.ru_utime);
    *systime = TIMEVALasDOUBLE(R.ru_stime);
    return 0;
}

#else /* HAVE_GETRUSAGE */

#include <sys/param.h>
#include <sys/times.h>

#if	!defined(HZ)
#define HZ	60
#endif	/* !defined(HZ) */

#define CPUTIMEasDOUBLE(t1, t2)		((double)(t1 + t2) / (double)HZ)

int GetResourceUsage(double *usertime, double *systime)
{
    struct tms	T;

    if (times(&T) == -1)
	return -1;
    *usertime = CPUTIMEasDOUBLE(T.tms_utime, T.tms_cutime);
    *systime = CPUTIMEasDOUBLE(T.tms_stime, T.tms_cstime);
    return 0;
}

#endif /* !HAVE_GETRUSAGE */