Basic babeltrace integration
[lttv.git] / lttv / lttv / traceset.c
1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #include <lttv/traceset.h>
24 #include <lttv/iattribute.h>
25 #include <stdio.h>
26 #include <babeltrace/context.h>
27
28 /* A trace is a sequence of events gathered in the same tracing session. The
29 events may be stored in several tracefiles in the same directory.
30 A trace set is defined when several traces are to be analyzed together,
31 possibly to study the interactions between events in the different traces.
32 */
33
34 struct _LttvTraceset {
35 char * filename;
36 GPtrArray *traces;
37 struct bt_context *context;
38 LttvAttribute *a;
39 };
40
41
42 struct _LttvTrace {
43 LttTrace *t;
44 LttvAttribute *a;
45 guint ref_count;
46 };
47
48
49 LttvTraceset *lttv_traceset_new()
50 {
51 LttvTraceset *s;
52
53 s = g_new(LttvTraceset, 1);
54 s->filename = NULL;
55 s->traces = g_ptr_array_new();
56 s->context = bt_context_create();
57 s->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
58 return s;
59 }
60
61 char * lttv_traceset_name(LttvTraceset * s)
62 {
63 return s->filename;
64 }
65
66 LttvTrace *lttv_trace_new(LttTrace *t)
67 {
68 LttvTrace *new_trace;
69
70 new_trace = g_new(LttvTrace, 1);
71 new_trace->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
72 new_trace->t = t;
73 new_trace->ref_count = 0;
74 return new_trace;
75 }
76
77
78 LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig)
79 {
80 guint i;
81 LttvTraceset *s;
82 LttvTrace * trace;
83
84 s = g_new(LttvTraceset, 1);
85 s->filename = NULL;
86 s->traces = g_ptr_array_new();
87 for(i=0;i<s_orig->traces->len;i++)
88 {
89 trace = g_ptr_array_index(s_orig->traces, i);
90 trace->ref_count++;
91
92 g_ptr_array_add(s->traces, trace);
93 }
94 s->context = s_orig->context;
95 bt_context_get(s->context);
96 s->a = LTTV_ATTRIBUTE(lttv_iattribute_deep_copy(LTTV_IATTRIBUTE(s_orig->a)));
97 return s;
98 }
99
100
101 LttvTraceset *lttv_traceset_load(const gchar *filename)
102 {
103 LttvTraceset *s = g_new(LttvTraceset,1);
104 FILE *tf;
105
106 s->filename = g_strdup(filename);
107 tf = fopen(filename,"r");
108
109 g_critical("NOT IMPLEMENTED : load traceset data from a XML file");
110
111 fclose(tf);
112 return s;
113 }
114
115 gint lttv_traceset_save(LttvTraceset *s)
116 {
117 FILE *tf;
118
119 tf = fopen(s->filename, "w");
120
121 g_critical("NOT IMPLEMENTED : save traceset data in a XML file");
122
123 fclose(tf);
124 return 0;
125 }
126
127 void lttv_traceset_destroy(LttvTraceset *s)
128 {
129 guint i;
130
131 for(i=0;i<s->traces->len;i++) {
132 LttvTrace *trace = g_ptr_array_index(s->traces, i);
133 lttv_trace_unref(trace);
134 if(lttv_trace_get_ref_number(trace) == 0)
135 lttv_trace_destroy(trace);
136 }
137 g_ptr_array_free(s->traces, TRUE);
138 bt_context_put(s->context);
139 g_object_unref(s->a);
140 g_free(s);
141 }
142
143 struct bt_context *lttv_traceset_get_context(LttvTraceset *s)
144 {
145 return s->context;
146 }
147
148 void lttv_trace_destroy(LttvTrace *t)
149 {
150 g_object_unref(t->a);
151 g_free(t);
152 }
153
154
155 void lttv_traceset_add(LttvTraceset *s, LttvTrace *t)
156 {
157 t->ref_count++;
158 g_ptr_array_add(s->traces, t);
159 }
160
161
162 unsigned lttv_traceset_number(LttvTraceset *s)
163 {
164 return s->traces->len;
165 }
166
167
168 LttvTrace *lttv_traceset_get(LttvTraceset *s, unsigned i)
169 {
170 g_assert(s->traces->len > i);
171 return ((LttvTrace *)s->traces->pdata[i]);
172 }
173
174
175 void lttv_traceset_remove(LttvTraceset *s, unsigned i)
176 {
177 LttvTrace * t;
178 g_assert(s->traces->len > i);
179 t = (LttvTrace *)s->traces->pdata[i];
180 t->ref_count--;
181 g_ptr_array_remove_index(s->traces, i);
182 }
183
184
185 /* A set of attributes is attached to each trace set, trace and tracefile
186 to store user defined data as needed. */
187
188 LttvAttribute *lttv_traceset_attribute(LttvTraceset *s)
189 {
190 return s->a;
191 }
192
193
194 LttvAttribute *lttv_trace_attribute(LttvTrace *t)
195 {
196 return t->a;
197 }
198
199
200 LttTrace *lttv_trace(LttvTrace *t)
201 {
202 return t->t;
203 }
204
205 guint lttv_trace_get_ref_number(LttvTrace * t)
206 {
207 return t->ref_count;
208 }
209
210 guint lttv_trace_ref(LttvTrace * t)
211 {
212 t->ref_count++;
213
214 return t->ref_count;
215 }
216
217 guint lttv_trace_unref(LttvTrace * t)
218 {
219 if(likely(t->ref_count > 0))
220 t->ref_count--;
221
222 return t->ref_count;
223 }
224
This page took 0.03247 seconds and 4 git commands to generate.