trace: add internal init and fini interface
[dpdk.git] / lib / librte_eal / common / eal_trace.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2020 Marvell International Ltd.
3  */
4
5 #ifndef __EAL_TRACE_H
6 #define __EAL_TRACE_H
7
8 #include <rte_spinlock.h>
9 #include <rte_trace.h>
10 #include <rte_trace_point.h>
11 #include <rte_uuid.h>
12
13 #define trace_err(fmt, args...) \
14         RTE_LOG(ERR, EAL, "%s():%u " fmt "\n", __func__, __LINE__, ## args)
15
16 #define trace_crit(fmt, args...) \
17         RTE_LOG(CRIT, EAL, "%s():%u " fmt "\n", __func__, __LINE__, ## args)
18
19 #define TRACE_PREFIX_LEN 12
20 #define TRACE_DIR_STR_LEN (sizeof("YYYY-mm-dd-AM-HH-MM-SS") + TRACE_PREFIX_LEN)
21 #define TRACE_CTF_FIELD_SIZE 384
22 #define TRACE_POINT_NAME_SIZE 64
23
24 struct trace_point {
25         STAILQ_ENTRY(trace_point) next;
26         rte_trace_point_t *handle;
27         char name[TRACE_POINT_NAME_SIZE];
28         char ctf_field[TRACE_CTF_FIELD_SIZE];
29 };
30
31 struct trace {
32         char dir[PATH_MAX];
33         int dir_offset;
34         int register_errno;
35         bool status;
36         enum rte_trace_mode mode;
37         rte_uuid_t uuid;
38         uint32_t buff_len;
39         uint32_t nb_trace_points;
40         rte_spinlock_t lock;
41 };
42
43 /* Helper functions */
44 static inline uint16_t
45 trace_id_get(rte_trace_point_t *trace)
46 {
47         return (*trace & __RTE_TRACE_FIELD_ID_MASK) >>
48                 __RTE_TRACE_FIELD_ID_SHIFT;
49 }
50
51 /* Trace object functions */
52 struct trace *trace_obj_get(void);
53
54 /* Trace point list functions */
55 STAILQ_HEAD(trace_point_head, trace_point);
56 struct trace_point_head *trace_list_head_get(void);
57
58 /* Util functions */
59 bool trace_has_duplicate_entry(void);
60 void trace_uuid_generate(void);
61 int trace_mkdir(void);
62
63 /* EAL interface */
64 int eal_trace_init(void);
65 void eal_trace_fini(void);
66
67 #endif /* __EAL_TRACE_H */