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-2015 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 
37 /*----------------------------------------------------------------------------*/
38 
40 
41 /*============================================================================
42  * Public types
43  *============================================================================*/
44 
45 /* Code_Saturne log file types */
46 
47 typedef enum {
48 
49  CS_LOG_DEFAULT, /* Default (main) log */
50  CS_LOG_SETUP, /* Calculation setup and options log */
51  CS_LOG_PERFORMANCE, /* Performance log */
52  CS_LOG_N_TYPES /* Number of log file types */
53 
54 } cs_log_t;
55 
56 /*============================================================================
57  * Public macros
58  *============================================================================*/
59 
60 /*============================================================================
61  * Public function prototypes
62  *============================================================================*/
63 
64 /*----------------------------------------------------------------------------
65  * Count printable length of a character string.
66  *
67  * This should also include UTF-8 strings.
68  *
69  * parameters:
70  * str <-- pointer to printable string
71  *
72  * returns:
73  * printable length of character string
74  *----------------------------------------------------------------------------*/
75 
76 size_t
77 cs_log_strlen(const char *s);
78 
79 /*----------------------------------------------------------------------------
80  * Pad a string so that its printable length is the required length.
81  *
82  * This allows pretty-printing with UTF-8 strings, whose actual length may be
83  * larger than their printable length in the presence of multibyte characters.
84  *
85  * If either the printable length of the string is longer than the target
86  * width or the actual length is long than the destination buffer's size,
87  * it is truncated.
88  *
89  * parameters:
90  * dest --> pointer to destination buffer
91  * str <-- pointer to printable string
92  * width <-- desired printed length
93  * destsize <-- destination buffer size
94  *----------------------------------------------------------------------------*/
95 
96 void
97 cs_log_strpad(char *dest,
98  const char *src,
99  size_t width,
100  size_t destsize);
101 
102 /*----------------------------------------------------------------------------
103  * Pad a string on the left so that its printable length is
104  * the required length.
105  *
106  * This allows pretty-printing with UTF-8 strings, whose actual length may be
107  * larger than their printable length in the presence of multibyte characters.
108  *
109  * If either the printable length of the string is longer than the target
110  * width or the actual length is long than the destination buffer's size,
111  * it is truncated.
112  *
113  * parameters:
114  * dest --> pointer to destination buffer
115  * str <-- pointer to printable string
116  * width <-- desired printed length
117  * destsize <-- destination buffer size
118  *----------------------------------------------------------------------------*/
119 
120 void
121 cs_log_strpadl(char *dest,
122  const char *src,
123  size_t width,
124  size_t destsize);
125 
126 /*----------------------------------------------------------------------------
127  * Print log info to a given log type.
128  *
129  * The format and variable arguments are similar to those of the printf()
130  * type functions.
131  *
132  * In parallel, output is only handled by rank 0.
133  *
134  * parameters:
135  * format <-- format string, as printf() and family.
136  * ... <-- variable arguments based on format string.
137  *
138  * returns:
139  * number of characters printed, not counting the trailing '\0' used
140  * to end output strings
141  *----------------------------------------------------------------------------*/
142 
143 #if defined(__GNUC__)
144 
145 int
147  const char *format,
148  ...)
149  __attribute__((format(printf, 2, 3)));
150 
151 #else
152 
153 int
155  const char *format,
156  ...);
157 
158 #endif
159 
160 
161 /*----------------------------------------------------------------------------
162  * Flush for output of cs_log_printf() with modifiable behavior.
163  *
164  * If the argument is set to CS_LOG_N_TYPES, all log files are flushed.
165  *
166  * returns:
167  * 0 upon successful completion 0 is returned. Otherwise, EOF is returned
168  * and errno is set to indicate the error.
169  *----------------------------------------------------------------------------*/
170 
171 int
173 
174 /*----------------------------------------------------------------------------
175  * Print a separator line in a log file
176  *
177  * In parallel, output is only handled by rank 0.
178  *
179  * parameters:
180  * log <-- log file type
181  *----------------------------------------------------------------------------*/
182 
183 void
185 
186 /*----------------------------------------------------------------------------
187  * Output timing data block to a given log.
188  *
189  * If the optional array of call counters is used, only lines
190  * with a number of calls greater than 0 are logged.
191  *
192  * In parallel, output is only handled by rank 0.
193  *
194  * parameters:
195  * log <-- log file type
196  * indent <-- indentation before first column
197  * header_title <-- title for optional header line
198  * calls <-- true if calls column is to be used
199  *----------------------------------------------------------------------------*/
200 
201 void
203  int indent,
204  const char *header_title,
205  bool calls);
206 
207 /*----------------------------------------------------------------------------
208  * Output timing data block to a given log.
209  *
210  * If the optional array of call counters is used, only lines
211  * with a number of calls greater than 0 are logged.
212  *
213  * In parallel, output is only handled by rank 0.
214  *
215  * parameters:
216  * log <-- log file type
217  * indent <-- indentation before first column
218  * n_lines <-- number of lines in array, excluding header
219  * line_titles <-- array of titles for data lines
220  * calls <-- optional array of call counters, or NULL
221  * time_count <-- array of time counters
222  *----------------------------------------------------------------------------*/
223 
224 void
226  int indent,
227  int n_lines,
228  const char *line_titles[],
229  const unsigned calls[],
230  const cs_timer_counter_t time_count[]);
231 
232 /*----------------------------------------------------------------------------*/
233 
235 
236 #endif /* __CS_LOG_H__ */
Definition: cs_log.h:50
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:526
Definition: cs_log.h:52
#define BEGIN_C_DECLS
Definition: cs_defs.h:429
int cs_log_printf_flush(cs_log_t log)
Flush output of a log file.
Definition: cs_log.c:408
Definition: cs_log.h:49
void cs_log_separator(cs_log_t log)
Print a separator line in a log file.
Definition: cs_log.c:444
Definition: cs_log.h:51
cs_log_t
Definition: cs_log.h:47
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:299
#define END_C_DECLS
Definition: cs_defs.h:430
int cs_log_printf(cs_log_t log, const char *format,...)
Print log info to a given log type.
Definition: cs_log.c:354
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:470
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:327
size_t cs_log_strlen(const char *s)
Count printable length of a character string.
Definition: cs_log.c:228
Definition: cs_timer.h:57