9.2
general documentation
cs_timer_stats.h
Go to the documentation of this file.
1#ifndef CS_TIMER_STATS_H
2#define CS_TIMER_STATS_H
3
4/*============================================================================
5 * Application timer statistics and graphs
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2026 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 "base/cs_defs.h"
35#include "base/cs_timer.h"
36#include "base/cs_time_plot.h"
37
38/*============================================================================
39 * Public types
40 *============================================================================*/
41
42/*============================================================================
43 * Public function prototypes
44 *============================================================================*/
45
46/*----------------------------------------------------------------------------*/
47/*
48 * \brief Initialize timer statistics handling.
49 *
50 * This creates 2 statistic timer trees, whose roots ids are:
51 * - 0 for computational operations
52 * - 1 for computational stages
53 */
54/*----------------------------------------------------------------------------*/
55
56extern "C" void
58
59/*----------------------------------------------------------------------------*/
60/*
61 * \brief Finalize timer statistics handling.
62 */
63/*----------------------------------------------------------------------------*/
64
65extern "C" void
67
68/*----------------------------------------------------------------------------*/
69/*
70 * \brief Set a start time for time stats.
71 *
72 * This is useful to shift the time id for restarts. This function must
73 * not be called after \ref cs_timer_stats_increment_time_step.
74 *
75 * \param[in] time_id associated starting time id
76 */
77/*----------------------------------------------------------------------------*/
78
79extern "C" void
81
82/*----------------------------------------------------------------------------*/
83/*
84 * \brief Set global timer statistics plot options.
85 *
86 * This function is only effective before the first call to
87 * \ref cs_timer_stats_increment_time_step.
88 *
89 * \param[in] format associated file format
90 * \param[in] frequency plot every n time steps
91 * \param[in] n_buffer_steps number of time steps in output buffer if
92 * file is not to be kept open
93 * \param[in] flush_wtime elapsed time interval between file flushes
94 * (if < 0, no forced flush)
95 */
96/*----------------------------------------------------------------------------*/
97
98extern "C" void
100 int frequency,
101 int n_buffer_steps,
102 double flush_wtime);
103
104/*----------------------------------------------------------------------------*/
105/*
106 * \brief Increment time step for timer statistics.
107 */
108/*----------------------------------------------------------------------------*/
109
110extern "C" void
112
113/*----------------------------------------------------------------------------*/
114/*
115 * \brief Create a timer statistics structure.
116 *
117 * \param[in] parent_name name of parent statistic, or NULL
118 * \param[in] name associated canonical name
119 * \param[in] label associated label, or NULL
120 *
121 * \return id of new timer stats structure
122 */
123/*----------------------------------------------------------------------------*/
124
125extern "C" int
126cs_timer_stats_create(const char *parent_name,
127 const char *name,
128 const char *label);
129
130/*----------------------------------------------------------------------------*/
131/*
132 * \brief Return the id of a defined statistic based on its name.
133 *
134 * If no timer with the given name exists, -1 is returned.
135 *
136 * \param[in] name statistic name
137 *
138 * \return id of the statistic, or -1 if not found
139 */
140/*----------------------------------------------------------------------------*/
141
142extern "C" int
143cs_timer_stats_id_by_name(const char *name);
144
145/*----------------------------------------------------------------------------*/
146/*
147 * \brief Enable or disable plotting for a timer statistic.
148 *
149 * By default plotting is enabled for all statistics, except root statistic 1
150 * (as it measures the same total time as root 0, with a different subtree).
151 *
152 * This function is only effective before the first call to
153 * \ref cs_timer_stats_increment_time_step.
154 *
155 * \param[in] id id of statistic
156 * \param[in] plot 0 to disable, 1 to enable
157 */
158/*----------------------------------------------------------------------------*/
159
160extern "C" void
162 int plot);
163
164/*----------------------------------------------------------------------------*/
165/*
166 * \brief indicate if a timer for a given statistic is currently active.
167 *
168 * \param[in] id id of statistic
169 *
170 * \return 1 if active, 0 otherwise
171 */
172/*----------------------------------------------------------------------------*/
173
174extern "C" int
176
177/*----------------------------------------------------------------------------*/
178/*
179 * \brief Start a timer for a given statistic.
180 *
181 * Parents of the current statistic are also started, if not active.
182 *
183 * If a timer with the same root but different parents is active, we assume
184 * the current operation is a subset of the active timer, so the timer is
185 * not started, so as to avoid having a sum of parts larger than the total.
186 *
187 * \param[in] id id of statistic
188 */
189/*----------------------------------------------------------------------------*/
190
191extern "C" void
193
194/*----------------------------------------------------------------------------*/
195/*
196 * \brief Stop a timer for a given statistic.
197 *
198 * Children of the current statistic are also stopped, if active.
199 *
200 * \param[in] id id of statistic
201 */
202/*----------------------------------------------------------------------------*/
203
204extern "C" void
205cs_timer_stats_stop(int id);
206
207/*----------------------------------------------------------------------------*/
208/*
209 * \brief Start a timer for a given statistic, stopping previous timers
210 * of the same type which are not a parent, and starting inactive
211 * parent timers if necessary.
212 *
213 * \param[in] id id of statistic
214 *
215 * \return id of previously active statistic, or -1 in case of error
216 */
217/*----------------------------------------------------------------------------*/
218
219extern "C" int
221
222/*----------------------------------------------------------------------------*/
223/*
224 * \brief Add a timing range to an inactive timer.
225 *
226 * This does not modify parent timers, so consistency of active and inactive
227 * timers must be ensured by the caller.
228 *
229 * \param[in] id id of statistic
230 * \param[in] t0 oldest timer value
231 * \param[in] t1 most recent timer value
232 */
233/*----------------------------------------------------------------------------*/
234
235extern "C" void
237 const cs_timer_t *t0,
238 const cs_timer_t *t1);
239
240/*----------------------------------------------------------------------------*/
241/*
242 * \brief Define default timer statistics
243 *
244 * This creates 2 statistic timer trees, whose roots ids are:
245 * - 0 for computational operations
246 * - 1 for computational stages
247 */
248/*----------------------------------------------------------------------------*/
249
250extern "C" void
252
253/*----------------------------------------------------------------------------*/
254/*
255 * \brief Switch stage for time statistics.
256 *
257 * This saves current totals then resets them.
258 */
259/*----------------------------------------------------------------------------*/
260
261extern "C" void
263
264/*----------------------------------------------------------------------------*/
265
266#endif /* CS_TIMER_STATS_H */
cs_time_plot_format_t
Definition: cs_time_plot.h:52
int cs_timer_stats_id_by_name(const char *name)
Return the id of a defined statistic based on its name.
Definition: cs_timer_stats.cpp:650
void cs_timer_stats_initialize(void)
Initialize timer statistics handling.
Definition: cs_timer_stats.cpp:380
int cs_timer_stats_is_active(int id)
indicate if a timer for a given statistic is currently active.
Definition: cs_timer_stats.cpp:691
void cs_timer_stats_stop(int id)
Stop a timer for a given statistic.
Definition: cs_timer_stats.cpp:762
void cs_timer_stats_increment_stage(void)
Switch stage for time statistics.
Definition: cs_timer_stats.cpp:925
void cs_timer_stats_increment_time_step(void)
Increment time step for timer statistics.
Definition: cs_timer_stats.cpp:497
void cs_timer_stats_define_defaults(void)
Define default timer statistics.
Definition: cs_timer_stats.cpp:890
void cs_timer_stats_start(int id)
Start a timer for a given statistic.
Definition: cs_timer_stats.cpp:717
void cs_timer_stats_set_plot(int id, int plot)
Enable or disable plotting for a timer statistic.
Definition: cs_timer_stats.cpp:671
int cs_timer_stats_create(const char *parent_name, const char *name, const char *label)
Create a timer statistics structure.
Definition: cs_timer_stats.cpp:548
void cs_timer_stats_set_start_time(int time_id)
Set a start time for time stats.
Definition: cs_timer_stats.cpp:453
void cs_timer_stats_set_plot_options(cs_time_plot_format_t format, int frequency, int n_buffer_steps, double flush_wtime)
Set global timer statistics plot options.
Definition: cs_timer_stats.cpp:478
void cs_timer_stats_add_diff(int id, const cs_timer_t *t0, const cs_timer_t *t1)
Add a timing range to an inactive timer.
Definition: cs_timer_stats.cpp:867
void cs_timer_stats_finalize(void)
Finalize timer statistics handling.
Definition: cs_timer_stats.cpp:408
int cs_timer_stats_switch(int id)
Start a timer for a given statistic, stopping previous timers of the same type which are not a parent...
Definition: cs_timer_stats.cpp:800
real(c_double), pointer, save t0
reference temperature.
Definition: cstphy.f90:68
char * label
Definition: keywords.h:58
Definition: cs_timer.h:42