9.2
general documentation
cs_log.h
Go to the documentation of this file.
1#ifndef CS_LOG_H
2#define CS_LOG_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-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 "stdarg.h"
37
38/*============================================================================
39 * Public types
40 *============================================================================*/
41
42/* code_saturne log file types */
43
44typedef enum {
45
46 CS_LOG_DEFAULT, /* Default (main) log */
47 CS_LOG_SETUP, /* Calculation setup and options log */
48 CS_LOG_PERFORMANCE, /* Performance log */
49 CS_LOG_WARNINGS, /* Warnings log */
50 CS_LOG_N_TYPES /* Number of log file types */
51
53
54/*============================================================================
55 * Public macros
56 *============================================================================*/
57
58/*============================================================================
59 * Public function prototypes
60 *============================================================================*/
61
62/*----------------------------------------------------------------------------*/
72/*----------------------------------------------------------------------------*/
73
74void
75cs_log_default_activate(bool activate);
76
77/*----------------------------------------------------------------------------*/
86/*----------------------------------------------------------------------------*/
87
88bool
90
91/*----------------------------------------------------------------------------
92 * Count printable length of a character string.
93 *
94 * This should also include UTF-8 strings.
95 *
96 * parameters:
97 * str <-- pointer to printable string
98 *
99 * returns:
100 * printable length of character string
101 *----------------------------------------------------------------------------*/
102
103size_t
104cs_log_strlen(const char *s);
105
106/*----------------------------------------------------------------------------
107 * Pad a string so that its printable length is the required length.
108 *
109 * This allows pretty-printing with UTF-8 strings, whose actual length may be
110 * larger than their printable length in the presence of multibyte characters.
111 *
112 * If either the printable length of the string is longer than the target
113 * width or the actual length is long than the destination buffer's size,
114 * it is truncated.
115 *
116 * parameters:
117 * dest --> pointer to destination buffer
118 * str <-- pointer to printable string
119 * width <-- desired printed length
120 * destsize <-- destination buffer size
121 *----------------------------------------------------------------------------*/
122
123void
124cs_log_strpad(char *dest,
125 const char *src,
126 size_t width,
127 size_t destsize);
128
129/*----------------------------------------------------------------------------
130 * Pad a string on the left so that its printable length is
131 * the required length.
132 *
133 * This allows pretty-printing with UTF-8 strings, whose actual length may be
134 * larger than their printable length in the presence of multibyte characters.
135 *
136 * If either the printable length of the string is longer than the target
137 * width or the actual length is long than the destination buffer's size,
138 * it is truncated.
139 *
140 * parameters:
141 * dest --> pointer to destination buffer
142 * str <-- pointer to printable string
143 * width <-- desired printed length
144 * destsize <-- destination buffer size
145 *----------------------------------------------------------------------------*/
146
147void
148cs_log_strpadl(char *dest,
149 const char *src,
150 size_t width,
151 size_t destsize);
152
153/*----------------------------------------------------------------------------*/
160/*----------------------------------------------------------------------------*/
161
162void
163cs_log_binary_pp_int32(int32_t code,
164 char buf[33]);
165
166/*----------------------------------------------------------------------------*/
182/*----------------------------------------------------------------------------*/
183
184int
186 const char *format,
187 va_list arg_ptr);
188
189/*----------------------------------------------------------------------------
190 * Print log info to a given log type.
191 *
192 * The format and variable arguments are similar to those of the printf()
193 * type functions.
194 *
195 * In parallel, output is only handled by rank 0.
196 *
197 * parameters:
198 * format <-- format string, as printf() and family.
199 * ... <-- variable arguments based on format string.
200 *
201 * returns:
202 * number of characters printed, not counting the trailing '\0' used
203 * to end output strings
204 *----------------------------------------------------------------------------*/
205
206#if defined(__GNUC__)
207
208int
210 const char *format,
211 ...)
212 __attribute__((format(printf, 2, 3)));
213
214#else
215
216int
218 const char *format,
219 ...);
220
221#endif
222
223
224/*----------------------------------------------------------------------------
225 * Flush for output of cs_log_printf() with modifiable behavior.
226 *
227 * If the argument is set to CS_LOG_N_TYPES, all log files are flushed.
228 *
229 * returns:
230 * 0 upon successful completion 0 is returned. Otherwise, EOF is returned
231 * and errno is set to indicate the error.
232 *----------------------------------------------------------------------------*/
233
234int
236
237/*----------------------------------------------------------------------------
238 * Print a separator line in a log file
239 *
240 * In parallel, output is only handled by rank 0.
241 *
242 * parameters:
243 * log <-- log file type
244 *----------------------------------------------------------------------------*/
245
246void
248
249/*----------------------------------------------------------------------------
250 * Output timing data block to a given log.
251 *
252 * If the optional array of call counters is used, only lines
253 * with a number of calls greater than 0 are logged.
254 *
255 * In parallel, output is only handled by rank 0.
256 *
257 * parameters:
258 * log <-- log file type
259 * indent <-- indentation before first column
260 * header_title <-- title for optional header line
261 * calls <-- true if calls column is to be used
262 *----------------------------------------------------------------------------*/
263
264void
266 int indent,
267 const char *header_title,
268 bool calls);
269
270/*----------------------------------------------------------------------------
271 * Output timing data block to a given log.
272 *
273 * If the optional array of call counters is used, only lines
274 * with a number of calls greater than 0 are logged.
275 *
276 * In parallel, output is only handled by rank 0.
277 *
278 * parameters:
279 * log <-- log file type
280 * indent <-- indentation before first column
281 * n_lines <-- number of lines in array, excluding header
282 * line_titles <-- array of titles for data lines
283 * calls <-- optional array of call counters, or NULL
284 * time_count <-- array of time counters
285 *----------------------------------------------------------------------------*/
286
287void
289 int indent,
290 int n_lines,
291 const char *line_titles[],
292 const unsigned calls[],
293 const cs_timer_counter_t time_count[]);
294
295/*----------------------------------------------------------------------------*/
311/*----------------------------------------------------------------------------*/
312
313int
314cs_log_warning(const char *format,
315 ...);
316
317/*----------------------------------------------------------------------------*/
318
319#endif /* CS_LOG_H */
int cs_log_printf_flush(cs_log_t log)
Flush output of a log file.
Definition: cs_log.cpp:523
void cs_log_default_activate(bool activate)
Update "active" or "inactive" flag of default log.
Definition: cs_log.cpp:229
bool cs_log_default_is_active(void)
Update "active" or "inactive" flag of default log.
Definition: cs_log.cpp:246
cs_log_t
Definition: cs_log.h:44
@ CS_LOG_DEFAULT
Definition: cs_log.h:46
@ CS_LOG_WARNINGS
Definition: cs_log.h:49
@ CS_LOG_PERFORMANCE
Definition: cs_log.h:48
@ CS_LOG_N_TYPES
Definition: cs_log.h:50
@ CS_LOG_SETUP
Definition: cs_log.h:47
int cs_log_printf(cs_log_t log, const char *format,...)
Print log info to a given log type.
Definition: cs_log.cpp:470
int cs_log_warning(const char *format,...)
Print log info to a given log type.
Definition: cs_log.cpp:697
void cs_log_strpadl(char *dest, const char *src, size_t width, size_t destsize)
Pad a string on the left so that its printable length is the required length.
Definition: cs_log.cpp:363
void cs_log_separator(cs_log_t log)
Print a separator line in a log file.
Definition: cs_log.cpp:559
size_t cs_log_strlen(const char *s)
Count printable length of a character string.
Definition: cs_log.cpp:264
void cs_log_strpad(char *dest, const char *src, size_t width, size_t destsize)
Pad a string so that its printable length is the required length.
Definition: cs_log.cpp:335
void cs_log_binary_pp_int32(int32_t code, char buf[33])
Pretty-print int-32 based bit field to string.
Definition: cs_log.cpp:381
int cs_log_vprintf(cs_log_t log, const char *format, va_list arg_ptr)
Print log info to a given log type.
Definition: cs_log.cpp:422
void cs_log_timer_array_header(cs_log_t log, int indent, const char *header_title, bool calls)
Output timing data array header to a given log.
Definition: cs_log.cpp:585
void cs_log_timer_array(cs_log_t log, int indent, int n_lines, const char *line_titles[], const unsigned calls[], const cs_timer_counter_t time_count[])
Output timing data block to a given log.
Definition: cs_log.cpp:641
Definition: cs_timer.h:51