4 * Copyright (c) Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 #ifndef _SPDK_TRACE_H_
40 #define _SPDK_TRACE_H_
49 #define SPDK_TRACE_SIZE (32 * 1024)
51 struct spdk_trace_entry
{
60 /* If type changes from a uint8_t, change this value. */
61 #define SPDK_TRACE_MAX_OWNER (UCHAR_MAX + 1)
63 struct spdk_trace_owner
{
68 /* If type changes from a uint8_t, change this value. */
69 #define SPDK_TRACE_MAX_OBJECT (UCHAR_MAX + 1)
71 struct spdk_trace_object
{
76 #define SPDK_TRACE_MAX_GROUP_ID 16
77 #define SPDK_TRACE_MAX_TPOINT_ID (SPDK_TRACE_MAX_GROUP_ID * 64)
78 #define SPDK_TPOINT_ID(group, tpoint) ((group * 64) + tpoint)
80 struct spdk_trace_tpoint
{
88 uint8_t arg1_is_alias
;
92 struct spdk_trace_history
{
93 /** Logical core number associated with this structure instance. */
97 * Circular buffer of spdk_trace_entry structures for tracing
98 * tpoints on this core. Debug tool spdk_trace reads this
99 * buffer from shared memory to post-process the tpoint entries and
100 * display in a human-readable format.
102 struct spdk_trace_entry entries
[SPDK_TRACE_SIZE
];
105 * Running count of number of occurrences of each tracepoint on this
106 * lcore. Debug tools can use this to easily count tracepoints such as
107 * number of SCSI tasks completed or PDUs read.
109 uint64_t tpoint_count
[SPDK_TRACE_MAX_TPOINT_ID
];
111 /** Index to next spdk_trace_entry to fill in the circular buffer. */
116 #define SPDK_TRACE_MAX_LCORE 128
118 struct spdk_trace_histories
{
120 uint64_t tpoint_mask
[SPDK_TRACE_MAX_GROUP_ID
];
121 struct spdk_trace_history per_lcore_history
[SPDK_TRACE_MAX_LCORE
];
122 struct spdk_trace_owner owner
[UCHAR_MAX
+ 1];
123 struct spdk_trace_object object
[UCHAR_MAX
+ 1];
124 struct spdk_trace_tpoint tpoint
[SPDK_TRACE_MAX_TPOINT_ID
];
128 void spdk_trace_record(uint16_t tpoint_id
, uint16_t poller_id
, uint32_t size
,
129 uint64_t object_id
, uint64_t arg1
);
131 /** Returns the current tpoint mask. */
132 uint64_t spdk_trace_get_tpoint_mask(uint32_t group_id
);
134 /** Adds the specified tpoints to the current tpoint mask for the given tpoint group. */
135 void spdk_trace_set_tpoints(uint32_t group_id
, uint64_t tpoint_mask
);
137 /** Clears the specified tpoints from the current tpoint mask for the given tpoint group. */
138 void spdk_trace_clear_tpoints(uint32_t group_id
, uint64_t tpoint_mask
);
140 /** Returns a mask of all tracepoint groups which have at least one tracepoint enabled. */
141 uint64_t spdk_trace_get_tpoint_group_mask(void);
143 /** For each tpoint group specified in the group mask, enable all of its tpoints. */
144 void spdk_trace_set_tpoint_group_mask(uint64_t tpoint_group_mask
);
146 void spdk_trace_init(const char *shm_name
);
147 void spdk_trace_cleanup(void);
150 #define OBJECT_NONE 0
152 void spdk_trace_register_owner(uint8_t type
, char id_prefix
);
153 void spdk_trace_register_object(uint8_t type
, char id_prefix
);
154 void spdk_trace_register_description(const char *name
, const char *short_name
,
155 uint16_t tpoint_id
, uint8_t owner_type
,
156 uint8_t object_type
, uint8_t new_object
,
157 uint8_t arg1_is_ptr
, uint8_t arg1_is_alias
,
158 const char *arg1_name
);
160 struct spdk_trace_register_fn
{
161 void (*reg_fn
)(void);
162 struct spdk_trace_register_fn
*next
;
165 void spdk_trace_add_register_fn(struct spdk_trace_register_fn
*reg_fn
);
167 #define SPDK_TRACE_REGISTER_FN(fn) \
168 static void fn(void); \
169 struct spdk_trace_register_fn reg_ ## fn = { \
173 __attribute__((constructor)) static void _ ## fn(void) \
175 spdk_trace_add_register_fn(®_ ## fn); \