2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wtay@chello.be>
5 * gsttrace.h: Header for tracing functions (deprecated)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 #ifndef __GST_TRACE_H__
25 #define __GST_TRACE_H__
33 * @GST_ALLOC_TRACE_NONE: No tracing specified or desired. Since 0.10.36.
34 * @GST_ALLOC_TRACE_LIVE: Trace number of non-freed memory.
35 * @GST_ALLOC_TRACE_MEM_LIVE: Trace pointers of unfreed memory.
37 * Flags indicating which tracing feature to enable.
40 GST_ALLOC_TRACE_NONE = 0,
41 GST_ALLOC_TRACE_LIVE = (1 << 0),
42 GST_ALLOC_TRACE_MEM_LIVE = (1 << 1)
45 typedef struct _GstAllocTrace GstAllocTrace;
49 * @name: The name of the tracing object
50 * @flags: Flags for this object
51 * @live: counter for live memory
52 * @mem_live: list with pointers to unfreed memory
54 * The main tracing object
56 struct _GstAllocTrace {
64 #ifndef GST_DISABLE_TRACE
66 typedef struct _GstTrace GstTrace;
67 typedef struct _GstTraceEntry GstTraceEntry;
72 * Opaque #GstTrace structure.
76 /* where this trace is going */
80 /* current buffer, size, head offset */
86 struct _GstTraceEntry {
93 GstTrace* gst_trace_new (const gchar *filename, gint size);
95 void gst_trace_destroy (GstTrace *trace);
96 void gst_trace_flush (GstTrace *trace);
97 void gst_trace_text_flush (GstTrace *trace);
100 * @trace: a #GstTrace
102 * Retrieve the buffer size of @trace.
104 #define gst_trace_get_size(trace) ((trace)->bufsize)
106 * gst_trace_get_offset:
107 * @trace: a #GstTrace
109 * Retrieve the current buffer offset of @trace.
111 #define gst_trace_get_offset(trace) ((trace)->bufoffset)
113 * gst_trace_get_remaining:
114 * @trace: a #GstTrace
116 * Retrieve the remaining size in the @trace buffer.
118 #define gst_trace_get_remaining(trace) ((trace)->bufsize - (trace)->bufoffset)
119 void gst_trace_set_default (GstTrace *trace);
121 void _gst_trace_add_entry (GstTrace *trace, guint32 seq,
122 guint32 data, gchar *msg);
124 void gst_trace_read_tsc (gint64 *dst);
127 GST_EXPORT GStaticMutex _gst_trace_mutex;
129 gboolean gst_alloc_trace_available (void);
130 const GList* gst_alloc_trace_list (void);
131 GstAllocTrace* _gst_alloc_trace_register (const gchar *name);
133 int gst_alloc_trace_live_all (void);
134 void gst_alloc_trace_print_all (void);
135 void gst_alloc_trace_print_live (void);
136 void gst_alloc_trace_set_flags_all (GstAllocTraceFlags flags);
138 GstAllocTrace* gst_alloc_trace_get (const gchar *name);
139 void gst_alloc_trace_print (const GstAllocTrace *trace);
140 void gst_alloc_trace_set_flags (GstAllocTrace *trace, GstAllocTraceFlags flags);
143 #ifndef GST_DISABLE_ALLOC_TRACE
145 * gst_alloc_trace_register:
146 * @name: The name of the tracer object
148 * Register a new alloc tracer with the given name
150 #define gst_alloc_trace_register(name) _gst_alloc_trace_register (name);
153 * gst_alloc_trace_new:
154 * @trace: The tracer to use
155 * @mem: The memory allocated
157 * Use the tracer to trace a new memory allocation
159 #define gst_alloc_trace_new(trace, mem) \
161 if (G_UNLIKELY ((trace)->flags)) { \
162 g_static_mutex_lock (&_gst_trace_mutex); \
163 if ((trace)->flags & GST_ALLOC_TRACE_LIVE) \
165 if ((trace)->flags & GST_ALLOC_TRACE_MEM_LIVE) \
166 (trace)->mem_live = \
167 g_slist_prepend ((trace)->mem_live, mem); \
168 g_static_mutex_unlock (&_gst_trace_mutex); \
173 * gst_alloc_trace_free:
174 * @trace: The tracer to use
175 * @mem: The memory that is freed
177 * Trace a memory free operation
179 #define gst_alloc_trace_free(trace, mem) \
181 if (G_UNLIKELY ((trace)->flags)) { \
182 g_static_mutex_lock (&_gst_trace_mutex); \
183 if ((trace)->flags & GST_ALLOC_TRACE_LIVE) \
185 if ((trace)->flags & GST_ALLOC_TRACE_MEM_LIVE) \
186 (trace)->mem_live = \
187 g_slist_remove ((trace)->mem_live, mem); \
188 g_static_mutex_unlock (&_gst_trace_mutex); \
193 #define gst_alloc_trace_register(name) (NULL)
194 #define gst_alloc_trace_new(trace, mem)
195 #define gst_alloc_trace_free(trace, mem)
199 GST_EXPORT gint _gst_trace_on;
201 * gst_trace_add_entry:
202 * @trace: a #GstTrace
203 * @seq: a sequence number
204 * @data: the data to trace
205 * @msg: the trace message
207 * Add an entry to @trace with sequence number @seq, @data and @msg.
208 * If @trace is NULL, the entry will be added to the default #GstTrace.
210 #define gst_trace_add_entry(trace,seq,data,msg) \
211 if (_gst_trace_on) { \
212 _gst_trace_add_entry(trace,(guint32)seq,(guint32)data,msg); \
215 #else /* GST_DISABLE_TRACE */
217 #if defined __GNUC__ && __GNUC__ >= 3
218 #pragma GCC poison gst_trace_new
219 #pragma GCC poison gst_trace_destroy
220 #pragma GCC poison gst_trace_flush
221 #pragma GCC poison gst_trace_text_flush
222 #pragma GCC poison gst_trace_get_size
223 #pragma GCC poison gst_trace_get_offset
224 #pragma GCC poison gst_trace_get_remaining
225 #pragma GCC poison gst_trace_set_default
226 #pragma GCC poison _gst_trace_add_entry
227 #pragma GCC poison gst_trace_read_tsc
230 #define gst_alloc_trace_register(name) (NULL)
231 #define gst_alloc_trace_new(trace, mem)
232 #define gst_alloc_trace_free(trace, mem)
234 #define gst_alloc_trace_available() (FALSE)
235 #define gst_alloc_trace_list() (NULL)
236 #define _gst_alloc_trace_register(name) (NULL)
238 #define gst_alloc_trace_live_all() (0)
239 #define gst_alloc_trace_print_all()
240 #define gst_alloc_trace_print_live()
241 #define gst_alloc_trace_set_flags_all(flags)
243 #define gst_alloc_trace_get(name) (NULL)
244 #define gst_alloc_trace_print(trace)
245 #define gst_alloc_trace_set_flags(trace,flags)
247 #define gst_trace_add_entry(trace,seq,data,msg)
249 #endif /* GST_DISABLE_TRACE */
253 #endif /* __GST_TRACE_H__ */