bcachefs: Initial commit
[linux-block.git] / fs / bcachefs / trace.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #undef TRACE_SYSTEM
3 #define TRACE_SYSTEM bcachefs
4
5 #if !defined(_TRACE_BCACHEFS_H) || defined(TRACE_HEADER_MULTI_READ)
6 #define _TRACE_BCACHEFS_H
7
8 #include <linux/tracepoint.h>
9
10 DECLARE_EVENT_CLASS(bpos,
11         TP_PROTO(struct bpos *p),
12         TP_ARGS(p),
13
14         TP_STRUCT__entry(
15                 __field(u64,    inode                           )
16                 __field(u64,    offset                          )
17         ),
18
19         TP_fast_assign(
20                 __entry->inode  = p->inode;
21                 __entry->offset = p->offset;
22         ),
23
24         TP_printk("%llu:%llu", __entry->inode, __entry->offset)
25 );
26
27 DECLARE_EVENT_CLASS(bkey,
28         TP_PROTO(const struct bkey *k),
29         TP_ARGS(k),
30
31         TP_STRUCT__entry(
32                 __field(u64,    inode                           )
33                 __field(u64,    offset                          )
34                 __field(u32,    size                            )
35         ),
36
37         TP_fast_assign(
38                 __entry->inode  = k->p.inode;
39                 __entry->offset = k->p.offset;
40                 __entry->size   = k->size;
41         ),
42
43         TP_printk("%llu:%llu len %u", __entry->inode,
44                   __entry->offset, __entry->size)
45 );
46
47 DECLARE_EVENT_CLASS(bch_dev,
48         TP_PROTO(struct bch_dev *ca),
49         TP_ARGS(ca),
50
51         TP_STRUCT__entry(
52                 __array(char,           uuid,   16      )
53         ),
54
55         TP_fast_assign(
56                 memcpy(__entry->uuid, ca->uuid.b, 16);
57         ),
58
59         TP_printk("%pU", __entry->uuid)
60 );
61
62 DECLARE_EVENT_CLASS(bch_fs,
63         TP_PROTO(struct bch_fs *c),
64         TP_ARGS(c),
65
66         TP_STRUCT__entry(
67                 __array(char,           uuid,   16 )
68         ),
69
70         TP_fast_assign(
71                 memcpy(__entry->uuid, c->sb.user_uuid.b, 16);
72         ),
73
74         TP_printk("%pU", __entry->uuid)
75 );
76
77 DECLARE_EVENT_CLASS(bio,
78         TP_PROTO(struct bio *bio),
79         TP_ARGS(bio),
80
81         TP_STRUCT__entry(
82                 __field(dev_t,          dev                     )
83                 __field(sector_t,       sector                  )
84                 __field(unsigned int,   nr_sector               )
85                 __array(char,           rwbs,   6               )
86         ),
87
88         TP_fast_assign(
89                 __entry->dev            = bio->bi_bdev ? bio_dev(bio) : 0;
90                 __entry->sector         = bio->bi_iter.bi_sector;
91                 __entry->nr_sector      = bio->bi_iter.bi_size >> 9;
92                 blk_fill_rwbs(__entry->rwbs, bio->bi_opf);
93         ),
94
95         TP_printk("%d,%d  %s %llu + %u",
96                   MAJOR(__entry->dev), MINOR(__entry->dev), __entry->rwbs,
97                   (unsigned long long)__entry->sector, __entry->nr_sector)
98 );
99
100 /* io.c: */
101
102 DEFINE_EVENT(bio, read_split,
103         TP_PROTO(struct bio *bio),
104         TP_ARGS(bio)
105 );
106
107 DEFINE_EVENT(bio, read_bounce,
108         TP_PROTO(struct bio *bio),
109         TP_ARGS(bio)
110 );
111
112 DEFINE_EVENT(bio, read_retry,
113         TP_PROTO(struct bio *bio),
114         TP_ARGS(bio)
115 );
116
117 DEFINE_EVENT(bio, promote,
118         TP_PROTO(struct bio *bio),
119         TP_ARGS(bio)
120 );
121
122 /* Journal */
123
124 DEFINE_EVENT(bch_fs, journal_full,
125         TP_PROTO(struct bch_fs *c),
126         TP_ARGS(c)
127 );
128
129 DEFINE_EVENT(bch_fs, journal_entry_full,
130         TP_PROTO(struct bch_fs *c),
131         TP_ARGS(c)
132 );
133
134 DEFINE_EVENT(bio, journal_write,
135         TP_PROTO(struct bio *bio),
136         TP_ARGS(bio)
137 );
138
139 /* bset.c: */
140
141 DEFINE_EVENT(bpos, bkey_pack_pos_fail,
142         TP_PROTO(struct bpos *p),
143         TP_ARGS(p)
144 );
145
146 /* Btree */
147
148 DECLARE_EVENT_CLASS(btree_node,
149         TP_PROTO(struct bch_fs *c, struct btree *b),
150         TP_ARGS(c, b),
151
152         TP_STRUCT__entry(
153                 __array(char,           uuid,           16      )
154                 __field(u8,             level                   )
155                 __field(u8,             id                      )
156                 __field(u64,            inode                   )
157                 __field(u64,            offset                  )
158         ),
159
160         TP_fast_assign(
161                 memcpy(__entry->uuid, c->sb.user_uuid.b, 16);
162                 __entry->level          = b->level;
163                 __entry->id             = b->btree_id;
164                 __entry->inode          = b->key.k.p.inode;
165                 __entry->offset         = b->key.k.p.offset;
166         ),
167
168         TP_printk("%pU  %u id %u %llu:%llu",
169                   __entry->uuid, __entry->level, __entry->id,
170                   __entry->inode, __entry->offset)
171 );
172
173 DEFINE_EVENT(btree_node, btree_read,
174         TP_PROTO(struct bch_fs *c, struct btree *b),
175         TP_ARGS(c, b)
176 );
177
178 TRACE_EVENT(btree_write,
179         TP_PROTO(struct btree *b, unsigned bytes, unsigned sectors),
180         TP_ARGS(b, bytes, sectors),
181
182         TP_STRUCT__entry(
183                 __field(enum bkey_type, type)
184                 __field(unsigned,       bytes                   )
185                 __field(unsigned,       sectors                 )
186         ),
187
188         TP_fast_assign(
189                 __entry->type   = btree_node_type(b);
190                 __entry->bytes  = bytes;
191                 __entry->sectors = sectors;
192         ),
193
194         TP_printk("bkey type %u bytes %u sectors %u",
195                   __entry->type , __entry->bytes, __entry->sectors)
196 );
197
198 DEFINE_EVENT(btree_node, btree_node_alloc,
199         TP_PROTO(struct bch_fs *c, struct btree *b),
200         TP_ARGS(c, b)
201 );
202
203 DEFINE_EVENT(btree_node, btree_node_free,
204         TP_PROTO(struct bch_fs *c, struct btree *b),
205         TP_ARGS(c, b)
206 );
207
208 DEFINE_EVENT(btree_node, btree_node_reap,
209         TP_PROTO(struct bch_fs *c, struct btree *b),
210         TP_ARGS(c, b)
211 );
212
213 DECLARE_EVENT_CLASS(btree_node_cannibalize_lock,
214         TP_PROTO(struct bch_fs *c),
215         TP_ARGS(c),
216
217         TP_STRUCT__entry(
218                 __array(char,                   uuid,   16      )
219         ),
220
221         TP_fast_assign(
222                 memcpy(__entry->uuid, c->sb.user_uuid.b, 16);
223         ),
224
225         TP_printk("%pU", __entry->uuid)
226 );
227
228 DEFINE_EVENT(btree_node_cannibalize_lock, btree_node_cannibalize_lock_fail,
229         TP_PROTO(struct bch_fs *c),
230         TP_ARGS(c)
231 );
232
233 DEFINE_EVENT(btree_node_cannibalize_lock, btree_node_cannibalize_lock,
234         TP_PROTO(struct bch_fs *c),
235         TP_ARGS(c)
236 );
237
238 DEFINE_EVENT(btree_node_cannibalize_lock, btree_node_cannibalize,
239         TP_PROTO(struct bch_fs *c),
240         TP_ARGS(c)
241 );
242
243 DEFINE_EVENT(bch_fs, btree_node_cannibalize_unlock,
244         TP_PROTO(struct bch_fs *c),
245         TP_ARGS(c)
246 );
247
248 TRACE_EVENT(btree_reserve_get_fail,
249         TP_PROTO(struct bch_fs *c, size_t required, struct closure *cl),
250         TP_ARGS(c, required, cl),
251
252         TP_STRUCT__entry(
253                 __array(char,                   uuid,   16      )
254                 __field(size_t,                 required        )
255                 __field(struct closure *,       cl              )
256         ),
257
258         TP_fast_assign(
259                 memcpy(__entry->uuid, c->sb.user_uuid.b, 16);
260                 __entry->required = required;
261                 __entry->cl = cl;
262         ),
263
264         TP_printk("%pU required %zu by %p", __entry->uuid,
265                   __entry->required, __entry->cl)
266 );
267
268 TRACE_EVENT(btree_insert_key,
269         TP_PROTO(struct bch_fs *c, struct btree *b, struct bkey_i *k),
270         TP_ARGS(c, b, k),
271
272         TP_STRUCT__entry(
273                 __field(u8,             id                      )
274                 __field(u64,            inode                   )
275                 __field(u64,            offset                  )
276                 __field(u32,            size                    )
277         ),
278
279         TP_fast_assign(
280                 __entry->id             = b->btree_id;
281                 __entry->inode          = k->k.p.inode;
282                 __entry->offset         = k->k.p.offset;
283                 __entry->size           = k->k.size;
284         ),
285
286         TP_printk("btree %u: %llu:%llu len %u", __entry->id,
287                   __entry->inode, __entry->offset, __entry->size)
288 );
289
290 DEFINE_EVENT(btree_node, btree_split,
291         TP_PROTO(struct bch_fs *c, struct btree *b),
292         TP_ARGS(c, b)
293 );
294
295 DEFINE_EVENT(btree_node, btree_compact,
296         TP_PROTO(struct bch_fs *c, struct btree *b),
297         TP_ARGS(c, b)
298 );
299
300 DEFINE_EVENT(btree_node, btree_merge,
301         TP_PROTO(struct bch_fs *c, struct btree *b),
302         TP_ARGS(c, b)
303 );
304
305 DEFINE_EVENT(btree_node, btree_set_root,
306         TP_PROTO(struct bch_fs *c, struct btree *b),
307         TP_ARGS(c, b)
308 );
309
310 /* Garbage collection */
311
312 DEFINE_EVENT(btree_node, btree_gc_coalesce,
313         TP_PROTO(struct bch_fs *c, struct btree *b),
314         TP_ARGS(c, b)
315 );
316
317 TRACE_EVENT(btree_gc_coalesce_fail,
318         TP_PROTO(struct bch_fs *c, int reason),
319         TP_ARGS(c, reason),
320
321         TP_STRUCT__entry(
322                 __field(u8,             reason                  )
323                 __array(char,           uuid,   16              )
324         ),
325
326         TP_fast_assign(
327                 __entry->reason         = reason;
328                 memcpy(__entry->uuid, c->disk_sb.sb->user_uuid.b, 16);
329         ),
330
331         TP_printk("%pU: %u", __entry->uuid, __entry->reason)
332 );
333
334 DEFINE_EVENT(btree_node, btree_gc_rewrite_node,
335         TP_PROTO(struct bch_fs *c, struct btree *b),
336         TP_ARGS(c, b)
337 );
338
339 DEFINE_EVENT(btree_node, btree_gc_rewrite_node_fail,
340         TP_PROTO(struct bch_fs *c, struct btree *b),
341         TP_ARGS(c, b)
342 );
343
344 DEFINE_EVENT(bch_fs, gc_start,
345         TP_PROTO(struct bch_fs *c),
346         TP_ARGS(c)
347 );
348
349 DEFINE_EVENT(bch_fs, gc_end,
350         TP_PROTO(struct bch_fs *c),
351         TP_ARGS(c)
352 );
353
354 DEFINE_EVENT(bch_fs, gc_coalesce_start,
355         TP_PROTO(struct bch_fs *c),
356         TP_ARGS(c)
357 );
358
359 DEFINE_EVENT(bch_fs, gc_coalesce_end,
360         TP_PROTO(struct bch_fs *c),
361         TP_ARGS(c)
362 );
363
364 DEFINE_EVENT(bch_dev, sectors_saturated,
365         TP_PROTO(struct bch_dev *ca),
366         TP_ARGS(ca)
367 );
368
369 DEFINE_EVENT(bch_fs, gc_sectors_saturated,
370         TP_PROTO(struct bch_fs *c),
371         TP_ARGS(c)
372 );
373
374 DEFINE_EVENT(bch_fs, gc_cannot_inc_gens,
375         TP_PROTO(struct bch_fs *c),
376         TP_ARGS(c)
377 );
378
379 /* Allocator */
380
381 TRACE_EVENT(alloc_batch,
382         TP_PROTO(struct bch_dev *ca, size_t free, size_t total),
383         TP_ARGS(ca, free, total),
384
385         TP_STRUCT__entry(
386                 __array(char,           uuid,   16      )
387                 __field(size_t,         free            )
388                 __field(size_t,         total           )
389         ),
390
391         TP_fast_assign(
392                 memcpy(__entry->uuid, ca->uuid.b, 16);
393                 __entry->free = free;
394                 __entry->total = total;
395         ),
396
397         TP_printk("%pU free %zu total %zu",
398                 __entry->uuid, __entry->free, __entry->total)
399 );
400
401 TRACE_EVENT(invalidate,
402         TP_PROTO(struct bch_dev *ca, u64 offset, unsigned sectors),
403         TP_ARGS(ca, offset, sectors),
404
405         TP_STRUCT__entry(
406                 __field(unsigned,       sectors                 )
407                 __field(dev_t,          dev                     )
408                 __field(__u64,          offset                  )
409         ),
410
411         TP_fast_assign(
412                 __entry->dev            = ca->disk_sb.bdev->bd_dev;
413                 __entry->offset         = offset,
414                 __entry->sectors        = sectors;
415         ),
416
417         TP_printk("invalidated %u sectors at %d,%d sector=%llu",
418                   __entry->sectors, MAJOR(__entry->dev),
419                   MINOR(__entry->dev), __entry->offset)
420 );
421
422 DEFINE_EVENT(bch_fs, rescale_prios,
423         TP_PROTO(struct bch_fs *c),
424         TP_ARGS(c)
425 );
426
427 DECLARE_EVENT_CLASS(bucket_alloc,
428         TP_PROTO(struct bch_dev *ca, enum alloc_reserve reserve),
429         TP_ARGS(ca, reserve),
430
431         TP_STRUCT__entry(
432                 __array(char,                   uuid,   16)
433                 __field(enum alloc_reserve,     reserve   )
434         ),
435
436         TP_fast_assign(
437                 memcpy(__entry->uuid, ca->uuid.b, 16);
438                 __entry->reserve = reserve;
439         ),
440
441         TP_printk("%pU reserve %d", __entry->uuid, __entry->reserve)
442 );
443
444 DEFINE_EVENT(bucket_alloc, bucket_alloc,
445         TP_PROTO(struct bch_dev *ca, enum alloc_reserve reserve),
446         TP_ARGS(ca, reserve)
447 );
448
449 DEFINE_EVENT(bucket_alloc, bucket_alloc_fail,
450         TP_PROTO(struct bch_dev *ca, enum alloc_reserve reserve),
451         TP_ARGS(ca, reserve)
452 );
453
454 DEFINE_EVENT(bucket_alloc, open_bucket_alloc_fail,
455         TP_PROTO(struct bch_dev *ca, enum alloc_reserve reserve),
456         TP_ARGS(ca, reserve)
457 );
458
459 /* Moving IO */
460
461 DEFINE_EVENT(bkey, move_extent,
462         TP_PROTO(const struct bkey *k),
463         TP_ARGS(k)
464 );
465
466 DEFINE_EVENT(bkey, move_alloc_fail,
467         TP_PROTO(const struct bkey *k),
468         TP_ARGS(k)
469 );
470
471 DEFINE_EVENT(bkey, move_race,
472         TP_PROTO(const struct bkey *k),
473         TP_ARGS(k)
474 );
475
476 TRACE_EVENT(move_data,
477         TP_PROTO(struct bch_fs *c, u64 sectors_moved,
478                  u64 keys_moved),
479         TP_ARGS(c, sectors_moved, keys_moved),
480
481         TP_STRUCT__entry(
482                 __array(char,           uuid,   16      )
483                 __field(u64,            sectors_moved   )
484                 __field(u64,            keys_moved      )
485         ),
486
487         TP_fast_assign(
488                 memcpy(__entry->uuid, c->sb.user_uuid.b, 16);
489                 __entry->sectors_moved = sectors_moved;
490                 __entry->keys_moved = keys_moved;
491         ),
492
493         TP_printk("%pU sectors_moved %llu keys_moved %llu",
494                 __entry->uuid, __entry->sectors_moved, __entry->keys_moved)
495 );
496
497 TRACE_EVENT(copygc,
498         TP_PROTO(struct bch_dev *ca,
499                  u64 sectors_moved, u64 sectors_not_moved,
500                  u64 buckets_moved, u64 buckets_not_moved),
501         TP_ARGS(ca,
502                 sectors_moved, sectors_not_moved,
503                 buckets_moved, buckets_not_moved),
504
505         TP_STRUCT__entry(
506                 __array(char,           uuid,   16              )
507                 __field(u64,            sectors_moved           )
508                 __field(u64,            sectors_not_moved       )
509                 __field(u64,            buckets_moved           )
510                 __field(u64,            buckets_not_moved       )
511         ),
512
513         TP_fast_assign(
514                 memcpy(__entry->uuid, ca->uuid.b, 16);
515                 __entry->sectors_moved          = sectors_moved;
516                 __entry->sectors_not_moved      = sectors_not_moved;
517                 __entry->buckets_moved          = buckets_moved;
518                 __entry->buckets_not_moved = buckets_moved;
519         ),
520
521         TP_printk("%pU sectors moved %llu remain %llu buckets moved %llu remain %llu",
522                 __entry->uuid,
523                 __entry->sectors_moved, __entry->sectors_not_moved,
524                 __entry->buckets_moved, __entry->buckets_not_moved)
525 );
526
527 #endif /* _TRACE_BCACHEFS_H */
528
529 /* This part must be outside protection */
530 #undef TRACE_INCLUDE_PATH
531 #define TRACE_INCLUDE_PATH ../../fs/bcachefs
532
533 #undef TRACE_INCLUDE_FILE
534 #define TRACE_INCLUDE_FILE trace
535
536 #include <trace/define_trace.h>