tracers: log: add missing hooks
[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_BIN);
39 GST_DEBUG_CATEGORY_STATIC (GST_CAT_BUFFER);
40 GST_DEBUG_CATEGORY_STATIC (GST_CAT_BUFFER_LIST);
41 GST_DEBUG_CATEGORY_STATIC (GST_CAT_EVENT);
42 GST_DEBUG_CATEGORY_STATIC (GST_CAT_MESSAGE);
43 GST_DEBUG_CATEGORY_STATIC (GST_CAT_QUERY);
44 GST_DEBUG_CATEGORY_STATIC (GST_CAT_STATES);
45 GST_DEBUG_CATEGORY_STATIC (GST_CAT_PADS);
46 GST_DEBUG_CATEGORY_STATIC (GST_CAT_ELEMENT_PADS);
47 GST_DEBUG_CATEGORY_STATIC (GST_CAT_ELEMENT_FACTORY);
48
49 #define _do_init \
50     GST_DEBUG_CATEGORY_INIT (gst_log_debug, "log", 0, "log tracer"); \
51     GST_DEBUG_CATEGORY_GET (GST_CAT_BUFFER, "GST_BUFFER"); \
52     GST_DEBUG_CATEGORY_GET (GST_CAT_BUFFER_LIST, "GST_BUFFER_LIST"); \
53     GST_DEBUG_CATEGORY_GET (GST_CAT_EVENT, "GST_EVENT"); \
54     GST_DEBUG_CATEGORY_GET (GST_CAT_MESSAGE, "GST_MESSAGE"); \
55     GST_DEBUG_CATEGORY_GET (GST_CAT_STATES, "GST_STATES"); \
56     GST_DEBUG_CATEGORY_GET (GST_CAT_PADS, "GST_PADS"); \
57     GST_DEBUG_CATEGORY_GET (GST_CAT_ELEMENT_PADS, "GST_ELEMENT_PADS"); \
58     GST_DEBUG_CATEGORY_GET (GST_CAT_ELEMENT_FACTORY, "GST_ELEMENT_FACTORY"); \
59     GST_DEBUG_CATEGORY_GET (GST_CAT_QUERY, "query"); \
60     GST_DEBUG_CATEGORY_GET (GST_CAT_BIN, "bin");
61 #define gst_log_tracer_parent_class parent_class
62 G_DEFINE_TYPE_WITH_CODE (GstLogTracer, gst_log_tracer, GST_TYPE_TRACER,
63     _do_init);
64
65 static void
66 do_log (GstDebugCategory * cat, const char *fmt, ...)
67 {
68   va_list var_args;
69
70   va_start (var_args, fmt);
71   gst_debug_log_valist (cat, GST_LEVEL_TRACE, "", "", 0, NULL, fmt, var_args);
72   va_end (var_args);
73 }
74
75 static void
76 do_push_buffer_pre (GstTracer * self, guint64 ts, GstPad * pad,
77     GstBuffer * buffer)
78 {
79   do_log (GST_CAT_BUFFER,
80       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", buffer=%" GST_PTR_FORMAT,
81       GST_TIME_ARGS (ts), pad, buffer);
82 }
83
84 static void
85 do_push_buffer_post (GstTracer * self, guint64 ts, GstPad * pad,
86     GstFlowReturn res)
87 {
88   do_log (GST_CAT_BUFFER,
89       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", res=%d",
90       GST_TIME_ARGS (ts), pad, res);
91 }
92
93 static void
94 do_push_buffer_list_pre (GstTracer * self, guint64 ts, GstPad * pad,
95     GstBufferList * list)
96 {
97   do_log (GST_CAT_BUFFER_LIST,
98       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", list=%p",
99       GST_TIME_ARGS (ts), pad, list);
100 }
101
102 static void
103 do_push_buffer_list_post (GstTracer * self, guint64 ts, GstPad * pad,
104     GstFlowReturn res)
105 {
106   do_log (GST_CAT_BUFFER_LIST,
107       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", res=%d",
108       GST_TIME_ARGS (ts), pad, res);
109 }
110
111 static void
112 do_pull_range_pre (GstTracer * self, guint64 ts, GstPad * pad, guint64 offset,
113     guint size)
114 {
115   do_log (GST_CAT_BUFFER,
116       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", offset=%" G_GUINT64_FORMAT
117       ", size=%u", GST_TIME_ARGS (ts), pad, offset, size);
118 }
119
120 static void
121 do_pull_range_post (GstTracer * self, guint64 ts, GstPad * pad,
122     GstBuffer * buffer, GstFlowReturn res)
123 {
124   do_log (GST_CAT_BUFFER,
125       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", buffer=%" GST_PTR_FORMAT
126       ", res=%d", GST_TIME_ARGS (ts), pad, buffer, res);
127 }
128
129 static void
130 do_push_event_pre (GstTracer * self, guint64 ts, GstPad * pad, GstEvent * event)
131 {
132   do_log (GST_CAT_EVENT,
133       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", event=%" GST_PTR_FORMAT,
134       GST_TIME_ARGS (ts), pad, event);
135 }
136
137 static void
138 do_push_event_post (GstTracer * self, guint64 ts, GstPad * pad, gboolean res)
139 {
140   do_log (GST_CAT_EVENT,
141       "%" GST_TIME_FORMAT ", pad=%" GST_PTR_FORMAT ", res=%d",
142       GST_TIME_ARGS (ts), pad, res);
143 }
144
145 static void
146 do_post_message_pre (GstTracer * self, guint64 ts, GstElement * elem,
147     GstMessage * msg)
148 {
149   do_log (GST_CAT_EVENT,
150       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT ", message=%"
151       GST_PTR_FORMAT, GST_TIME_ARGS (ts), elem, msg);
152 }
153
154 static void
155 do_post_message_post (GstTracer * self, guint64 ts, GstElement * elem,
156     gboolean res)
157 {
158   do_log (GST_CAT_EVENT,
159       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT ", res=%d",
160       GST_TIME_ARGS (ts), elem, res);
161 }
162
163 static void
164 do_query_pre (GstTracer * self, guint64 ts, GstElement * elem, GstQuery * query)
165 {
166   do_log (GST_CAT_QUERY,
167       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT ", query=%"
168       GST_PTR_FORMAT, GST_TIME_ARGS (ts), elem, query);
169 }
170
171 static void
172 do_query_post (GstTracer * self, guint64 ts, GstElement * elem, gboolean res)
173 {
174   do_log (GST_CAT_QUERY,
175       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT ", res=%d",
176       GST_TIME_ARGS (ts), elem, res);
177 }
178
179 static void
180 do_element_new (GstTracer * self, guint64 ts, GstElement * elem)
181 {
182   do_log (GST_CAT_ELEMENT_FACTORY,
183       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT,
184       GST_TIME_ARGS (ts), elem);
185 }
186
187 static void
188 do_element_add_pad (GstTracer * self, guint64 ts, GstElement * elem,
189     GstPad * pad)
190 {
191   do_log (GST_CAT_ELEMENT_PADS,
192       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT ", pad=%" GST_PTR_FORMAT,
193       GST_TIME_ARGS (ts), elem, pad);
194 }
195
196 static void
197 do_element_remove_pad (GstTracer * self, guint64 ts, GstElement * elem,
198     GstPad * pad)
199 {
200   do_log (GST_CAT_ELEMENT_PADS,
201       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT ", pad=%" GST_PTR_FORMAT,
202       GST_TIME_ARGS (ts), elem, pad);
203 }
204
205 static void
206 do_element_change_state_pre (GstTracer * self, guint64 ts, GstElement * elem,
207     GstStateChange change)
208 {
209   do_log (GST_CAT_STATES,
210       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT ", change=%d",
211       GST_TIME_ARGS (ts), elem, (gint) change);
212 }
213
214 static void
215 do_element_change_state_post (GstTracer * self, guint64 ts, GstElement * elem,
216     GstStateChange change, GstStateChangeReturn res)
217 {
218   do_log (GST_CAT_STATES,
219       "%" GST_TIME_FORMAT ", element=%" GST_PTR_FORMAT ", change=%d, res=%d",
220       GST_TIME_ARGS (ts), elem, (gint) change, (gint) res);
221 }
222
223 static void
224 do_bin_add_pre (GstTracer * self, guint64 ts, GstBin * bin, GstElement * elem)
225 {
226   do_log (GST_CAT_BIN,
227       "%" GST_TIME_FORMAT ", bin=%" GST_PTR_FORMAT ", element=%" GST_PTR_FORMAT,
228       GST_TIME_ARGS (ts), bin, elem);
229 }
230
231 static void
232 do_bin_add_post (GstTracer * self, guint64 ts, GstBin * bin, GstElement * elem,
233     gboolean res)
234 {
235   do_log (GST_CAT_BIN,
236       "%" GST_TIME_FORMAT ", bin=%" GST_PTR_FORMAT ", element=%" GST_PTR_FORMAT
237       ", res=%d", GST_TIME_ARGS (ts), bin, elem, res);
238 }
239
240 static void
241 do_bin_remove_pre (GstTracer * self, guint64 ts, GstBin * bin,
242     GstElement * elem)
243 {
244   do_log (GST_CAT_BIN,
245       "%" GST_TIME_FORMAT ", bin=%" GST_PTR_FORMAT ", element=%" GST_PTR_FORMAT,
246       GST_TIME_ARGS (ts), bin, elem);
247 }
248
249 static void
250 do_bin_remove_post (GstTracer * self, guint64 ts, GstBin * bin, gboolean res)
251 {
252   do_log (GST_CAT_BIN,
253       "%" GST_TIME_FORMAT ", bin=%" GST_PTR_FORMAT ", res=%d",
254       GST_TIME_ARGS (ts), bin, res);
255 }
256
257 static void
258 do_pad_link_pre (GstTracer * self, guint64 ts, GstPad * src, GstElement * sink)
259 {
260   do_log (GST_CAT_PADS,
261       "%" GST_TIME_FORMAT ", src=%" GST_PTR_FORMAT ", sink=%" GST_PTR_FORMAT,
262       GST_TIME_ARGS (ts), src, sink);
263 }
264
265 static void
266 do_pad_link_post (GstTracer * self, guint64 ts, GstPad * src, GstElement * sink,
267     GstPadLinkReturn res)
268 {
269   do_log (GST_CAT_PADS,
270       "%" GST_TIME_FORMAT ", src=%" GST_PTR_FORMAT ", sink=%" GST_PTR_FORMAT
271       ", res=%d", GST_TIME_ARGS (ts), src, sink, (gint) res);
272 }
273
274 static void
275 do_pad_unlink_pre (GstTracer * self, guint64 ts, GstPad * src,
276     GstElement * sink)
277 {
278   do_log (GST_CAT_PADS,
279       "%" GST_TIME_FORMAT ", src=%" GST_PTR_FORMAT ", sink=%" GST_PTR_FORMAT,
280       GST_TIME_ARGS (ts), src, sink);
281 }
282
283 static void
284 do_pad_unlink_post (GstTracer * self, guint64 ts, GstPad * src,
285     GstElement * sink, gboolean res)
286 {
287   do_log (GST_CAT_PADS,
288       "%" GST_TIME_FORMAT ", src=%" GST_PTR_FORMAT ", sink=%" GST_PTR_FORMAT
289       ", res=%d", GST_TIME_ARGS (ts), src, sink, (gint) res);
290 }
291
292 /* tracer class */
293
294 static void
295 gst_log_tracer_class_init (GstLogTracerClass * klass)
296 {
297 }
298
299 static void
300 gst_log_tracer_init (GstLogTracer * self)
301 {
302   GstTracer *tracer = GST_TRACER (self);
303
304   gst_tracing_register_hook (tracer, "pad-push-pre",
305       G_CALLBACK (do_push_buffer_pre));
306   gst_tracing_register_hook (tracer, "pad-push-post",
307       G_CALLBACK (do_push_buffer_post));
308   gst_tracing_register_hook (tracer, "pad-push-list-pre",
309       G_CALLBACK (do_push_buffer_list_pre));
310   gst_tracing_register_hook (tracer, "pad-push-list-post",
311       G_CALLBACK (do_push_buffer_list_post));
312   gst_tracing_register_hook (tracer, "pad-pull-range-pre",
313       G_CALLBACK (do_pull_range_pre));
314   gst_tracing_register_hook (tracer, "pad-pull-range-post",
315       G_CALLBACK (do_pull_range_post));
316   gst_tracing_register_hook (tracer, "pad-push-event-pre",
317       G_CALLBACK (do_push_event_pre));
318   gst_tracing_register_hook (tracer, "pad-push-event-post",
319       G_CALLBACK (do_push_event_post));
320   gst_tracing_register_hook (tracer, "pad-query-pre",
321       G_CALLBACK (do_query_pre));
322   gst_tracing_register_hook (tracer, "pad-query-post",
323       G_CALLBACK (do_query_post));
324   gst_tracing_register_hook (tracer, "element-post-message-pre",
325       G_CALLBACK (do_post_message_pre));
326   gst_tracing_register_hook (tracer, "element-post-message-post",
327       G_CALLBACK (do_post_message_post));
328   gst_tracing_register_hook (tracer, "element-query-pre",
329       G_CALLBACK (do_query_pre));
330   gst_tracing_register_hook (tracer, "element-query-post",
331       G_CALLBACK (do_query_post));
332   gst_tracing_register_hook (tracer, "element-new",
333       G_CALLBACK (do_element_new));
334   gst_tracing_register_hook (tracer, "element-add-pad",
335       G_CALLBACK (do_element_add_pad));
336   gst_tracing_register_hook (tracer, "element-remove-pad",
337       G_CALLBACK (do_element_remove_pad));
338   gst_tracing_register_hook (tracer, "element-change-state-pre",
339       G_CALLBACK (do_element_change_state_pre));
340   gst_tracing_register_hook (tracer, "element-change-state-post",
341       G_CALLBACK (do_element_change_state_post));
342   gst_tracing_register_hook (tracer, "bin-add-pre",
343       G_CALLBACK (do_bin_add_pre));
344   gst_tracing_register_hook (tracer, "bin-add-post",
345       G_CALLBACK (do_bin_add_post));
346   gst_tracing_register_hook (tracer, "bin-remove-pre",
347       G_CALLBACK (do_bin_remove_pre));
348   gst_tracing_register_hook (tracer, "bin-remove-post",
349       G_CALLBACK (do_bin_remove_post));
350   gst_tracing_register_hook (tracer, "pad-link-pre",
351       G_CALLBACK (do_pad_link_pre));
352   gst_tracing_register_hook (tracer, "pad-link-post",
353       G_CALLBACK (do_pad_link_post));
354   gst_tracing_register_hook (tracer, "pad-unlink-pre",
355       G_CALLBACK (do_pad_unlink_pre));
356   gst_tracing_register_hook (tracer, "pad-unlink-post",
357       G_CALLBACK (do_pad_unlink_post));
358 }