uninitialized variables checked, plus O2 optimisations checked : strict aliasing...
[lttv.git] / ltt / branches / poly / 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
20 #include <lttv/traceset.h>
21 #include <lttv/iattribute.h>
22 #include <stdio.h>
23
24 /* A trace is a sequence of events gathered in the same tracing session. The
25 events may be stored in several tracefiles in the same directory.
26 A trace set is defined when several traces are to be analyzed together,
27 possibly to study the interactions between events in the different traces.
28 */
29
30 struct _LttvTraceset {
31 char * filename;
32 GPtrArray *traces;
33 LttvAttribute *a;
34 };
35
36
37 struct _LttvTrace {
38 LttTrace *t;
39 LttvAttribute *a;
40 guint ref_count;
41 };
42
43
44 LttvTraceset *lttv_traceset_new()
45 {
46 LttvTraceset *s;
47
48 s = g_new(LttvTraceset, 1);
49 s->filename = NULL;
50 s->traces = g_ptr_array_new();
51 s->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
52 return s;
53 }
54
55 char * lttv_traceset_name(LttvTraceset * s)
56 {
57 return s->filename;
58 }
59
60 LttvTrace *lttv_trace_new(LttTrace *t)
61 {
62 LttvTrace *new_trace;
63
64 new_trace = g_new(LttvTrace, 1);
65 new_trace->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
66 new_trace->t = t;
67 new_trace->ref_count = 0;
68 return new_trace;
69 }
70
71
72 LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig)
73 {
74 guint i;
75 LttvTraceset *s;
76 LttvTrace * trace;
77
78 s = g_new(LttvTraceset, 1);
79 s->filename = NULL;
80 s->traces = g_ptr_array_new();
81 for(i=0;i<s_orig->traces->len;i++)
82 {
83 trace = g_ptr_array_index(s_orig->traces, i);
84 trace->ref_count++;
85
86 g_ptr_array_add(s->traces,
87 trace);
88 }
89 s->a = LTTV_ATTRIBUTE(lttv_iattribute_deep_copy(LTTV_IATTRIBUTE(s_orig->a)));
90 return s;
91 }
92
93
94 LttvTraceset *lttv_traceset_load(const gchar *filename)
95 {
96 LttvTraceset *s = g_new(LttvTraceset,1);
97 FILE *tf;
98
99 s->filename = g_strdup(filename);
100 tf = fopen(filename,"r");
101
102 g_critical("NOT IMPLEMENTED : load traceset data from a XML file");
103
104 fclose(tf);
105 return s;
106 }
107
108 gint lttv_traceset_save(LttvTraceset *s)
109 {
110 FILE *tf;
111
112 tf = fopen(s->filename, "w");
113
114 g_critical("NOT IMPLEMENTED : save traceset data in a XML file");
115
116 fclose(tf);
117 return 0;
118 }
119
120 void lttv_traceset_destroy(LttvTraceset *s)
121 {
122 guint i;
123
124 for(i=0;i<s->traces->len;i++) {
125 LttvTrace *trace = g_ptr_array_index(s->traces, i);
126 lttv_trace_unref(trace);
127 if(lttv_trace_get_ref_number(trace) == 0)
128 lttv_trace_destroy(trace);
129 }
130 g_ptr_array_free(s->traces, TRUE);
131 g_object_unref(s->a);
132 g_free(s);
133 }
134
135 void lttv_trace_destroy(LttvTrace *t)
136 {
137 g_object_unref(t->a);
138 g_free(t);
139 }
140
141
142 void lttv_traceset_add(LttvTraceset *s, LttvTrace *t)
143 {
144 t->ref_count++;
145 g_ptr_array_add(s->traces, t);
146 }
147
148
149 unsigned lttv_traceset_number(LttvTraceset *s)
150 {
151 return s->traces->len;
152 }
153
154
155 LttvTrace *lttv_traceset_get(LttvTraceset *s, unsigned i)
156 {
157 g_assert(s->traces->len > i);
158 return ((LttvTrace *)s->traces->pdata[i]);
159 }
160
161
162 void lttv_traceset_remove(LttvTraceset *s, unsigned i)
163 {
164 LttvTrace * t;
165 g_assert(s->traces->len > i);
166 t = (LttvTrace *)s->traces->pdata[i];
167 t->ref_count--;
168 g_ptr_array_remove_index(s->traces, i);
169 }
170
171
172 /* A set of attributes is attached to each trace set, trace and tracefile
173 to store user defined data as needed. */
174
175 LttvAttribute *lttv_traceset_attribute(LttvTraceset *s)
176 {
177 return s->a;
178 }
179
180
181 LttvAttribute *lttv_trace_attribute(LttvTrace *t)
182 {
183 return t->a;
184 }
185
186
187 LttTrace *lttv_trace(LttvTrace *t)
188 {
189 return t->t;
190 }
191
192 guint lttv_trace_get_ref_number(LttvTrace * t)
193 {
194 return t->ref_count;
195 }
196
197 guint lttv_trace_ref(LttvTrace * t)
198 {
199 t->ref_count++;
200
201 return t->ref_count;
202 }
203
204 guint lttv_trace_unref(LttvTrace * t)
205 {
206 if(t->ref_count > 0)
207 t->ref_count--;
208
209 return t->ref_count;
210 }
211
This page took 0.033381 seconds and 4 git commands to generate.