xref: /openbmc/linux/fs/iomap/trace.h (revision f80be457)
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 
87 #define IOMAP_TYPE_STRINGS \
88 	{ IOMAP_HOLE,		"HOLE" }, \
89 	{ IOMAP_DELALLOC,	"DELALLOC" }, \
90 	{ IOMAP_MAPPED,		"MAPPED" }, \
91 	{ IOMAP_UNWRITTEN,	"UNWRITTEN" }, \
92 	{ IOMAP_INLINE,		"INLINE" }
93 
94 #define IOMAP_FLAGS_STRINGS \
95 	{ IOMAP_WRITE,		"WRITE" }, \
96 	{ IOMAP_ZERO,		"ZERO" }, \
97 	{ IOMAP_REPORT,		"REPORT" }, \
98 	{ IOMAP_FAULT,		"FAULT" }, \
99 	{ IOMAP_DIRECT,		"DIRECT" }, \
100 	{ IOMAP_NOWAIT,		"NOWAIT" }
101 
102 #define IOMAP_F_FLAGS_STRINGS \
103 	{ IOMAP_F_NEW,		"NEW" }, \
104 	{ IOMAP_F_DIRTY,	"DIRTY" }, \
105 	{ IOMAP_F_SHARED,	"SHARED" }, \
106 	{ IOMAP_F_MERGED,	"MERGED" }, \
107 	{ IOMAP_F_BUFFER_HEAD,	"BH" }, \
108 	{ IOMAP_F_SIZE_CHANGED,	"SIZE_CHANGED" }
109 
110 DECLARE_EVENT_CLASS(iomap_class,
111 	TP_PROTO(struct inode *inode, struct iomap *iomap),
112 	TP_ARGS(inode, iomap),
113 	TP_STRUCT__entry(
114 		__field(dev_t, dev)
115 		__field(u64, ino)
116 		__field(u64, addr)
117 		__field(loff_t, offset)
118 		__field(u64, length)
119 		__field(u16, type)
120 		__field(u16, flags)
121 		__field(dev_t, bdev)
122 	),
123 	TP_fast_assign(
124 		__entry->dev = inode->i_sb->s_dev;
125 		__entry->ino = inode->i_ino;
126 		__entry->addr = iomap->addr;
127 		__entry->offset = iomap->offset;
128 		__entry->length = iomap->length;
129 		__entry->type = iomap->type;
130 		__entry->flags = iomap->flags;
131 		__entry->bdev = iomap->bdev ? iomap->bdev->bd_dev : 0;
132 	),
133 	TP_printk("dev %d:%d ino 0x%llx bdev %d:%d addr 0x%llx offset 0x%llx "
134 		  "length 0x%llx type %s flags %s",
135 		  MAJOR(__entry->dev), MINOR(__entry->dev),
136 		  __entry->ino,
137 		  MAJOR(__entry->bdev), MINOR(__entry->bdev),
138 		  __entry->addr,
139 		  __entry->offset,
140 		  __entry->length,
141 		  __print_symbolic(__entry->type, IOMAP_TYPE_STRINGS),
142 		  __print_flags(__entry->flags, "|", IOMAP_F_FLAGS_STRINGS))
143 )
144 
145 #define DEFINE_IOMAP_EVENT(name)		\
146 DEFINE_EVENT(iomap_class, name,	\
147 	TP_PROTO(struct inode *inode, struct iomap *iomap), \
148 	TP_ARGS(inode, iomap))
149 DEFINE_IOMAP_EVENT(iomap_iter_dstmap);
150 DEFINE_IOMAP_EVENT(iomap_iter_srcmap);
151 
152 TRACE_EVENT(iomap_iter,
153 	TP_PROTO(struct iomap_iter *iter, const void *ops,
154 		 unsigned long caller),
155 	TP_ARGS(iter, ops, caller),
156 	TP_STRUCT__entry(
157 		__field(dev_t, dev)
158 		__field(u64, ino)
159 		__field(loff_t, pos)
160 		__field(u64, length)
161 		__field(unsigned int, flags)
162 		__field(const void *, ops)
163 		__field(unsigned long, caller)
164 	),
165 	TP_fast_assign(
166 		__entry->dev = iter->inode->i_sb->s_dev;
167 		__entry->ino = iter->inode->i_ino;
168 		__entry->pos = iter->pos;
169 		__entry->length = iomap_length(iter);
170 		__entry->flags = iter->flags;
171 		__entry->ops = ops;
172 		__entry->caller = caller;
173 	),
174 	TP_printk("dev %d:%d ino 0x%llx pos 0x%llx length 0x%llx flags %s (0x%x) ops %ps caller %pS",
175 		  MAJOR(__entry->dev), MINOR(__entry->dev),
176 		   __entry->ino,
177 		   __entry->pos,
178 		   __entry->length,
179 		   __print_flags(__entry->flags, "|", IOMAP_FLAGS_STRINGS),
180 		   __entry->flags,
181 		   __entry->ops,
182 		   (void *)__entry->caller)
183 );
184 
185 #endif /* _IOMAP_TRACE_H */
186 
187 #undef TRACE_INCLUDE_PATH
188 #define TRACE_INCLUDE_PATH .
189 #define TRACE_INCLUDE_FILE trace
190 #include <trace/define_trace.h>
191