btrfs: Add trace for btrfs_workqueue alloc/destroy
authorQu Wenruo <quwenruo@cn.fujitsu.com>
Wed, 12 Mar 2014 08:05:33 +0000 (08:05 +0000)
committerChris Mason <clm@fb.com>
Fri, 21 Mar 2014 00:15:28 +0000 (17:15 -0700)
Since most of the btrfs_workqueue is printed as pointer address,
for easier analysis, add trace for btrfs_workqueue alloc/destroy.
So it is possible to determine the workqueue that a given work belongs
to(by comparing the wq pointer address with alloc trace event).

Signed-off-by: Qu Wenruo <quenruo@cn.fujitsu.com>
Signed-off-by: Chris Mason <clm@fb.com>
fs/btrfs/async-thread.c
fs/btrfs/async-thread.h
include/trace/events/btrfs.h

index 66532b8f0f7c683b4cda403f2cc3bcdf1c04ca38..ecb5832c0967e96ffcb0084435f3a37f69f0d661 100644 (file)
@@ -56,7 +56,8 @@ struct btrfs_workqueue {
 };
 
 static inline struct __btrfs_workqueue
-*__btrfs_alloc_workqueue(char *name, int flags, int max_active, int thresh)
+*__btrfs_alloc_workqueue(const char *name, int flags, int max_active,
+                        int thresh)
 {
        struct __btrfs_workqueue *ret = kzalloc(sizeof(*ret), GFP_NOFS);
 
@@ -92,13 +93,14 @@ static inline struct __btrfs_workqueue
        INIT_LIST_HEAD(&ret->ordered_list);
        spin_lock_init(&ret->list_lock);
        spin_lock_init(&ret->thres_lock);
+       trace_btrfs_workqueue_alloc(ret, name, flags & WQ_HIGHPRI);
        return ret;
 }
 
 static inline void
 __btrfs_destroy_workqueue(struct __btrfs_workqueue *wq);
 
-struct btrfs_workqueue *btrfs_alloc_workqueue(char *name,
+struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name,
                                              int flags,
                                              int max_active,
                                              int thresh)
@@ -305,6 +307,7 @@ static inline void
 __btrfs_destroy_workqueue(struct __btrfs_workqueue *wq)
 {
        destroy_workqueue(wq->normal_wq);
+       trace_btrfs_workqueue_destroy(wq);
        kfree(wq);
 }
 
index 0a891cdc4c284ac0c0a0800f1dfe1a29bd664e99..9c6b66d15fb0a07cd0a6a4656d6865848aa5c8ea 100644 (file)
@@ -38,7 +38,7 @@ struct btrfs_work {
        unsigned long flags;
 };
 
-struct btrfs_workqueue *btrfs_alloc_workqueue(char *name,
+struct btrfs_workqueue *btrfs_alloc_workqueue(const char *name,
                                              int flags,
                                              int max_active,
                                              int thresh);
index c346919254a907eff9b862057d606a13c259f1dd..4ee4e30d26d9b3a9d5bccbb51348e0b876365f26 100644 (file)
@@ -22,6 +22,7 @@ struct btrfs_free_cluster;
 struct map_lookup;
 struct extent_buffer;
 struct btrfs_work;
+struct __btrfs_workqueue;
 
 #define show_ref_type(type)                                            \
        __print_symbolic(type,                                          \
@@ -1063,6 +1064,60 @@ DEFINE_EVENT(btrfs__work, btrfs_ordered_sched,
        TP_ARGS(work)
 );
 
+DECLARE_EVENT_CLASS(btrfs__workqueue,
+
+       TP_PROTO(struct __btrfs_workqueue *wq, const char *name, int high),
+
+       TP_ARGS(wq, name, high),
+
+       TP_STRUCT__entry(
+               __field(        void *, wq                      )
+               __string(       name,   name                    )
+               __field(        int ,   high                    )
+       ),
+
+       TP_fast_assign(
+               __entry->wq             = wq;
+               __assign_str(name, name);
+               __entry->high           = high;
+       ),
+
+       TP_printk("name=%s%s, wq=%p", __get_str(name),
+                 __print_flags(__entry->high, "",
+                               {(WQ_HIGHPRI),  "-high"}),
+                 __entry->wq)
+);
+
+DEFINE_EVENT(btrfs__workqueue, btrfs_workqueue_alloc,
+
+       TP_PROTO(struct __btrfs_workqueue *wq, const char *name, int high),
+
+       TP_ARGS(wq, name, high)
+);
+
+DECLARE_EVENT_CLASS(btrfs__workqueue_done,
+
+       TP_PROTO(struct __btrfs_workqueue *wq),
+
+       TP_ARGS(wq),
+
+       TP_STRUCT__entry(
+               __field(        void *, wq                      )
+       ),
+
+       TP_fast_assign(
+               __entry->wq             = wq;
+       ),
+
+       TP_printk("wq=%p", __entry->wq)
+);
+
+DEFINE_EVENT(btrfs__workqueue_done, btrfs_workqueue_destroy,
+
+       TP_PROTO(struct __btrfs_workqueue *wq),
+
+       TP_ARGS(wq)
+);
 
 #endif /* _TRACE_BTRFS_H */