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