My Project
Toggle main menu visibility
Loading...
Searching...
No Matches
kernel
oswrapper
timer.cc
Go to the documentation of this file.
1
/****************************************
2
* Computer Algebra System SINGULAR *
3
****************************************/
4
5
/*
6
* ABSTRACT - get the computing time
7
*/
8
9
10
11
12
#include "
kernel/mod2.h
"
13
14
#include <sys/resource.h>
15
#include <unistd.h>
16
17
VAR
int
timerv
= 0;
18
STATIC_VAR
double
timer_resolution
=
TIMER_RESOLUTION
;
19
20
STATIC_VAR
double
mintime
= 0.5;
21
22
void
SetTimerResolution
(
int
res
)
23
{
24
timer_resolution
= (double)
res
;
25
}
26
27
void
SetMinDisplayTime
(
double
mtime)
28
{
29
mintime
= mtime;
30
}
31
32
#include <stdio.h>
33
34
#ifdef TIME_WITH_SYS_TIME
35
# include <time.h>
36
# ifdef HAVE_SYS_TIME_H
37
# include <sys/time.h>
38
# endif
39
#else
40
# ifdef HAVE_SYS_TIME_H
41
# include <sys/time.h>
42
# else
43
# include <time.h>
44
# endif
45
#endif
46
47
#ifdef HAVE_SYS_TIMES_H
48
#include <sys/times.h>
49
#endif
50
51
52
#include "
reporter/reporter.h
"
53
#include "
kernel/oswrapper/timer.h
"
54
55
/*3
56
* the start time of the timer
57
*/
58
STATIC_VAR
int64
siStartTime
;
59
60
/*3
61
* temp structure to get the time
62
*/
63
STATIC_VAR
struct
rusage
t_rec
;
64
/*0 implementation*/
65
66
int
startTimer
()
67
{
68
getrusage(RUSAGE_SELF,&
t_rec
);
69
siStartTime
= (
int64
)
t_rec
.ru_utime.tv_sec*1000000+(
int64
)
t_rec
.ru_utime.tv_usec
70
+(
int64
)
t_rec
.ru_stime.tv_sec*1000000+(
int64
)
t_rec
.ru_stime.tv_usec;
71
getrusage(RUSAGE_CHILDREN,&
t_rec
);
72
siStartTime
+= (
int64
)
t_rec
.ru_utime.tv_sec*1000000+(
int64
)
t_rec
.ru_utime.tv_usec
73
+(
int64
)
t_rec
.ru_stime.tv_sec*1000000+(
int64
)
t_rec
.ru_stime.tv_usec;
74
return
(
int
)time(
NULL
);
75
}
76
77
/*2
78
* returns the time since a fixed point in seconds
79
*/
80
long
getTimer
()
81
{
82
int64
curr;
83
getrusage(RUSAGE_SELF,&
t_rec
);
84
curr = (
int64
)
t_rec
.ru_utime.tv_sec*1000000+(
int64
)
t_rec
.ru_utime.tv_usec
85
+(
int64
)
t_rec
.ru_stime.tv_sec*1000000+(
int64
)
t_rec
.ru_stime.tv_usec;
86
getrusage(RUSAGE_CHILDREN,&
t_rec
);
87
curr += (
int64
)
t_rec
.ru_utime.tv_sec*1000000+(
int64
)
t_rec
.ru_utime.tv_usec
88
+(
int64
)
t_rec
.ru_stime.tv_sec*1000000+(
int64
)
t_rec
.ru_stime.tv_usec;
89
double
f
= ((double)curr) *
timer_resolution
/ (
double
)1000000;
90
return
(
long
)(
f
+0.5);
91
}
92
93
/*2
94
* stops timer, writes string s and the time since last call of startTimer
95
* if this time is > mintime sec
96
*/
97
#ifdef EXTEND_TIMER_D
98
EXTERN_VAR
int
iiOp
;
99
#endif
100
101
void
writeTime
(
const
char
*
v
)
102
{
103
int64
curr;
104
getrusage(RUSAGE_SELF,&
t_rec
);
105
curr = (
int64
)
t_rec
.ru_utime.tv_sec*1000000+(
int64
)
t_rec
.ru_utime.tv_usec
106
+(
int64
)
t_rec
.ru_stime.tv_sec*1000000+(
int64
)
t_rec
.ru_stime.tv_usec;
107
getrusage(RUSAGE_CHILDREN,&
t_rec
);
108
curr += (
int64
)
t_rec
.ru_utime.tv_sec*1000000+(
int64
)
t_rec
.ru_utime.tv_usec
109
+(
int64
)
t_rec
.ru_stime.tv_sec*1000000+(
int64
)
t_rec
.ru_stime.tv_usec;
110
curr -=
siStartTime
;
111
double
f
= ((double)curr) *
timer_resolution
/ (
double
)1000000;
112
if
(
f
/
timer_resolution
>
mintime
)
113
{
114
#ifdef EXTEND_TIMER_D
115
Print
(
"//%s %.2f/%d sec (%d) >>%s<<\n"
,
v
,
f
,(
int
)
timer_resolution
,
iiOp
,
my_yylinebuf
);
116
#else
117
if
(
timer_resolution
==(
double
)1.0)
118
Print
(
"//%s %.2f sec\n"
,
v
,
f
);
119
else
120
Print
(
"//%s %.2f/%d sec\n"
,
v
,
f
,(
int
)
timer_resolution
);
121
#endif
122
}
123
}
124
125
/*0 Real timer implementation*/
126
VAR
int
rtimerv
= 0;
127
STATIC_VAR
struct
timeval
startRl
;
128
STATIC_VAR
struct
timeval
siStartRTime
;
129
STATIC_VAR
struct
timezone
tzp
;
130
131
void
startRTimer
()
132
{
133
gettimeofday(&
siStartRTime
, &
tzp
);
134
}
135
136
void
initRTimer
()
137
{
138
#ifdef HAVE_GETTIMEOFDAY
139
gettimeofday(&
startRl
, &
tzp
);
140
gettimeofday(&
siStartRTime
, &
tzp
);
141
#else
142
memset(&
startRl
,0,
sizeof
(
startRl
));
143
memset(&
siStartRTime
,0,
sizeof
(
siStartRTime
));
144
#endif
145
}
146
147
/*2
148
* returns the time since a fixed point in resolutions
149
*/
150
int
getRTimer
()
151
{
152
struct
timeval now;
153
154
gettimeofday(&now, &
tzp
);
155
156
if
(
startRl
.tv_usec > now.tv_usec)
157
{
158
now.tv_usec += 1000000;
159
now.tv_sec --;
160
}
161
162
double
f
=((double) (now.tv_sec -
startRl
.tv_sec))*
timer_resolution
+
163
((
double
) (now.tv_usec -
startRl
.tv_usec))*
timer_resolution
/
164
(double) 1000000;
165
166
return
(
int
)(
f
+0.5);
167
}
168
169
/*2
170
* stops timer, writes string s and the time since last call of startTimer
171
* if this time is > mintime
172
*/
173
void
writeRTime
(
const
char
*
v
)
174
{
175
struct
timeval now;
176
177
gettimeofday(&now, &
tzp
);
178
179
if
(
siStartRTime
.tv_usec > now.tv_usec)
180
{
181
now.tv_usec += 1000000;
182
now.tv_sec --;
183
}
184
185
double
f
=((double) (now.tv_sec -
siStartRTime
.tv_sec)) +
186
((
double
) (now.tv_usec -
siStartRTime
.tv_usec)) /
187
(double) 1000000;
188
189
if
(
f
>
mintime
)
190
Print
(
"//%s %.2f sec \n"
,
v
,
f
);
191
}
int64
long int64
Definition
auxiliary.h:68
f
FILE * f
Definition
checklibs.c:9
Print
#define Print
Definition
emacs.cc:80
res
CanonicalForm res
Definition
facAbsFact.cc:60
v
const Variable & v
< [in] a sqrfree bivariate poly
Definition
facBivar.h:39
my_yylinebuf
VAR char my_yylinebuf[80]
Definition
febase.cc:44
STATIC_VAR
#define STATIC_VAR
Definition
globaldefs.h:7
EXTERN_VAR
#define EXTERN_VAR
Definition
globaldefs.h:6
VAR
#define VAR
Definition
globaldefs.h:5
iiOp
VAR int iiOp
Definition
iparith.cc:219
mod2.h
TIMER_RESOLUTION
#define TIMER_RESOLUTION
Definition
mod2.h:35
NULL
#define NULL
Definition
omList.c:12
reporter.h
writeRTime
void writeRTime(const char *v)
Definition
timer.cc:173
SetMinDisplayTime
void SetMinDisplayTime(double mtime)
Definition
timer.cc:27
startTimer
int startTimer()
Definition
timer.cc:66
siStartRTime
STATIC_VAR struct timeval siStartRTime
Definition
timer.cc:128
mintime
STATIC_VAR double mintime
Definition
timer.cc:20
initRTimer
void initRTimer()
Definition
timer.cc:136
timer_resolution
STATIC_VAR double timer_resolution
Definition
timer.cc:18
startRl
STATIC_VAR struct timeval startRl
Definition
timer.cc:127
getRTimer
int getRTimer()
Definition
timer.cc:150
getTimer
long getTimer()
Definition
timer.cc:80
t_rec
STATIC_VAR struct rusage t_rec
Definition
timer.cc:63
siStartTime
STATIC_VAR int64 siStartTime
Definition
timer.cc:58
rtimerv
VAR int rtimerv
Definition
timer.cc:126
tzp
STATIC_VAR struct timezone tzp
Definition
timer.cc:129
writeTime
void writeTime(const char *v)
Definition
timer.cc:101
timerv
VAR int timerv
Definition
timer.cc:17
SetTimerResolution
void SetTimerResolution(int res)
Definition
timer.cc:22
startRTimer
void startRTimer()
Definition
timer.cc:131
timer.h
Generated on
for My Project by
doxygen 1.17.0
for
Singular