programmer's documentation
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
src
base
cs_timer.h
Go to the documentation of this file.
1
#ifndef __CS_TIMER_H__
2
#define __CS_TIMER_H__
3
4
/*============================================================================
5
* Program timing information
6
*============================================================================*/
7
8
/*
9
This file is part of Code_Saturne, a general-purpose CFD tool.
10
11
Copyright (C) 1998-2013 EDF S.A.
12
13
This program is free software; you can redistribute it and/or modify it under
14
the terms of the GNU General Public License as published by the Free Software
15
Foundation; either version 2 of the License, or (at your option) any later
16
version.
17
18
This program is distributed in the hope that it will be useful, but WITHOUT
19
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21
details.
22
23
You should have received a copy of the GNU General Public License along with
24
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25
Street, Fifth Floor, Boston, MA 02110-1301, USA.
26
*/
27
28
/*----------------------------------------------------------------------------*/
29
30
/*----------------------------------------------------------------------------
31
* Local headers
32
*----------------------------------------------------------------------------*/
33
34
#include "
cs_defs.h
"
35
36
/*----------------------------------------------------------------------------*/
37
38
BEGIN_C_DECLS
39
40
/*============================================================================
41
* Public types
42
*============================================================================*/
43
44
/* Information structure for precise timings */
45
46
typedef
struct
{
47
48
long
long
wall_sec
;
/* wall-time seconds */
49
long
long
wall_nsec
;
/* wall-time nanoseconds */
50
long
long
cpu_sec
;
/* CPU time seconds */
51
long
long
cpu_nsec
;
/* CPU time nanoseconds */
52
53
}
cs_timer_t
;
54
55
/* Information structure for timing counters */
56
57
typedef
struct
{
58
59
long
long
wall_nsec
;
/* wall-time nanoseconds */
60
long
long
cpu_nsec
;
/* CPU time nanoseconds */
61
62
}
cs_timer_counter_t
;
63
64
/*============================================================================
65
* Public macros
66
*============================================================================*/
67
68
/*----------------------------------------------------------------------------
69
* Initialize timer counter.
70
*
71
* parameters:
72
* _t --> resulting counter.
73
*----------------------------------------------------------------------------*/
74
75
#define CS_TIMER_COUNTER_INIT(_t) \
76
(_t.wall_nsec = 0, \
77
_t.cpu_nsec = 0)
78
79
/*----------------------------------------------------------------------------
80
* Add timer counter.
81
*
82
* The result may be identical to one of the 2 counters to add.
83
*
84
* parameters:
85
* _res --> resulting counter.
86
* _c0 <-- counter to add.
87
* _c1 <-- counter to add.
88
*----------------------------------------------------------------------------*/
89
90
#define CS_TIMER_COUNTER_ADD(_res, _c0, _c1) \
91
(_res.wall_nsec = _c0.wall_nsec + _c1.wall_nsec, \
92
_res.cpu_nsec = _c0.cpu_nsec + _c1.cpu_nsec)
93
94
/*============================================================================
95
* Public function prototypes
96
*============================================================================*/
97
98
/*----------------------------------------------------------------------------
99
* Return Wall clock time
100
*
101
* returns:
102
* elapsed time from first call of a function of the cs_timer_...()
103
* series, or -1 if unable to compute.
104
*----------------------------------------------------------------------------*/
105
106
double
107
cs_timer_wtime
(
void
);
108
109
/*----------------------------------------------------------------------------
110
* Return CPU time.
111
*
112
* Note that in the rare case that only the minimal C library clock()
113
* method is available (see cs_timer_cpu_time_method()), at least one of
114
* the cs_timer_...() functions (possibly this one) must be called
115
* upon program start for this function to be used. In addition,
116
* in this case, time may "loop" back to 0 every multiple of
117
* 2^size_t / CLOCKS_PER_SEC seconds.
118
*
119
* returns:
120
* current CPU time usage, or -1 if unable to compute.
121
*----------------------------------------------------------------------------*/
122
123
double
124
cs_timer_cpu_time
(
void
);
125
126
/*----------------------------------------------------------------------------
127
* Return separate user and system CPU times.
128
*
129
* parameters:
130
* user_time --> current user CPU usage.
131
* system_time --> current system CPU usage.
132
*----------------------------------------------------------------------------*/
133
134
void
135
cs_timer_cpu_times
(
double
*user_time,
136
double
*system_time);
137
138
/*----------------------------------------------------------------------------
139
* Return a timer's value
140
*
141
* returns:
142
* timer structure.
143
*----------------------------------------------------------------------------*/
144
145
cs_timer_t
146
cs_timer_time
(
void
);
147
148
/*----------------------------------------------------------------------------
149
* Compute the difference between 2 timers.
150
*
151
* parameters:
152
* t0 <-- oldest timer value
153
* t1 <-- most recent timer value
154
*
155
* returns:
156
* last - first timer value.
157
*----------------------------------------------------------------------------*/
158
159
cs_timer_counter_t
160
cs_timer_diff
(
const
cs_timer_t
*t0,
161
const
cs_timer_t
*t1);
162
163
/*----------------------------------------------------------------------------
164
* Add the the difference between 2 timers to a counter.
165
*
166
* parameters:
167
* tc <-> pointer to timer counter
168
* t0 <-- oldest timer value
169
* t1 <-- most recent timer value
170
*
171
* returns:
172
* last - first timer value.
173
*----------------------------------------------------------------------------*/
174
175
void
176
cs_timer_counter_add_diff
(
cs_timer_counter_t
*tc,
177
const
cs_timer_t
*t0,
178
const
cs_timer_t
*t1);
179
180
/*----------------------------------------------------------------------------
181
* Return method used to return wall clock time.
182
*
183
* Note that in the rare case that only the minimal C library clock()
184
* method is available, this function will return -1 values.
185
*
186
* returns:
187
* short description of method used to return wall clock time.
188
*----------------------------------------------------------------------------*/
189
190
const
char
*
191
cs_timer_wtime_method
(
void
);
192
193
/*----------------------------------------------------------------------------
194
* Return method used to return CPU time.
195
*
196
* returns:
197
* short description of method used to return CPU time.
198
*----------------------------------------------------------------------------*/
199
200
const
char
*
201
cs_timer_cpu_time_method
(
void
);
202
203
/*----------------------------------------------------------------------------*/
204
205
END_C_DECLS
206
207
#endif
/* __CS_TIMER_H__ */
Generated on Thu Feb 27 2014 19:21:34 by
1.8.3.1