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_LIVE: Trace number of non-freed memory
34 * @GST_ALLOC_TRACE_MEM_LIVE: trace pointers of unfreed memory
36 * Flags indicating which tracing feature to enable.
39 GST_ALLOC_TRACE_LIVE = (1 << 0),
40 GST_ALLOC_TRACE_MEM_LIVE = (1 << 1)
43 typedef struct _GstAllocTrace GstAllocTrace;
47 * @name: The name of the tracing object
48 * @flags: Flags for this object
49 * @live: counter for live memory
50 * @mem_live: list with pointers to unfreed memory
52 * The main tracing object
54 struct _GstAllocTrace {
62 #ifndef GST_DISABLE_TRACE
64 typedef struct _GstTrace GstTrace;
65 typedef struct _GstTraceEntry GstTraceEntry;
70 * Opaque #GstTrace structure.
74 /* where this trace is going */
78 /* current buffer, size, head offset */
84 struct _GstTraceEntry {
91 GstTrace* gst_trace_new (const gchar *filename, gint size);
93 void gst_trace_destroy (GstTrace *trace);
94 void gst_trace_flush (GstTrace *trace);
95 void gst_trace_text_flush (GstTrace *trace);
100 * Retrieve the buffer size of @trace.
102 #define gst_trace_get_size(trace) ((trace)->bufsize)
104 * gst_trace_get_offset:
105 * @trace: a #GstTrace
107 * Retrieve the current buffer offset of @trace.
109 #define gst_trace_get_offset(trace) ((trace)->bufoffset)
111 * gst_trace_get_remaining:
112 * @trace: a #GstTrace
114 * Retrieve the remaining size in the @trace buffer.
116 #define gst_trace_get_remaining(trace) ((trace)->bufsize - (trace)->bufoffset)
117 void gst_trace_set_default (GstTrace *trace);
119 void _gst_trace_add_entry (GstTrace *trace, guint32 seq,
120 guint32 data, gchar *msg);
122 void gst_trace_read_tsc (gint64 *dst);
125 extern GStaticMutex _gst_trace_mutex;
127 gboolean gst_alloc_trace_available (void);
128 G_CONST_RETURN GList* gst_alloc_trace_list (void);
129 GstAllocTrace* _gst_alloc_trace_register (const gchar *name);
131 int gst_alloc_trace_live_all (void);
132 void gst_alloc_trace_print_all (void);
133 void gst_alloc_trace_print_live (void);
134 void gst_alloc_trace_set_flags_all (GstAllocTraceFlags flags);
136 GstAllocTrace* gst_alloc_trace_get (const gchar *name);
137 void gst_alloc_trace_print (const GstAllocTrace *trace);
138 void gst_alloc_trace_set_flags (GstAllocTrace *trace, GstAllocTraceFlags flags);
141 #ifndef GST_DISABLE_ALLOC_TRACE
143 * gst_alloc_trace_register:
144 * @name: The name of the tracer object
146 * Register a new alloc tracer with the given name
148 #define gst_alloc_trace_register(name) _gst_alloc_trace_register (name);
151 * gst_alloc_trace_new:
152 * @trace: The tracer to use
153 * @mem: The memory allocated
155 * Use the tracer to trace a new memory allocation
157 #define gst_alloc_trace_new(trace, mem) \
159 if (G_UNLIKELY ((trace)->flags)) { \
160 g_static_mutex_lock (&_gst_trace_mutex); \
161 if ((trace)->flags & GST_ALLOC_TRACE_LIVE) \
163 if ((trace)->flags & GST_ALLOC_TRACE_MEM_LIVE) \
164 (trace)->mem_live = \
165 g_slist_prepend ((trace)->mem_live, mem); \
166 g_static_mutex_unlock (&_gst_trace_mutex); \
171 * gst_alloc_trace_free:
172 * @trace: The tracer to use
173 * @mem: The memory that is freed
175 * Trace a memory free operation
177 #define gst_alloc_trace_free(trace, mem) \
179 if (G_UNLIKELY ((trace)->flags)) { \
180 g_static_mutex_lock (&_gst_trace_mutex); \
181 if ((trace)->flags & GST_ALLOC_TRACE_LIVE) \
183 if ((trace)->flags & GST_ALLOC_TRACE_MEM_LIVE) \
184 (trace)->mem_live = \
185 g_slist_remove ((trace)->mem_live, mem); \
186 g_static_mutex_unlock (&_gst_trace_mutex); \
191 #define gst_alloc_trace_register(name) (NULL)
192 #define gst_alloc_trace_new(trace, mem)
193 #define gst_alloc_trace_free(trace, mem)
197 extern gint _gst_trace_on;
199 * gst_trace_add_entry:
200 * @trace: a #GstTrace
201 * @seq: a sequence number
202 * @data: the data to trace
203 * @msg: the trace message
205 * Add an entry to @trace with sequence number @seq, @data and @msg.
206 * If @trace is NULL, the entry will be added to the default #GstTrace.
208 #define gst_trace_add_entry(trace,seq,data,msg) \
209 if (_gst_trace_on) { \
210 _gst_trace_add_entry(trace,(guint32)seq,(guint32)data,msg); \
213 #else /* GST_DISABLE_TRACE */
215 #if defined __GNUC__ && __GNUC__ >= 3
216 #pragma GCC poison gst_trace_new
217 #pragma GCC poison gst_trace_destroy
218 #pragma GCC poison gst_trace_flush
219 #pragma GCC poison gst_trace_text_flush
220 #pragma GCC poison gst_trace_get_size
221 #pragma GCC poison gst_trace_get_offset
222 #pragma GCC poison gst_trace_get_remaining
223 #pragma GCC poison gst_trace_set_default
224 #pragma GCC poison _gst_trace_add_entry
225 #pragma GCC poison gst_trace_read_tsc
228 #define gst_alloc_trace_register(name) (NULL)
229 #define gst_alloc_trace_new(trace, mem)
230 #define gst_alloc_trace_free(trace, mem)
232 #define gst_alloc_trace_available() (FALSE)
233 #define gst_alloc_trace_list() (NULL)
234 #define _gst_alloc_trace_register(name) (NULL)
236 #define gst_alloc_trace_live_all() (0)
237 #define gst_alloc_trace_print_all()
238 #define gst_alloc_trace_print_live()
239 #define gst_alloc_trace_set_flags_all(flags)
241 #define gst_alloc_trace_get(name) (NULL)
242 #define gst_alloc_trace_print(trace)
243 #define gst_alloc_trace_set_flags(trace,flags)
245 #define gst_trace_add_entry(trace,seq,data,msg)
247 #endif /* GST_DISABLE_TRACE */
251 #endif /* __GST_TRACE_H__ */