Add a bt_context to the lttv_traceset struct
[lttv.git] / lttv / lttv / traceset.c
... / ...
CommitLineData
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
34struct _LttvTraceset {
35 char * filename;
36 GPtrArray *traces;
37 struct bt_context *context;
38 LttvAttribute *a;
39};
40
41
42struct _LttvTrace {
43 LttTrace *t;
44 LttvAttribute *a;
45 guint ref_count;
46};
47
48
49LttvTraceset *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
61char * lttv_traceset_name(LttvTraceset * s)
62{
63 return s->filename;
64}
65
66LttvTrace *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
78LttvTraceset *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
101LttvTraceset *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
115gint 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
127void 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
143void lttv_trace_destroy(LttvTrace *t)
144{
145 g_object_unref(t->a);
146 g_free(t);
147}
148
149
150void lttv_traceset_add(LttvTraceset *s, LttvTrace *t)
151{
152 t->ref_count++;
153 g_ptr_array_add(s->traces, t);
154}
155
156
157unsigned lttv_traceset_number(LttvTraceset *s)
158{
159 return s->traces->len;
160}
161
162
163LttvTrace *lttv_traceset_get(LttvTraceset *s, unsigned i)
164{
165 g_assert(s->traces->len > i);
166 return ((LttvTrace *)s->traces->pdata[i]);
167}
168
169
170void lttv_traceset_remove(LttvTraceset *s, unsigned i)
171{
172 LttvTrace * t;
173 g_assert(s->traces->len > i);
174 t = (LttvTrace *)s->traces->pdata[i];
175 t->ref_count--;
176 g_ptr_array_remove_index(s->traces, i);
177}
178
179
180/* A set of attributes is attached to each trace set, trace and tracefile
181 to store user defined data as needed. */
182
183LttvAttribute *lttv_traceset_attribute(LttvTraceset *s)
184{
185 return s->a;
186}
187
188
189LttvAttribute *lttv_trace_attribute(LttvTrace *t)
190{
191 return t->a;
192}
193
194
195LttTrace *lttv_trace(LttvTrace *t)
196{
197 return t->t;
198}
199
200guint lttv_trace_get_ref_number(LttvTrace * t)
201{
202 return t->ref_count;
203}
204
205guint lttv_trace_ref(LttvTrace * t)
206{
207 t->ref_count++;
208
209 return t->ref_count;
210}
211
212guint lttv_trace_unref(LttvTrace * t)
213{
214 if(likely(t->ref_count > 0))
215 t->ref_count--;
216
217 return t->ref_count;
218}
219
This page took 0.022707 seconds and 4 git commands to generate.