Commit | Line | Data |
---|---|---|
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> |
cbb811b3 | 26 | #include <babeltrace/context.h> |
dc877563 | 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 { | |
90e19f82 AM |
35 | char * filename; |
36 | GPtrArray *traces; | |
cbb811b3 | 37 | struct bt_context *context; |
90e19f82 | 38 | LttvAttribute *a; |
308711e5 | 39 | }; |
40 | ||
41 | ||
42 | struct _LttvTrace { | |
90e19f82 AM |
43 | LttTrace *t; |
44 | LttvAttribute *a; | |
45 | guint ref_count; | |
dc877563 | 46 | }; |
47 | ||
48 | ||
d83f6739 | 49 | LttvTraceset *lttv_traceset_new() |
dc877563 | 50 | { |
90e19f82 | 51 | LttvTraceset *s; |
dc877563 | 52 | |
90e19f82 AM |
53 | s = g_new(LttvTraceset, 1); |
54 | s->filename = NULL; | |
55 | s->traces = g_ptr_array_new(); | |
cbb811b3 | 56 | s->context = bt_context_create(); |
90e19f82 AM |
57 | s->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
58 | return s; | |
dc877563 | 59 | } |
60 | ||
49bf71b5 | 61 | char * lttv_traceset_name(LttvTraceset * s) |
62 | { | |
90e19f82 | 63 | return s->filename; |
49bf71b5 | 64 | } |
65 | ||
308711e5 | 66 | LttvTrace *lttv_trace_new(LttTrace *t) |
67 | { | |
90e19f82 | 68 | LttvTrace *new_trace; |
308711e5 | 69 | |
90e19f82 AM |
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; | |
308711e5 | 75 | } |
76 | ||
77 | ||
f7afe191 | 78 | LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig) |
79 | { | |
90e19f82 AM |
80 | guint i; |
81 | LttvTraceset *s; | |
82 | LttvTrace * trace; | |
f7afe191 | 83 | |
90e19f82 AM |
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++; | |
2176f952 | 91 | |
90e19f82 AM |
92 | g_ptr_array_add(s->traces, trace); |
93 | } | |
cbb811b3 YB |
94 | s->context = s_orig->context; |
95 | bt_context_get(s->context); | |
90e19f82 AM |
96 | s->a = LTTV_ATTRIBUTE(lttv_iattribute_deep_copy(LTTV_IATTRIBUTE(s_orig->a))); |
97 | return s; | |
f7afe191 | 98 | } |
dc877563 | 99 | |
f7afe191 | 100 | |
101 | LttvTraceset *lttv_traceset_load(const gchar *filename) | |
102 | { | |
90e19f82 AM |
103 | LttvTraceset *s = g_new(LttvTraceset,1); |
104 | FILE *tf; | |
f7afe191 | 105 | |
90e19f82 AM |
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; | |
f7afe191 | 113 | } |
114 | ||
115 | gint lttv_traceset_save(LttvTraceset *s) | |
116 | { | |
90e19f82 | 117 | FILE *tf; |
f7afe191 | 118 | |
90e19f82 | 119 | tf = fopen(s->filename, "w"); |
f7afe191 | 120 | |
90e19f82 AM |
121 | g_critical("NOT IMPLEMENTED : save traceset data in a XML file"); |
122 | ||
123 | fclose(tf); | |
124 | return 0; | |
f7afe191 | 125 | } |
308711e5 | 126 | |
ba576a78 | 127 | void lttv_traceset_destroy(LttvTraceset *s) |
dc877563 | 128 | { |
90e19f82 | 129 | guint i; |
5e2c04a2 | 130 | |
90e19f82 AM |
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); | |
cbb811b3 | 138 | bt_context_put(s->context); |
90e19f82 AM |
139 | g_object_unref(s->a); |
140 | g_free(s); | |
dc877563 | 141 | } |
142 | ||
922581a4 YB |
143 | struct bt_context *lttv_traceset_get_context(LttvTraceset *s) |
144 | { | |
145 | return s->context; | |
146 | } | |
147 | ||
308711e5 | 148 | void lttv_trace_destroy(LttvTrace *t) |
149 | { | |
90e19f82 AM |
150 | g_object_unref(t->a); |
151 | g_free(t); | |
308711e5 | 152 | } |
153 | ||
154 | ||
155 | void lttv_traceset_add(LttvTraceset *s, LttvTrace *t) | |
dc877563 | 156 | { |
90e19f82 AM |
157 | t->ref_count++; |
158 | g_ptr_array_add(s->traces, t); | |
dc877563 | 159 | } |
160 | ||
161 | ||
162 | unsigned lttv_traceset_number(LttvTraceset *s) | |
163 | { | |
90e19f82 | 164 | return s->traces->len; |
dc877563 | 165 | } |
166 | ||
167 | ||
308711e5 | 168 | LttvTrace *lttv_traceset_get(LttvTraceset *s, unsigned i) |
dc877563 | 169 | { |
90e19f82 AM |
170 | g_assert(s->traces->len > i); |
171 | return ((LttvTrace *)s->traces->pdata[i]); | |
dc877563 | 172 | } |
173 | ||
174 | ||
ba576a78 | 175 | void lttv_traceset_remove(LttvTraceset *s, unsigned i) |
dc877563 | 176 | { |
90e19f82 AM |
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); | |
dc877563 | 182 | } |
183 | ||
184 | ||
185 | /* A set of attributes is attached to each trace set, trace and tracefile | |
90e19f82 | 186 | to store user defined data as needed. */ |
dc877563 | 187 | |
188 | LttvAttribute *lttv_traceset_attribute(LttvTraceset *s) | |
189 | { | |
90e19f82 | 190 | return s->a; |
dc877563 | 191 | } |
192 | ||
193 | ||
308711e5 | 194 | LttvAttribute *lttv_trace_attribute(LttvTrace *t) |
195 | { | |
90e19f82 | 196 | return t->a; |
308711e5 | 197 | } |
198 | ||
199 | ||
200 | LttTrace *lttv_trace(LttvTrace *t) | |
dc877563 | 201 | { |
90e19f82 | 202 | return t->t; |
dc877563 | 203 | } |
308711e5 | 204 | |
2176f952 | 205 | guint lttv_trace_get_ref_number(LttvTrace * t) |
206 | { | |
90e19f82 | 207 | return t->ref_count; |
2176f952 | 208 | } |
a43d67ba | 209 | |
210 | guint lttv_trace_ref(LttvTrace * t) | |
211 | { | |
90e19f82 AM |
212 | t->ref_count++; |
213 | ||
214 | return t->ref_count; | |
a43d67ba | 215 | } |
216 | ||
217 | guint lttv_trace_unref(LttvTrace * t) | |
218 | { | |
90e19f82 AM |
219 | if(likely(t->ref_count > 0)) |
220 | t->ref_count--; | |
a43d67ba | 221 | |
90e19f82 | 222 | return t->ref_count; |
a43d67ba | 223 | } |
224 |