My Project
programmer's 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-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 #include "cs_timer.h"
36 #include "stdarg.h"
37 
38 /*----------------------------------------------------------------------------*/
39 
41 
42 /*============================================================================
43  * Public types
44  *============================================================================*/
45 
46 /* Code_Saturne log file types */
47 
48 typedef enum {
49 
50  CS_LOG_DEFAULT, /* Default (main) log */
51  CS_LOG_SETUP, /* Calculation setup and options log */
52  CS_LOG_PERFORMANCE, /* Performance log */
53  CS_LOG_N_TYPES /* Number of log file types */
54 
55 } cs_log_t;
56 
57 extern int cs_glob_log_frequency;
58 
59 /*============================================================================
60  * Public macros
61  *============================================================================*/
62 
63 /*============================================================================
64  * Public function prototypes
65  *============================================================================*/
66 
67 /*----------------------------------------------------------------------------
68  * Count printable length of a character string.
69  *
70  * This should also include UTF-8 strings.
71  *
72  * parameters:
73  * str <-- pointer to printable string
74  *
75  * returns:
76  * printable length of character string
77  *----------------------------------------------------------------------------*/
78 
79 size_t
80 cs_log_strlen(const char *s);
81 
82 /*----------------------------------------------------------------------------
83  * Pad a string so that its printable length is the required length.
84  *
85  * This allows pretty-printing with UTF-8 strings, whose actual length may be
86  * larger than their printable length in the presence of multibyte characters.
87  *
88  * If either the printable length of the string is longer than the target
89  * width or the actual length is long than the destination buffer's size,
90  * it is truncated.
91  *
92  * parameters:
93  * dest --> pointer to destination buffer
94  * str <-- pointer to printable string
95  * width <-- desired printed length
96  * destsize <-- destination buffer size
97  *----------------------------------------------------------------------------*/
98 
99 void
100 cs_log_strpad(char *dest,
101  const char *src,
102  size_t width,
103  size_t destsize);
104 
105 /*----------------------------------------------------------------------------
106  * Pad a string on the left so that its printable length is
107  * 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 
123 void
124 cs_log_strpadl(char *dest,
125  const char *src,
126  size_t width,
127  size_t destsize);
128 
129 /*----------------------------------------------------------------------------*/
136 /*----------------------------------------------------------------------------*/
137 
138 void
139 cs_log_binary_pp_int32(int32_t code,
140  char buf[33]);
141 
142 /*----------------------------------------------------------------------------*/
158 /*----------------------------------------------------------------------------*/
159 
160 int
162  const char *format,
163  va_list arg_ptr);
164 
165 /*----------------------------------------------------------------------------
166  * Print log info to a given log type.
167  *
168  * The format and variable arguments are similar to those of the printf()
169  * type functions.
170  *
171  * In parallel, output is only handled by rank 0.
172  *
173  * parameters:
174  * format <-- format string, as printf() and family.
175  * ... <-- variable arguments based on format string.
176  *
177  * returns:
178  * number of characters printed, not counting the trailing '\0' used
179  * to end output strings
180  *----------------------------------------------------------------------------*/
181 
182 #if defined(__GNUC__)
183 
184 int
186  const char *format,
187  ...)
188  __attribute__((format(printf, 2, 3)));
189 
190 #else
191 
192 int
194  const char *format,
195  ...);
196 
197 #endif
198 
199 
200 /*----------------------------------------------------------------------------
201  * Flush for output of cs_log_printf() with modifiable behavior.
202  *
203  * If the argument is set to CS_LOG_N_TYPES, all log files are flushed.
204  *
205  * returns:
206  * 0 upon successful completion 0 is returned. Otherwise, EOF is returned
207  * and errno is set to indicate the error.
208  *----------------------------------------------------------------------------*/
209 
210 int
212 
213 /*----------------------------------------------------------------------------
214  * Print a separator line in a log file
215  *
216  * In parallel, output is only handled by rank 0.
217  *
218  * parameters:
219  * log <-- log file type
220  *----------------------------------------------------------------------------*/
221 
222 void
224 
225 /*----------------------------------------------------------------------------
226  * Output timing data block to a given log.
227  *
228  * If the optional array of call counters is used, only lines
229  * with a number of calls greater than 0 are logged.
230  *
231  * In parallel, output is only handled by rank 0.
232  *
233  * parameters:
234  * log <-- log file type
235  * indent <-- indentation before first column
236  * header_title <-- title for optional header line
237  * calls <-- true if calls column is to be used
238  *----------------------------------------------------------------------------*/
239 
240 void
242  int indent,
243  const char *header_title,
244  bool calls);
245 
246 /*----------------------------------------------------------------------------
247  * Output timing data block to a given log.
248  *
249  * If the optional array of call counters is used, only lines
250  * with a number of calls greater than 0 are logged.
251  *
252  * In parallel, output is only handled by rank 0.
253  *
254  * parameters:
255  * log <-- log file type
256  * indent <-- indentation before first column
257  * n_lines <-- number of lines in array, excluding header
258  * line_titles <-- array of titles for data lines
259  * calls <-- optional array of call counters, or NULL
260  * time_count <-- array of time counters
261  *----------------------------------------------------------------------------*/
262 
263 void
265  int indent,
266  int n_lines,
267  const char *line_titles[],
268  const unsigned calls[],
269  const cs_timer_counter_t time_count[]);
270 
271 /*----------------------------------------------------------------------------*/
272 
274 
275 #endif /* __CS_LOG_H__ */
CS_LOG_N_TYPES
Definition: cs_log.h:53
cs_defs.h
cs_log_strlen
size_t cs_log_strlen(const char *s)
Count printable length of a character string.
Definition: cs_log.c:257
cs_log_timer_array
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.c:635
cs_timer_counter_t
Definition: cs_timer.h:57
END_C_DECLS
#define END_C_DECLS
Definition: cs_defs.h:468
CS_LOG_DEFAULT
Definition: cs_log.h:50
BEGIN_C_DECLS
#define BEGIN_C_DECLS
Definition: cs_defs.h:467
CS_LOG_PERFORMANCE
Definition: cs_log.h:52
cs_log_printf_flush
int cs_log_printf_flush(cs_log_t log)
Flush output of a log file.
Definition: cs_log.c:517
cs_log_separator
void cs_log_separator(cs_log_t log)
Print a separator line in a log file.
Definition: cs_log.c:553
cs_log_vprintf
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.c:415
cs_log_binary_pp_int32
void cs_log_binary_pp_int32(int32_t code, char buf[33])
Pretty-print int-32 based bit field to string.
Definition: cs_log.c:374
cs_log_strpad
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.c:328
cs_glob_log_frequency
int cs_glob_log_frequency
cs_log_t
cs_log_t
Definition: cs_log.h:48
cs_log_strpadl
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.c:356
CS_LOG_SETUP
Definition: cs_log.h:51
cs_log_printf
int cs_log_printf(cs_log_t log, const char *format,...)
Print log info to a given log type.
Definition: cs_log.c:463
cs_log_timer_array_header
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.c:579
cs_timer.h