Automatic update of common submodule
[platform/upstream/gstreamer.git] / gst / gsttrace.h
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gsttrace.h: Header for tracing functions (deprecated)
6  *
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.
11  *
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.
16  *
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.
21  */
22
23
24 #ifndef __GST_TRACE_H__
25 #define __GST_TRACE_H__
26
27 #include <glib.h>
28
29 G_BEGIN_DECLS
30
31 /**
32  * GstAllocTraceFlags:
33  * @GST_ALLOC_TRACE_LIVE: Trace number of non-freed memory
34  * @GST_ALLOC_TRACE_MEM_LIVE: trace pointers of unfreed memory
35  *
36  * Flags indicating which tracing feature to enable.
37  */
38 typedef enum {
39   GST_ALLOC_TRACE_LIVE          = (1 << 0),
40   GST_ALLOC_TRACE_MEM_LIVE      = (1 << 1)
41 } GstAllocTraceFlags;
42
43 typedef struct _GstAllocTrace   GstAllocTrace;
44
45 /**
46  * 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
51  *
52  * The main tracing object
53  */
54 struct _GstAllocTrace {
55   gchar         *name;
56   gint           flags;
57
58   gint           live;
59   GSList        *mem_live;
60 };
61
62 #ifndef GST_DISABLE_TRACE
63
64 typedef struct _GstTrace        GstTrace;
65 typedef struct _GstTraceEntry   GstTraceEntry;
66
67 /**
68  * GstTrace:
69  *
70  * Opaque #GstTrace structure.
71  */
72 struct _GstTrace {
73   /*< private >*/
74   /* where this trace is going */
75   gchar *filename;
76   int fd;
77
78   /* current buffer, size, head offset */
79   GstTraceEntry *buf;
80   gint bufsize;
81   gint bufoffset;
82 };
83
84 struct _GstTraceEntry {
85   gint64 timestamp;
86   guint32 sequence;
87   guint32 data;
88   gchar message[112];
89 };
90
91 GstTrace*       gst_trace_new                   (const gchar *filename, gint size);
92
93 void            gst_trace_destroy               (GstTrace *trace);
94 void            gst_trace_flush                 (GstTrace *trace);
95 void            gst_trace_text_flush            (GstTrace *trace);
96 /**
97  * gst_trace_get_size:
98  * @trace: a #GstTrace
99  *
100  * Retrieve the buffer size of @trace.
101  */
102 #define         gst_trace_get_size(trace)       ((trace)->bufsize)
103 /**
104  * gst_trace_get_offset:
105  * @trace: a #GstTrace
106  *
107  * Retrieve the current buffer offset of @trace.
108  */
109 #define         gst_trace_get_offset(trace)     ((trace)->bufoffset)
110 /**
111  * gst_trace_get_remaining:
112  * @trace: a #GstTrace
113  *
114  * Retrieve the remaining size in the @trace buffer.
115  */
116 #define         gst_trace_get_remaining(trace)  ((trace)->bufsize - (trace)->bufoffset)
117 void            gst_trace_set_default           (GstTrace *trace);
118
119 void            _gst_trace_add_entry            (GstTrace *trace, guint32 seq,
120                                                  guint32 data, gchar *msg);
121
122 void            gst_trace_read_tsc              (gint64 *dst);
123
124
125 extern GStaticMutex     _gst_trace_mutex;
126
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);
130
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);
135
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);
139
140
141 #ifndef GST_DISABLE_ALLOC_TRACE
142 /**
143  * gst_alloc_trace_register:
144  * @name: The name of the tracer object
145  *
146  * Register a new alloc tracer with the given name
147  */
148 #define gst_alloc_trace_register(name) _gst_alloc_trace_register (name);
149
150 /**
151  * gst_alloc_trace_new:
152  * @trace: The tracer to use
153  * @mem: The memory allocated
154  *
155  * Use the tracer to trace a new memory allocation
156  */
157 #define gst_alloc_trace_new(trace, mem)                 \
158 G_STMT_START {                                          \
159   if (G_UNLIKELY ((trace)->flags)) {                    \
160     g_static_mutex_lock (&_gst_trace_mutex);            \
161     if ((trace)->flags & GST_ALLOC_TRACE_LIVE)          \
162       (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);          \
167   }                                                     \
168 } G_STMT_END
169
170 /**
171  * gst_alloc_trace_free:
172  * @trace: The tracer to use
173  * @mem: The memory that is freed
174  *
175  * Trace a memory free operation
176  */
177 #define gst_alloc_trace_free(trace, mem)                \
178 G_STMT_START {                                          \
179   if (G_UNLIKELY ((trace)->flags)) {                    \
180     g_static_mutex_lock (&_gst_trace_mutex);            \
181     if ((trace)->flags & GST_ALLOC_TRACE_LIVE)          \
182       (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);          \
187   }                                                     \
188 } G_STMT_END
189
190 #else
191 #define gst_alloc_trace_register(name) (NULL)
192 #define gst_alloc_trace_new(trace, mem)
193 #define gst_alloc_trace_free(trace, mem)
194 #endif
195
196
197 extern gint _gst_trace_on;
198 /**
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
204  *
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.
207  */
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); \
211   }
212
213 #else /* GST_DISABLE_TRACE */
214
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
226 #endif
227
228 #define         gst_alloc_trace_register(name)  (NULL)
229 #define         gst_alloc_trace_new(trace, mem)
230 #define         gst_alloc_trace_free(trace, mem)
231
232 #define         gst_alloc_trace_available()     (FALSE)
233 #define         gst_alloc_trace_list()          (NULL)
234 #define         _gst_alloc_trace_register(name) (NULL)
235
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)
240
241 #define         gst_alloc_trace_get(name)       (NULL)
242 #define         gst_alloc_trace_print(trace)
243 #define         gst_alloc_trace_set_flags(trace,flags)
244
245 #define         gst_trace_add_entry(trace,seq,data,msg)
246
247 #endif /* GST_DISABLE_TRACE */
248
249 G_END_DECLS
250
251 #endif /* __GST_TRACE_H__ */