2 * Copyright (C) 2013 Stefan Sauer <ensonic@users.sf.net>
4 * gstlog.c: tracing module that logs events
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.
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.
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.
23 * @short_description: log hook event
25 * A tracing module that logs all data from all hooks.
34 #include <gst/printf/printf.h>
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);
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,
55 static void gst_log_tracer_invoke (GstTracer * self, GstTracerMessageId mid,
59 gst_log_tracer_class_init (GstLogTracerClass * klass)
61 GstTracerClass *gst_tracer_class = GST_TRACER_CLASS (klass);
63 gst_tracer_class->invoke = gst_log_tracer_invoke;
67 gst_log_tracer_init (GstLogTracer * self)
69 g_object_set (self, "mask", GST_TRACER_HOOK_ALL, NULL);
73 gst_log_tracer_invoke (GstTracer * self, GstTracerMessageId mid,
76 const gchar *fmt = NULL;
77 GstDebugCategory *cat = GST_CAT_DEFAULT;
78 guint64 ts = va_arg (var_args, guint64);
80 /* TODO(ensonic): log to different categories depending on 'mid'
81 * GST_TRACER_HOOK_ID_QUERIES -> (static category)
82 * GST_TRACER_HOOK_ID_TOPLOGY -> ?
85 case GST_TRACER_MESSAGE_ID_PAD_PUSH_PRE:
87 fmt = "pad=%" GST_PTR_FORMAT ", buffer=%" GST_PTR_FORMAT;
89 case GST_TRACER_MESSAGE_ID_PAD_PUSH_POST:
91 fmt = "pad=%" GST_PTR_FORMAT ", res=%d";
93 case GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_PRE:
94 cat = GST_CAT_BUFFER_LIST;
95 fmt = "pad=%" GST_PTR_FORMAT ", list=%p";
97 case GST_TRACER_MESSAGE_ID_PAD_PUSH_LIST_POST:
98 cat = GST_CAT_BUFFER_LIST;
99 fmt = "pad=%" GST_PTR_FORMAT ", res=%d";
101 case GST_TRACER_MESSAGE_ID_PAD_PULL_RANGE_PRE:
102 cat = GST_CAT_BUFFER;
103 fmt = "pad=%" GST_PTR_FORMAT ", offset=%" G_GUINT64_FORMAT ", size=%u";
105 case GST_TRACER_MESSAGE_ID_PAD_PULL_RANGE_POST:
106 cat = GST_CAT_BUFFER;
107 fmt = "pad=%" GST_PTR_FORMAT ", buffer=%" GST_PTR_FORMAT ", res=%d";
109 case GST_TRACER_MESSAGE_ID_PAD_PUSH_EVENT_PRE:
111 fmt = "pad=%" GST_PTR_FORMAT ", event=%" GST_PTR_FORMAT;
113 case GST_TRACER_MESSAGE_ID_PAD_PUSH_EVENT_POST:
115 fmt = "pad=%" GST_PTR_FORMAT ", res=%d";
117 case GST_TRACER_MESSAGE_ID_ELEMENT_POST_MESSAGE_PRE:
118 cat = GST_CAT_MESSAGE;
119 fmt = "element=%" GST_PTR_FORMAT ", message=%" GST_PTR_FORMAT;
121 case GST_TRACER_MESSAGE_ID_ELEMENT_POST_MESSAGE_POST:
122 cat = GST_CAT_MESSAGE;
123 fmt = "element=%" GST_PTR_FORMAT ", res=%d";
125 case GST_TRACER_MESSAGE_ID_ELEMENT_QUERY_PRE:
127 fmt = "element=%" GST_PTR_FORMAT ", query=%" GST_PTR_FORMAT;
129 case GST_TRACER_MESSAGE_ID_ELEMENT_QUERY_POST:
131 fmt = "element=%" GST_PTR_FORMAT ", res=%d";
139 __gst_vasprintf (&str, fmt, var_args);
140 GST_CAT_TRACE (cat, "[%d] %" GST_TIME_FORMAT ", %s",
141 mid, GST_TIME_ARGS (ts), str);
144 GST_CAT_TRACE (cat, "[%d] %" GST_TIME_FORMAT, mid, GST_TIME_ARGS (ts));