xref: /linux/fs/iomap/trace.h (revision e6a901a00822659181c93c86d8bbc2a17779fddc)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2009-2021 Christoph Hellwig
4  *
5  * NOTE: none of these tracepoints shall be considered a stable kernel ABI
6  * as they can change at any time.
7  *
8  * Current conventions for printing numbers measuring specific units:
9  *
10  * offset: byte offset into a subcomponent of a file operation
11  * pos: file offset, in bytes
12  * length: length of a file operation, in bytes
13  * ino: inode number
14  *
15  * Numbers describing space allocations should be formatted in hexadecimal.
16  */
17 #undef TRACE_SYSTEM
18 #define TRACE_SYSTEM iomap
19 
20 #if !defined(_IOMAP_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
21 #define _IOMAP_TRACE_H
22 
23 #include <linux/tracepoint.h>
24 
25 struct inode;
26 
27 DECLARE_EVENT_CLASS(iomap_readpage_class,
28 	TP_PROTO(struct inode *inode, int nr_pages),
29 	TP_ARGS(inode, nr_pages),
30 	TP_STRUCT__entry(
31 		__field(dev_t, dev)
32 		__field(u64, ino)
33 		__field(int, nr_pages)
34 	),
35 	TP_fast_assign(
36 		__entry->dev = inode->i_sb->s_dev;
37 		__entry->ino = inode->i_ino;
38 		__entry->nr_pages = nr_pages;
39 	),
40 	TP_printk("dev %d:%d ino 0x%llx nr_pages %d",
41 		  MAJOR(__entry->dev), MINOR(__entry->dev),
42 		  __entry->ino,
43 		  __entry->nr_pages)
44 )
45 
46 #define DEFINE_READPAGE_EVENT(name)		\
47 DEFINE_EVENT(iomap_readpage_class, name,	\
48 	TP_PROTO(struct inode *inode, int nr_pages), \
49 	TP_ARGS(inode, nr_pages))
50 DEFINE_READPAGE_EVENT(iomap_readpage);
51 DEFINE_READPAGE_EVENT(iomap_readahead);
52 
53 DECLARE_EVENT_CLASS(iomap_range_class,
54 	TP_PROTO(struct inode *inode, loff_t off, u64 len),
55 	TP_ARGS(inode, off, len),
56 	TP_STRUCT__entry(
57 		__field(dev_t, dev)
58 		__field(u64, ino)
59 		__field(loff_t, size)
60 		__field(loff_t, offset)
61 		__field(u64, length)
62 	),
63 	TP_fast_assign(
64 		__entry->dev = inode->i_sb->s_dev;
65 		__entry->ino = inode->i_ino;
66 		__entry->size = i_size_read(inode);
67 		__entry->offset = off;
68 		__entry->length = len;
69 	),
70 	TP_printk("dev %d:%d ino 0x%llx size 0x%llx offset 0x%llx length 0x%llx",
71 		  MAJOR(__entry->dev), MINOR(__entry->dev),
72 		  __entry->ino,
73 		  __entry->size,
74 		  __entry->offset,
75 		  __entry->length)
76 )
77 
78 #define DEFINE_RANGE_EVENT(name)		\
79 DEFINE_EVENT(iomap_range_class, name,	\
80 	TP_PROTO(struct inode *inode, loff_t off, u64 len),\
81 	TP_ARGS(inode, off, len))
82 DEFINE_RANGE_EVENT(iomap_writepage);
83 DEFINE_RANGE_EVENT(iomap_release_folio);
84 DEFINE_RANGE_EVENT(iomap_invalidate_folio);
85 DEFINE_RANGE_EVENT(iomap_dio_invalidate_fail);
86 DEFINE_RANGE_EVENT(iomap_dio_rw_queued);
87 
88 #define IOMAP_TYPE_STRINGS \
89 	{ IOMAP_HOLE,		"HOLE" }, \
90 	{ IOMAP_DELALLOC,	"DELALLOC" }, \
91 	{ IOMAP_MAPPED,		"MAPPED" }, \
92 	{ IOMAP_UNWRITTEN,	"UNWRITTEN" }, \
93 	{ IOMAP_INLINE,		"INLINE" }
94 
95 #define IOMAP_FLAGS_STRINGS \
96 	{ IOMAP_WRITE,		"WRITE" }, \
97 	{ IOMAP_ZERO,		"ZERO" }, \
98 	{ IOMAP_REPORT,		"REPORT" }, \
99 	{ IOMAP_FAULT,		"FAULT" }, \
100 	{ IOMAP_DIRECT,		"DIRECT" }, \
101 	{ IOMAP_NOWAIT,		"NOWAIT" }
102 
103 #define IOMAP_F_FLAGS_STRINGS \
104 	{ IOMAP_F_NEW,		"NEW" }, \
105 	{ IOMAP_F_DIRTY,	"DIRTY" }, \
106 	{ IOMAP_F_SHARED,	"SHARED" }, \
107 	{ IOMAP_F_MERGED,	"MERGED" }, \
108 	{ IOMAP_F_BUFFER_HEAD,	"BH" }, \
109 	{ IOMAP_F_SIZE_CHANGED,	"SIZE_CHANGED" }
110 
111 #define IOMAP_DIO_STRINGS \
112 	{IOMAP_DIO_FORCE_WAIT,	"DIO_FORCE_WAIT" }, \
113 	{IOMAP_DIO_OVERWRITE_ONLY, "DIO_OVERWRITE_ONLY" }, \
114 	{IOMAP_DIO_PARTIAL,	"DIO_PARTIAL" }
115 
116 DECLARE_EVENT_CLASS(iomap_class,
117 	TP_PROTO(struct inode *inode, struct iomap *iomap),
118 	TP_ARGS(inode, iomap),
119 	TP_STRUCT__entry(
120 		__field(dev_t, dev)
121 		__field(u64, ino)
122 		__field(u64, addr)
123 		__field(loff_t, offset)
124 		__field(u64, length)
125 		__field(u16, type)
126 		__field(u16, flags)
127 		__field(dev_t, bdev)
128 	),
129 	TP_fast_assign(
130 		__entry->dev = inode->i_sb->s_dev;
131 		__entry->ino = inode->i_ino;
132 		__entry->addr = iomap->addr;
133 		__entry->offset = iomap->offset;
134 		__entry->length = iomap->length;
135 		__entry->type = iomap->type;
136 		__entry->flags = iomap->flags;
137 		__entry->bdev = iomap->bdev ? iomap->bdev->bd_dev : 0;
138 	),
139 	TP_printk("dev %d:%d ino 0x%llx bdev %d:%d addr 0x%llx offset 0x%llx "
140 		  "length 0x%llx type %s flags %s",
141 		  MAJOR(__entry->dev), MINOR(__entry->dev),
142 		  __entry->ino,
143 		  MAJOR(__entry->bdev), MINOR(__entry->bdev),
144 		  __entry->addr,
145 		  __entry->offset,
146 		  __entry->length,
147 		  __print_symbolic(__entry->type, IOMAP_TYPE_STRINGS),
148 		  __print_flags(__entry->flags, "|", IOMAP_F_FLAGS_STRINGS))
149 )
150 
151 #define DEFINE_IOMAP_EVENT(name)		\
152 DEFINE_EVENT(iomap_class, name,	\
153 	TP_PROTO(struct inode *inode, struct iomap *iomap), \
154 	TP_ARGS(inode, iomap))
155 DEFINE_IOMAP_EVENT(iomap_iter_dstmap);
156 DEFINE_IOMAP_EVENT(iomap_iter_srcmap);
157 
158 TRACE_EVENT(iomap_writepage_map,
159 	TP_PROTO(struct inode *inode, u64 pos, unsigned int dirty_len,
160 		 struct iomap *iomap),
161 	TP_ARGS(inode, pos, dirty_len, iomap),
162 	TP_STRUCT__entry(
163 		__field(dev_t, dev)
164 		__field(u64, ino)
165 		__field(u64, pos)
166 		__field(u64, dirty_len)
167 		__field(u64, addr)
168 		__field(loff_t, offset)
169 		__field(u64, length)
170 		__field(u16, type)
171 		__field(u16, flags)
172 		__field(dev_t, bdev)
173 	),
174 	TP_fast_assign(
175 		__entry->dev = inode->i_sb->s_dev;
176 		__entry->ino = inode->i_ino;
177 		__entry->pos = pos;
178 		__entry->dirty_len = dirty_len;
179 		__entry->addr = iomap->addr;
180 		__entry->offset = iomap->offset;
181 		__entry->length = iomap->length;
182 		__entry->type = iomap->type;
183 		__entry->flags = iomap->flags;
184 		__entry->bdev = iomap->bdev ? iomap->bdev->bd_dev : 0;
185 	),
186 	TP_printk("dev %d:%d ino 0x%llx bdev %d:%d pos 0x%llx dirty len 0x%llx "
187 		  "addr 0x%llx offset 0x%llx length 0x%llx type %s flags %s",
188 		  MAJOR(__entry->dev), MINOR(__entry->dev),
189 		  __entry->ino,
190 		  MAJOR(__entry->bdev), MINOR(__entry->bdev),
191 		  __entry->pos,
192 		  __entry->dirty_len,
193 		  __entry->addr,
194 		  __entry->offset,
195 		  __entry->length,
196 		  __print_symbolic(__entry->type, IOMAP_TYPE_STRINGS),
197 		  __print_flags(__entry->flags, "|", IOMAP_F_FLAGS_STRINGS))
198 );
199 
200 TRACE_EVENT(iomap_iter,
201 	TP_PROTO(struct iomap_iter *iter, const void *ops,
202 		 unsigned long caller),
203 	TP_ARGS(iter, ops, caller),
204 	TP_STRUCT__entry(
205 		__field(dev_t, dev)
206 		__field(u64, ino)
207 		__field(loff_t, pos)
208 		__field(u64, length)
209 		__field(s64, processed)
210 		__field(unsigned int, flags)
211 		__field(const void *, ops)
212 		__field(unsigned long, caller)
213 	),
214 	TP_fast_assign(
215 		__entry->dev = iter->inode->i_sb->s_dev;
216 		__entry->ino = iter->inode->i_ino;
217 		__entry->pos = iter->pos;
218 		__entry->length = iomap_length(iter);
219 		__entry->processed = iter->processed;
220 		__entry->flags = iter->flags;
221 		__entry->ops = ops;
222 		__entry->caller = caller;
223 	),
224 	TP_printk("dev %d:%d ino 0x%llx pos 0x%llx length 0x%llx processed %lld flags %s (0x%x) ops %ps caller %pS",
225 		  MAJOR(__entry->dev), MINOR(__entry->dev),
226 		   __entry->ino,
227 		   __entry->pos,
228 		   __entry->length,
229 		   __entry->processed,
230 		   __print_flags(__entry->flags, "|", IOMAP_FLAGS_STRINGS),
231 		   __entry->flags,
232 		   __entry->ops,
233 		   (void *)__entry->caller)
234 );
235 
236 TRACE_EVENT(iomap_dio_rw_begin,
237 	TP_PROTO(struct kiocb *iocb, struct iov_iter *iter,
238 		 unsigned int dio_flags, size_t done_before),
239 	TP_ARGS(iocb, iter, dio_flags, done_before),
240 	TP_STRUCT__entry(
241 		__field(dev_t,	dev)
242 		__field(ino_t,	ino)
243 		__field(loff_t, isize)
244 		__field(loff_t, pos)
245 		__field(size_t,	count)
246 		__field(size_t,	done_before)
247 		__field(int,	ki_flags)
248 		__field(unsigned int,	dio_flags)
249 		__field(bool,	aio)
250 	),
251 	TP_fast_assign(
252 		__entry->dev = file_inode(iocb->ki_filp)->i_sb->s_dev;
253 		__entry->ino = file_inode(iocb->ki_filp)->i_ino;
254 		__entry->isize = file_inode(iocb->ki_filp)->i_size;
255 		__entry->pos = iocb->ki_pos;
256 		__entry->count = iov_iter_count(iter);
257 		__entry->done_before = done_before;
258 		__entry->ki_flags = iocb->ki_flags;
259 		__entry->dio_flags = dio_flags;
260 		__entry->aio = !is_sync_kiocb(iocb);
261 	),
262 	TP_printk("dev %d:%d ino 0x%lx size 0x%llx offset 0x%llx length 0x%zx done_before 0x%zx flags %s dio_flags %s aio %d",
263 		  MAJOR(__entry->dev), MINOR(__entry->dev),
264 		  __entry->ino,
265 		  __entry->isize,
266 		  __entry->pos,
267 		  __entry->count,
268 		  __entry->done_before,
269 		  __print_flags(__entry->ki_flags, "|", TRACE_IOCB_STRINGS),
270 		  __print_flags(__entry->dio_flags, "|", IOMAP_DIO_STRINGS),
271 		  __entry->aio)
272 );
273 
274 TRACE_EVENT(iomap_dio_complete,
275 	TP_PROTO(struct kiocb *iocb, int error, ssize_t ret),
276 	TP_ARGS(iocb, error, ret),
277 	TP_STRUCT__entry(
278 		__field(dev_t,	dev)
279 		__field(ino_t,	ino)
280 		__field(loff_t, isize)
281 		__field(loff_t, pos)
282 		__field(int,	ki_flags)
283 		__field(bool,	aio)
284 		__field(int,	error)
285 		__field(ssize_t, ret)
286 	),
287 	TP_fast_assign(
288 		__entry->dev = file_inode(iocb->ki_filp)->i_sb->s_dev;
289 		__entry->ino = file_inode(iocb->ki_filp)->i_ino;
290 		__entry->isize = file_inode(iocb->ki_filp)->i_size;
291 		__entry->pos = iocb->ki_pos;
292 		__entry->ki_flags = iocb->ki_flags;
293 		__entry->aio = !is_sync_kiocb(iocb);
294 		__entry->error = error;
295 		__entry->ret = ret;
296 	),
297 	TP_printk("dev %d:%d ino 0x%lx size 0x%llx offset 0x%llx flags %s aio %d error %d ret %zd",
298 		  MAJOR(__entry->dev), MINOR(__entry->dev),
299 		  __entry->ino,
300 		  __entry->isize,
301 		  __entry->pos,
302 		  __print_flags(__entry->ki_flags, "|", TRACE_IOCB_STRINGS),
303 		  __entry->aio,
304 		  __entry->error,
305 		  __entry->ret)
306 );
307 
308 #endif /* _IOMAP_TRACE_H */
309 
310 #undef TRACE_INCLUDE_PATH
311 #define TRACE_INCLUDE_PATH .
312 #define TRACE_INCLUDE_FILE trace
313 #include <trace/define_trace.h>
314