Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / tracing / tracing-common.h
1 #if !defined(TRACING_COMMON_H)
2 #define TRACING_COMMON_H
3
4 // Amount of buffer data to dump when using ceph_ctf_sequence or ceph_ctf_sequencep.
5 // If 0, then *_data field is omitted entirely.
6 #if !defined(CEPH_TRACE_BUF_TRUNC_LEN)
7 #define CEPH_TRACE_BUF_TRUNC_LEN 0u
8 #endif
9
10 // TODO: This is GCC-specific.  Replace CEPH_MAX and CEPH_MIN with standard macros, if possible.
11 #define CEPH_MAX(a,b) \
12    ({ __typeof__ (a) _a = (a); \
13        __typeof__ (b) _b = (b); \
14      _a > _b ? _a : _b; })
15
16 #define CEPH_MIN(a,b) \
17    ({ __typeof__ (a) _a = (a); \
18        __typeof__ (b) _b = (b); \
19      _a < _b ? _a : _b; })
20
21 // type should be an integer type
22 // val should have type type*
23 #define ceph_ctf_integerp(type, field, val) \
24     ctf_integer(type, field, (val) == NULL ? 0 : (val)) \
25     ctf_integer(uint8_t, field##_isnull, (val) == NULL)
26
27 // val should have type char*
28 #define ceph_ctf_string(field, val) \
29     ctf_string(field, (val) == NULL ? "" : (val)) \
30     ctf_integer(uint8_t, field##_isnull, (val) == NULL)
31
32 // val should have type char**
33 #define ceph_ctf_stringp(field, val) \
34     ctf_string(field, ((val) == NULL || *(val) == NULL) ? "" : *(val)) \
35     ctf_integer(uint8_t, field##_isnull, (val) == NULL) \
36     ctf_integer(uint8_t, field##_data_isnull, (val) == NULL || *(val) == NULL)
37
38 // val should have type type*
39 // lenval should have type lentype
40 #if CEPH_TRACE_BUF_TRUNC_LEN > 0
41 #define ceph_ctf_sequence(type, field, val, lentype, lenval) \
42     ctf_integer_hex(void*, field, val) \
43     ctf_sequence(type, field##_data, (val) == NULL ? "" : (val), lentype, (val) == NULL ? 0 : CEPH_MIN((lenval), CEPH_TRACE_BUF_TRUNC_LEN)) \
44     ctf_integer(uint8_t, field##_isnull, (val) == NULL) \
45     ctf_integer(lentype, field##_len, lenval)
46 #else
47 #define ceph_ctf_sequence(type, field, val, lentype, lenval) \
48     ctf_integer_hex(void*, field, val) \
49     ctf_integer(uint8_t, field##_isnull, (val) == NULL) \
50     ctf_integer(lentype, field##_len, lenval)
51 #endif
52
53 // val should have type type**
54 // lenval should have type lentype*
55 #if CEPH_TRACE_BUF_TRUNC_LEN > 0
56 #define ceph_ctf_sequencep(type, field, val, lentype, lenval) \
57     ctf_integer_hex(void*, field, val) \
58     ctf_sequence(type, \
59                  field##_data, \
60                  ((val) == NULL || *(val) == NULL) ? "" : *(val), \
61                  lentype, \
62                  ((val) == NULL || *(val) == NULL || (lenval) == NULL) ? 0 : CEPH_MIN(*(lenval), CEPH_TRACE_BUF_TRUNC_LEN)) \
63     ctf_integer(uint8_t, field##_isnull, (val) == NULL) \
64     ctf_integer(uint8_t, field##_data_isnull, ((val) == NULL || *(val) == NULL)) \
65     ctf_integer(lentype, field##_len, (lenval) == NULL ? 0 : *(lenval)) \
66     ctf_integer(lentype, field##_len_isnull, (lenval) == NULL)
67 #else
68 #define ceph_ctf_sequencep(type, field, val, lentype, lenval) \
69     ctf_integer_hex(void*, field, val) \
70     ctf_integer(uint8_t, field##_isnull, (val) == NULL) \
71     ctf_integer(uint8_t, field##_data_isnull, ((val) == NULL || *(val) == NULL)) \
72     ctf_integer(lentype, field##_len, (lenval) == NULL ? 0 : *(lenval)) \
73     ctf_integer(lentype, field##_len_isnull, (lenval) == NULL)
74 #endif
75
76 // p should be of type struct timeval*
77 #define ceph_ctf_timevalp(field, p) \
78     ctf_integer(long int, field##_sec, (p) == NULL ? 0 : (p)->tv_sec) \
79     ctf_integer(long int, field##_usec, (p) == NULL ? 0 : (p)->tv_usec) \
80     ctf_integer(uint8_t, field##_isnull, (p) == NULL)
81
82 // p should be of type struct timespec*
83 #define ceph_ctf_timespecp(field, p) \
84     ctf_integer(long int, field##_sec, (p) == NULL ? 0 : (p)->tv_sec) \
85     ctf_integer(long int, field##_nsec, (p) == NULL ? 0 : (p)->tv_nsec) \
86     ctf_integer(uint8_t, field##_isnull, (p) == NULL)
87
88 // val should be of type time_t
89 // Currently assumes that time_t is an integer and no more than 64 bits wide.
90 // This is verified by the configure script.
91 #define ceph_ctf_time_t(field, val) \
92     ctf_integer(uint64_t, field, (uint64_t)(val))
93
94 // val should be of type time_t*
95 // Currently assumes that time_t is an integer and no more than 64 bits wide.
96 // This is verified by the configure script.
97 #define ceph_ctf_time_tp(field, val) \
98     ctf_integer(uint64_t, field, (val) == NULL ? 0 : (uint64_t)(*val)) \
99     ctf_integer(uint8_t, field##_isnull, (val) == NULL)
100
101
102 #endif /* TRACING_COMMON_H */