1 /*
2  * Copyright © 2020 Google, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #ifndef FREEDRENO_LOG_H_
25 #define FREEDRENO_LOG_H_
26 
27 #include "freedreno_util.h"
28 
29 struct fd_batch;
30 struct fd_context;
31 
32 void fd_log_process(struct fd_context *ctx, bool wait);
33 void fd_log_flush(struct fd_batch *batch);
34 void _fd_log(struct fd_batch *batch, const char *fmt, ...)
35 	_util_printf_format(2, 3);
36 
37 /* macro wrapper so that arguments are not evaluated when logging is not
38  * enabled:
39  */
40 #define fd_log(__batch, __fmt, ...) 							\
41 	do { 														\
42 		if (unlikely(fd_mesa_debug & FD_DBG_LOG)) { 			\
43 			_fd_log(__batch, __fmt, ##__VA_ARGS__); 			\
44 		} else { 												\
45 			DBG(__fmt, ##__VA_ARGS__); 							\
46 		} 														\
47 	} while (0)
48 
49 /* A variant of fd_log() which provides a FILE* stream to write the
50  * log msg into, mostly to make u_dump_state stuff useful
51  */
52 #define fd_log_stream(__batch, __stream, __exp)					\
53 	do {														\
54 		if (unlikely(fd_mesa_debug & FD_DBG_LOG)) { 			\
55 			char buf[1024];										\
56 			FILE *__stream = fmemopen(buf, sizeof(buf), "w");	\
57 			__exp;												\
58 			fclose(__stream);									\
59 			_fd_log(__batch, "%s", buf);						\
60 		} 														\
61 	} while (0)
62 
63 void fd_log_eof(struct fd_context *ctx);
64 
65 #endif /* FREEDRENO_LOG_H_ */
66