blob: f89411b9c29623492363b8d02c54f39b1cc7db18 [file] [log] [blame]
Imre Kis2ccd8e82021-10-08 11:21:14 +02001/* SPDX-License-Identifier: BSD-3-Clause */
2/*
3 * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
4 */
5
6#ifndef TRACE_H_
7#define TRACE_H_
8
9#include "compiler.h"
10
11#define TRACE_LEVEL_NONE (0)
12#define TRACE_LEVEL_ERROR (1)
13#define TRACE_LEVEL_INFO (2)
14#define TRACE_LEVEL_DEBUG (3)
15
16#ifndef TRACE_LEVEL
17#define TRACE_LEVEL TRACE_LEVEL_ERROR
18#endif /* TRACE_LEVEL */
19
20/**
21 * no_trace_printf will be optimized out becase of the 'if (0)' but all the
22 * checks will still run against the format string and the parameters.
23 */
24#define no_trace_printf(func, line, level, fmt, ...) \
25 do { \
26 if (0) { \
27 trace_printf(func, line, level, fmt, ##__VA_ARGS__); \
28 } \
29 } while (0)
30
31void trace_puts(const char *str);
32void trace_printf(const char *func, int line, int level, const char *fmt, ...) __printf(4, 5);
33
34#if TRACE_LEVEL >= TRACE_LEVEL_ERROR
35#define EMSG(...) trace_printf(__func__, __LINE__, TRACE_LEVEL_ERROR, __VA_ARGS__)
36#else
37#define EMSG(...) no_trace_printf(__func__, __LINE__, TRACE_LEVEL_ERROR, __VA_ARGS__)
38#endif /* TRACE_LEVEL >= TRACE_LEVEL_ERROR */
39
40#if TRACE_LEVEL >= TRACE_LEVEL_INFO
41#define IMSG(...) trace_printf(__func__, __LINE__, TRACE_LEVEL_INFO, __VA_ARGS__)
42#else
43#define IMSG(...) no_trace_printf(__func__, __LINE__, TRACE_LEVEL_INFO, __VA_ARGS__)
44#endif /* TRACE_LEVEL >= TRACE_LEVEL_INFO */
45
46#if TRACE_LEVEL >= TRACE_LEVEL_DEBUG
47#define DMSG(...) trace_printf(__func__, __LINE__, TRACE_LEVEL_DEBUG, __VA_ARGS__)
48#else
49#define DMSG(...) no_trace_printf(__func__, __LINE__, TRACE_LEVEL_DEBUG, __VA_ARGS__)
50#endif /* TRACE_LEVEL >= TRACE_LEVEL_DEBUG */
51
52#endif /* TRACE_H_ */