Code_Saturne
CFD tool
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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-2012 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_SETUP, /* Calculation setup and options log */
50  CS_LOG_PERFORMANCE, /* Performance log */
51  CS_LOG_N_TYPES /* Number of log file types */
52 
53 } cs_log_t;
54 
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 int
145  const char *format,
146  ...);
147 
148 /*----------------------------------------------------------------------------
149  * Flush for output of cs_log_printf() with modifiable behavior.
150  *
151  * If the argument is set to CS_LOG_N_TYPES, all log files are flushed.
152  *
153  * returns:
154  * 0 upon successful completion 0 is returned. Otherwise, EOF is returned
155  * and errno is set to indicate the error.
156  *----------------------------------------------------------------------------*/
157 
158 int
160 
161 /*----------------------------------------------------------------------------
162  * Print a separator line in a log file
163  *
164  * In parallel, output is only handled by rank 0.
165  *
166  * parameters:
167  * log <-- log file type
168  *----------------------------------------------------------------------------*/
169 
170 void
172 
173 /*----------------------------------------------------------------------------
174  * Output timing data block to a given log.
175  *
176  * If the optional array of call counters is used, only lines
177  * with a number of calls greater than 0 are logged.
178  *
179  * In parallel, output is only handled by rank 0.
180  *
181  * parameters:
182  * log <-- log file type
183  * indent <-- indentation before first column
184  * header_title <-- title for optional header line
185  * calls <-- true if calls column is to be used
186  *----------------------------------------------------------------------------*/
187 
188 void
190  int indent,
191  const char *header_title,
192  bool calls);
193 
194 /*----------------------------------------------------------------------------
195  * Output timing data block to a given log.
196  *
197  * If the optional array of call counters is used, only lines
198  * with a number of calls greater than 0 are logged.
199  *
200  * In parallel, output is only handled by rank 0.
201  *
202  * parameters:
203  * log <-- log file type
204  * indent <-- indentation before first column
205  * n_lines <-- number of lines in array, excluding header
206  * line_titles <-- array of titles for data lines
207  * calls <-- optional array of call counters, or NULL
208  * time_count <-- array of time counters
209  *----------------------------------------------------------------------------*/
210 
211 void
213  int indent,
214  int n_lines,
215  const char *line_titles[],
216  const unsigned calls[],
217  const cs_timer_counter_t time_count[]);
218 
219 /*----------------------------------------------------------------------------*/
220 
222 
223 #endif /* __CS_LOG_H__ */
Definition: cs_log.h:49
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:495
Definition: cs_log.h:51
#define BEGIN_C_DECLS
Definition: cs_defs.h:365
int cs_log_printf_flush(cs_log_t log)
Flush output of a log file.
Definition: cs_log.c:383
void cs_log_separator(cs_log_t log)
Print a separator line in a log file.
Definition: cs_log.c:413
Definition: cs_log.h:50
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:292
#define END_C_DECLS
Definition: cs_defs.h:366
int cs_log_printf(cs_log_t log, const char *format,...)
Print log info to a given log type.
Definition: cs_log.c:346
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:439
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:319
size_t cs_log_strlen(const char *s)
Count printable length of a character string.
Definition: cs_log.c:222
Definition: cs_timer.h:57