X-shooter Pipeline Reference Manual 3.8.15
xsh_model_cputime.c
Go to the documentation of this file.
1/* $Id: xsh_model_cputime.c,v 1.4 2011-12-02 14:15:28 amodigli Exp $
2 *
3 *Not sure about the copyright stuff here!
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20/*
21 * $Author: amodigli $
22 * $Date: 2011-12-02 14:15:28 $
23 * $Revision: 1.4 $
24 * $Name: not supported by cvs2svn $
25 */
26/* for cpu timing uses getrusage() unless TIMES is defined */
27#ifdef HAVE_CONFIG_H
28#include <config.h>
29#endif
30/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
39/*-----------------------------------------------------------------------------
40 Includes
41 -----------------------------------------------------------------------------*/
42
43#include <cpl.h>
44
45#include "xsh_model_kernel.h"
46
47/*----------------------------------------------------------------------------*/
48
49#ifdef TIMES
50#include <sys/tupes.h>
51#include <sys/times.h>
52#include <sys/param.h>
53
54#ifndef HZ
55#define HZ 60.0
56#endif
57
58#else
59
60#include <sys/time.h>
61#include <sys/resource.h>
62
63#endif
64
65#include "xsh_model_cputime.h"
66
67#ifdef NO_PROTO
68void xsh_report_cpu( fp, str )
69FILE *fp;
70char *str;
71#else
72void xsh_report_cpu(FILE *fp, char *str)
73#endif
74{
75 static int call_no = 0;
76 double utime, s_time;
77
78 get_cpu_time(&utime, &s_time);
79
80 if ( str == NULL )
81 {
82 if ( call_no++ == 0 )
83 fprintf(fp,"Preprocessing");
84 else
85 fprintf(fp,"Total CPU");
86 }
87 else
88 fprintf(fp,"%s", str);
89
90 fprintf(fp," time:\t%2.2fu %2.2fs\t%2.2f (sec)\n", utime, s_time,
91 utime + s_time);
92
93
94}
95
96#ifdef NO_PROTO
97void get_cpu_time(usertime, systime)
98double *usertime;
99double *systime;
100#else
101void get_cpu_time(double *usertime, double *systime)
102#endif
103{
104#ifdef TIMES
105 struct tms time;
106
107 times( &time );
108
109 *usertime = (double)time.tms_utime / (double)HZ;
110 *systime = (double)time.tms_stime / (double)HZ;
111
112#else
113
114 struct rusage usage;
115
116 getrusage( RUSAGE_SELF, &usage );
117
118 *usertime = (double)usage.ru_utime.tv_sec +
119 (double)usage.ru_utime.tv_usec / 1000000.;
120 *systime = (double)usage.ru_stime.tv_sec +
121 (double)usage.ru_stime.tv_usec / 1000000.;
122
123#endif
124
125}
126
void get_cpu_time(double *usertime, double *systime)
void xsh_report_cpu(FILE *fp, char *str)