My Project
programmer's documentation
Loading...
Searching...
No Matches
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-2019 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
39
40/*============================================================================
41 * Public types
42 *============================================================================*/
43
44/* Information structure for precise timings */
45
46typedef 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
54
55/* Information structure for timing counters */
56
57typedef struct {
58
59 long long wall_nsec; /* wall-time nanoseconds */
60 long long cpu_nsec; /* CPU time nanoseconds */
61
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
106double
107cs_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
123double
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
134void
135cs_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
146cs_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
160cs_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
175static inline void
177 const cs_timer_t *t0,
178 const cs_timer_t *t1)
179{
180 tc->wall_nsec += (t1->wall_sec - t0->wall_sec) * (long long)1000000000
181 + t1->wall_nsec - t0->wall_nsec;
182 tc->cpu_nsec += (t1->cpu_sec - t0->cpu_sec) * (long long)1000000000
183 + t1->cpu_nsec - t0->cpu_nsec;
184}
185
186/*----------------------------------------------------------------------------
187 * Return method used to return wall clock time.
188 *
189 * Note that in the rare case that only the minimal C library clock()
190 * method is available, this function will return -1 values.
191 *
192 * returns:
193 * short description of method used to return wall clock time.
194 *----------------------------------------------------------------------------*/
195
196const char *
198
199/*----------------------------------------------------------------------------
200 * Return method used to return CPU time.
201 *
202 * returns:
203 * short description of method used to return CPU time.
204 *----------------------------------------------------------------------------*/
205
206const char *
208
209/*----------------------------------------------------------------------------*/
210
212
213#endif /* __CS_TIMER_H__ */
#define BEGIN_C_DECLS
Definition cs_defs.h:467
#define END_C_DECLS
Definition cs_defs.h:468
double cs_timer_wtime(void)
Return Wall clock time.
Definition cs_timer.c:489
static void cs_timer_counter_add_diff(cs_timer_counter_t *tc, const cs_timer_t *t0, const cs_timer_t *t1)
Definition cs_timer.h:176
const char * cs_timer_wtime_method(void)
Return method used to return wall clock time.
Definition cs_timer.c:658
const char * cs_timer_cpu_time_method(void)
Return method used to return CPU time.
Definition cs_timer.c:686
void cs_timer_cpu_times(double *user_time, double *system_time)
Return separate user and system CPU times.
Definition cs_timer.c:558
cs_timer_t cs_timer_time(void)
Return a timer's value.
Definition cs_timer.c:607
double cs_timer_cpu_time(void)
Return CPU time.
Definition cs_timer.c:525
cs_timer_counter_t cs_timer_diff(const cs_timer_t *t0, const cs_timer_t *t1)
Compute the difference between 2 timers.
Definition cs_timer.c:636
Definition cs_timer.h:57
long long wall_nsec
Definition cs_timer.h:59
long long cpu_nsec
Definition cs_timer.h:60
Definition cs_timer.h:46
long long cpu_sec
Definition cs_timer.h:50
long long wall_nsec
Definition cs_timer.h:49
long long wall_sec
Definition cs_timer.h:48
long long cpu_nsec
Definition cs_timer.h:51