tracer: Use GST_TIME_ARGS when printing with GST_TIME_FORMAT.
[platform/upstream/gstreamer.git] / plugins / tracers / gstlog.c
1 /* GStreamer
2  * Copyright (C) 2013 Stefan Sauer <ensonic@users.sf.net>
3  *
4  * gstlog.c: tracing module that logs events
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  */
21 /**
22  * SECTION:gstlog
23  * @short_description: log hook event
24  *
25  * A tracing module that logs all data from all hooks. 
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #  include "config.h"
30 #endif
31
32 #include "gstlog.h"
33
34 #include <gst/printf/printf.h>
35
36 GST_DEBUG_CATEGORY_STATIC (gst_log_debug);
37 #define GST_CAT_DEFAULT gst_log_debug
38 GST_DEBUG_CATEGORY_STATIC (GST_CAT_BUFFER);
39 GST_DEBUG_CATEGORY_STATIC (GST_CAT_BUFFER_LIST);
40 GST_DEBUG_CATEGORY_STATIC (GST_CAT_EVENT);
41 GST_DEBUG_CATEGORY_STATIC (GST_CAT_MESSAGE);
42 GST_DEBUG_CATEGORY_STATIC (GST_CAT_QUERY);
43
44 #define _do_init \
45     GST_DEBUG_CATEGORY_INIT (gst_log_debug, "log", 0, "log tracer"); \
46     GST_DEBUG_CATEGORY_GET (GST_CAT_BUFFER, "GST_BUFFER"); \
47     GST_DEBUG_CATEGORY_GET (GST_CAT_BUFFER_LIST, "GST_BUFFER_LIST"); \
48     GST_DEBUG_CATEGORY_GET (GST_CAT_EVENT, "GST_EVENT"); \
49     GST_DEBUG_CATEGORY_GET (GST_CAT_MESSAGE, "GST_MESSAGE"); \
50     GST_DEBUG_CATEGORY_GET (GST_CAT_QUERY, "query");
51 #define gst_log_tracer_parent_class parent_class
52 G_DEFINE_TYPE_WITH_CODE (GstLogTracer, gst_log_tracer, GST_TYPE_TRACER,
53     _do_init);
54
55 static void
56 do_log (GstDebugCategory * cat, const char *fmt, ...)
57 {
58   va_list var_args;
59
60   va_start (var_args, fmt);
61   gst_debug_log_valist (cat, GST_LEVEL_TRACE, "", "", 0, NULL, fmt, var_args);
62   va_end (var_args);
63 }
64
65 static void
66 do_push_buffer_pre (GstTracer * self, guint64 ts, GstPad * pad,
67     GstBuffer * buffer)
68 {
69   do_log (GST_CAT_BUFFER,
70       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", buffer=%" GST_PTR_FORMAT,
71       GST_TIME_ARGS (ts), pad, buffer);
72 }
73
74 static void
75 do_push_buffer_post (GstTracer * self, guint64 ts, GstPad * pad,
76     GstFlowReturn res)
77 {
78   do_log (GST_CAT_BUFFER,
79       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", res=%d",
80       GST_TIME_ARGS (ts), pad, res);
81 }
82
83 static void
84 do_push_buffer_list_pre (GstTracer * self, guint64 ts, GstPad * pad,
85     GstBufferList * list)
86 {
87   do_log (GST_CAT_BUFFER_LIST,
88       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", list=%p",
89       GST_TIME_ARGS (ts), pad, list);
90 }
91
92 static void
93 do_push_buffer_list_post (GstTracer * self, guint64 ts, GstPad * pad,
94     GstFlowReturn res)
95 {
96   do_log (GST_CAT_BUFFER_LIST,
97       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", res=%d",
98       GST_TIME_ARGS (ts), pad, res);
99 }
100
101 static void
102 do_pull_range_pre (GstTracer * self, guint64 ts, GstPad * pad, guint64 offset,
103     guint size)
104 {
105   do_log (GST_CAT_BUFFER,
106       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", offset=%" G_GUINT64_FORMAT
107       ", size=%u", GST_TIME_ARGS (ts), pad, offset, size);
108 }
109
110 static void
111 do_pull_range_post (GstTracer * self, guint64 ts, GstPad * pad,
112     GstBuffer * buffer, GstFlowReturn res)
113 {
114   do_log (GST_CAT_BUFFER,
115       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", buffer=%" GST_PTR_FORMAT
116       ", res=%d", GST_TIME_ARGS (ts), pad, buffer, res);
117 }
118
119 static void
120 do_push_event_pre (GstTracer * self, guint64 ts, GstPad * pad, GstEvent * event)
121 {
122   do_log (GST_CAT_EVENT,
123       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", event=%" GST_PTR_FORMAT,
124       GST_TIME_ARGS (ts), pad, event);
125 }
126
127 static void
128 do_push_event_post (GstTracer * self, guint64 ts, GstPad * pad, gboolean res)
129 {
130   do_log (GST_CAT_EVENT,
131       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", res=%d",
132       GST_TIME_ARGS (ts), pad, res);
133 }
134
135 static void
136 do_post_message_pre (GstTracer * self, guint64 ts, GstElement * elem,
137     GstMessage * msg)
138 {
139   do_log (GST_CAT_EVENT,
140       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT ", message=%"
141       GST_PTR_FORMAT, GST_TIME_ARGS (ts), elem, msg);
142 }
143
144 static void
145 do_post_message_post (GstTracer * self, guint64 ts, GstElement * elem,
146     gboolean res)
147 {
148   do_log (GST_CAT_EVENT,
149       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT ", res=%d",
150       GST_TIME_ARGS (ts), elem, res);
151 }
152
153 static void
154 do_query_pre (GstTracer * self, guint64 ts, GstElement * elem, GstQuery * query)
155 {
156   do_log (GST_CAT_QUERY,
157       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT ", query=%"
158       GST_PTR_FORMAT, GST_TIME_ARGS (ts), elem, query);
159 }
160
161 static void
162 do_query_post (GstTracer * self, guint64 ts, GstElement * elem, gboolean res)
163 {
164   do_log (GST_CAT_QUERY,
165       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT ", res=%d",
166       GST_TIME_ARGS (ts), elem, res);
167 }
168
169
170 /* tracer class */
171
172 static void
173 gst_log_tracer_class_init (GstLogTracerClass * klass)
174 {
175 }
176
177 static void
178 gst_log_tracer_init (GstLogTracer * self)
179 {
180   GstTracer *tracer = GST_TRACER (self);
181
182   gst_tracing_register_hook (tracer, "pad-push-pre",
183       G_CALLBACK (do_push_buffer_pre));
184   gst_tracing_register_hook (tracer, "pad-push-post",
185       G_CALLBACK (do_push_buffer_post));
186   gst_tracing_register_hook (tracer, "pad-push-list-pre",
187       G_CALLBACK (do_push_buffer_list_pre));
188   gst_tracing_register_hook (tracer, "pad-push-list-post",
189       G_CALLBACK (do_push_buffer_list_post));
190   gst_tracing_register_hook (tracer, "pad-pull-range-pre",
191       G_CALLBACK (do_pull_range_pre));
192   gst_tracing_register_hook (tracer, "pad-pull-range-post",
193       G_CALLBACK (do_pull_range_post));
194   gst_tracing_register_hook (tracer, "pad-push-event-pre",
195       G_CALLBACK (do_push_event_pre));
196   gst_tracing_register_hook (tracer, "pad-push-event-post",
197       G_CALLBACK (do_push_event_post));
198   gst_tracing_register_hook (tracer, "element-post-message-pre",
199       G_CALLBACK (do_post_message_pre));
200   gst_tracing_register_hook (tracer, "element-post-message-post",
201       G_CALLBACK (do_post_message_post));
202   gst_tracing_register_hook (tracer, "element-query-pre",
203       G_CALLBACK (do_query_pre));
204   gst_tracing_register_hook (tracer, "element-query-post",
205       G_CALLBACK (do_query_post));
206 }