xref: /freebsd-src/sys/contrib/openzfs/include/os/linux/zfs/sys/trace_dbuf.h (revision 7a7741af18d6c8a804cc643cb7ecda9d730c6aa6)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or https://opensource.org/licenses/CDDL-1.0.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 #if defined(_KERNEL)
23 #if defined(HAVE_DECLARE_EVENT_CLASS)
24 
25 #undef TRACE_SYSTEM
26 #define	TRACE_SYSTEM zfs
27 
28 #undef TRACE_SYSTEM_VAR
29 #define	TRACE_SYSTEM_VAR zfs_dbuf
30 
31 #if !defined(_TRACE_DBUF_H) || defined(TRACE_HEADER_MULTI_READ)
32 #define	_TRACE_DBUF_H
33 
34 #include <linux/tracepoint.h>
35 #include <sys/types.h>
36 
37 #ifndef	TRACE_DBUF_MSG_MAX
38 #define	TRACE_DBUF_MSG_MAX	512
39 #endif
40 
41 /*
42  * Generic support for two argument tracepoints of the form:
43  *
44  * DTRACE_PROBE2(...,
45  *     dmu_buf_impl_t *, ...,
46  *     zio_t *, ...);
47  */
48 #define	DBUF_TP_STRUCT_ENTRY_OS_SPA \
49 	    (db != NULL && \
50 		POINTER_IS_VALID(DB_DNODE(db)->dn_objset)) \
51 	    ? spa_name(DB_DNODE(db)->dn_objset->os_spa) : "NULL"
52 
53 #define	DBUF_TP_STRUCT_ENTRY					\
54 	__string(os_spa, DBUF_TP_STRUCT_ENTRY_OS_SPA)		\
55 	__field(uint64_t,	ds_object)			\
56 	__field(uint64_t,	db_object)			\
57 	__field(uint64_t,	db_level)			\
58 	__field(uint64_t,	db_blkid)			\
59 	__field(uint64_t,	db_offset)			\
60 	__field(uint64_t,	db_size)			\
61 	__field(uint64_t,	db_state)			\
62 	__field(int64_t,	db_holds)
63 
64 #define	DBUF_TP_FAST_ASSIGN						\
65 	if (db != NULL) {						\
66 		__assign_str_impl(os_spa, DBUF_TP_STRUCT_ENTRY_OS_SPA); \
67 		__entry->ds_object = db->db_objset->os_dsl_dataset ?	\
68 		db->db_objset->os_dsl_dataset->ds_object : 0;		\
69 									\
70 		__entry->db_object = db->db.db_object;			\
71 		__entry->db_level  = db->db_level;			\
72 		__entry->db_blkid  = db->db_blkid;			\
73 		__entry->db_offset = db->db.db_offset;			\
74 		__entry->db_size   = db->db.db_size;			\
75 		__entry->db_state  = db->db_state;			\
76 		__entry->db_holds  = zfs_refcount_count(&db->db_holds);	\
77 	} else {							\
78 		__assign_str_impl(os_spa, DBUF_TP_STRUCT_ENTRY_OS_SPA); \
79 		__entry->ds_object = 0;					\
80 		__entry->db_object = 0;					\
81 		__entry->db_level  = 0;					\
82 		__entry->db_blkid  = 0;					\
83 		__entry->db_offset = 0;					\
84 		__entry->db_size   = 0;					\
85 		__entry->db_state  = 0;					\
86 		__entry->db_holds  = 0;					\
87 	}
88 
89 #define	DBUF_TP_PRINTK_FMT						\
90 	"dbuf { spa \"%s\" objset %llu object %llu level %llu "		\
91 	"blkid %llu offset %llu size %llu state %llu holds %lld }"
92 
93 #define	DBUF_TP_PRINTK_ARGS					\
94 	__get_str(os_spa), __entry->ds_object,			\
95 	__entry->db_object, __entry->db_level,			\
96 	__entry->db_blkid, __entry->db_offset,			\
97 	__entry->db_size, __entry->db_state, __entry->db_holds
98 
99 /* BEGIN CSTYLED */
100 DECLARE_EVENT_CLASS(zfs_dbuf_class,
101 	TP_PROTO(dmu_buf_impl_t *db, zio_t *zio),
102 	TP_ARGS(db, zio),
103 	TP_STRUCT__entry(DBUF_TP_STRUCT_ENTRY),
104 	TP_fast_assign(DBUF_TP_FAST_ASSIGN),
105 	TP_printk(DBUF_TP_PRINTK_FMT, DBUF_TP_PRINTK_ARGS)
106 );
107 
108 DECLARE_EVENT_CLASS(zfs_dbuf_state_class,
109 	TP_PROTO(dmu_buf_impl_t *db, const char *why),
110 	TP_ARGS(db, why),
111 	TP_STRUCT__entry(DBUF_TP_STRUCT_ENTRY),
112 	TP_fast_assign(DBUF_TP_FAST_ASSIGN),
113 	TP_printk(DBUF_TP_PRINTK_FMT, DBUF_TP_PRINTK_ARGS)
114 );
115 /* END CSTYLED */
116 
117 #define	DEFINE_DBUF_EVENT(name) \
118 DEFINE_EVENT(zfs_dbuf_class, name, \
119     TP_PROTO(dmu_buf_impl_t *db, zio_t *zio), \
120     TP_ARGS(db, zio))
121 DEFINE_DBUF_EVENT(zfs_blocked__read);
122 
123 #define	DEFINE_DBUF_STATE_EVENT(name) \
124 DEFINE_EVENT(zfs_dbuf_state_class, name, \
125     TP_PROTO(dmu_buf_impl_t *db, const char *why), \
126     TP_ARGS(db, why))
127 DEFINE_DBUF_STATE_EVENT(zfs_dbuf__state_change);
128 
129 /* BEGIN CSTYLED */
130 DECLARE_EVENT_CLASS(zfs_dbuf_evict_one_class,
131 	TP_PROTO(dmu_buf_impl_t *db, multilist_sublist_t *mls),
132 	TP_ARGS(db, mls),
133 	TP_STRUCT__entry(DBUF_TP_STRUCT_ENTRY),
134 	TP_fast_assign(DBUF_TP_FAST_ASSIGN),
135 	TP_printk(DBUF_TP_PRINTK_FMT, DBUF_TP_PRINTK_ARGS)
136 );
137 /* END CSTYLED */
138 
139 #define	DEFINE_DBUF_EVICT_ONE_EVENT(name) \
140 DEFINE_EVENT(zfs_dbuf_evict_one_class, name, \
141     TP_PROTO(dmu_buf_impl_t *db, multilist_sublist_t *mls), \
142     TP_ARGS(db, mls))
143 DEFINE_DBUF_EVICT_ONE_EVENT(zfs_dbuf__evict__one);
144 
145 #endif /* _TRACE_DBUF_H */
146 
147 #undef TRACE_INCLUDE_PATH
148 #undef TRACE_INCLUDE_FILE
149 #define	TRACE_INCLUDE_PATH sys
150 #define	TRACE_INCLUDE_FILE trace_dbuf
151 #include <trace/define_trace.h>
152 
153 #else
154 
155 DEFINE_DTRACE_PROBE2(blocked__read);
156 DEFINE_DTRACE_PROBE2(dbuf__evict__one);
157 DEFINE_DTRACE_PROBE2(dbuf__state_change);
158 
159 #endif /* HAVE_DECLARE_EVENT_CLASS */
160 #endif /* _KERNEL */
161