header missing
[lttv.git] / ltt / branches / poly / lttv / lttv / traceset.c
CommitLineData
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
dc877563 19
20#include <lttv/traceset.h>
3e67c985 21#include <lttv/iattribute.h>
f7afe191 22#include <stdio.h>
dc877563 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
30struct _LttvTraceset {
f7afe191 31 char * filename;
dc877563 32 GPtrArray *traces;
308711e5 33 LttvAttribute *a;
34};
35
36
37struct _LttvTrace {
38 LttTrace *t;
dc877563 39 LttvAttribute *a;
2176f952 40 guint ref_count;
dc877563 41};
42
43
d83f6739 44LttvTraceset *lttv_traceset_new()
dc877563 45{
ba576a78 46 LttvTraceset *s;
dc877563 47
48 s = g_new(LttvTraceset, 1);
f7afe191 49 s->filename = NULL;
dc877563 50 s->traces = g_ptr_array_new();
ba576a78 51 s->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
d83f6739 52 return s;
dc877563 53}
54
49bf71b5 55char * lttv_traceset_name(LttvTraceset * s)
56{
57 return s->filename;
58}
59
308711e5 60LttvTrace *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;
2176f952 67 new_trace->ref_count = 0;
308711e5 68 return new_trace;
69}
70
71
f7afe191 72LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig)
73{
00e74b69 74 guint i;
f7afe191 75 LttvTraceset *s;
2176f952 76 LttvTrace * trace;
f7afe191 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 {
2176f952 83 trace = g_ptr_array_index(s_orig->traces, i);
84 trace->ref_count++;
85
5e2c04a2 86 g_ptr_array_add(s->traces,
87 trace);
f7afe191 88 }
e1681e46 89 s->a = LTTV_ATTRIBUTE(lttv_iattribute_deep_copy(LTTV_IATTRIBUTE(s_orig->a)));
f7afe191 90 return s;
91}
dc877563 92
f7afe191 93
94LttvTraceset *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
108gint 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}
308711e5 119
ba576a78 120void lttv_traceset_destroy(LttvTraceset *s)
dc877563 121{
5e2c04a2 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 }
ba576a78 130 g_ptr_array_free(s->traces, TRUE);
131 g_object_unref(s->a);
132 g_free(s);
dc877563 133}
134
308711e5 135void lttv_trace_destroy(LttvTrace *t)
136{
137 g_object_unref(t->a);
138 g_free(t);
139}
140
141
142void lttv_traceset_add(LttvTraceset *s, LttvTrace *t)
dc877563 143{
2176f952 144 t->ref_count++;
dc877563 145 g_ptr_array_add(s->traces, t);
dc877563 146}
147
148
149unsigned lttv_traceset_number(LttvTraceset *s)
150{
ba576a78 151 return s->traces->len;
dc877563 152}
153
154
308711e5 155LttvTrace *lttv_traceset_get(LttvTraceset *s, unsigned i)
dc877563 156{
157 g_assert(s->traces->len > i);
308711e5 158 return ((LttvTrace *)s->traces->pdata[i]);
dc877563 159}
160
161
ba576a78 162void lttv_traceset_remove(LttvTraceset *s, unsigned i)
dc877563 163{
2176f952 164 LttvTrace * t;
165 g_assert(s->traces->len > i);
166 t = (LttvTrace *)s->traces->pdata[i];
167 t->ref_count--;
ba576a78 168 g_ptr_array_remove_index(s->traces, i);
dc877563 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
175LttvAttribute *lttv_traceset_attribute(LttvTraceset *s)
176{
177 return s->a;
178}
179
180
308711e5 181LttvAttribute *lttv_trace_attribute(LttvTrace *t)
182{
183 return t->a;
184}
185
186
187LttTrace *lttv_trace(LttvTrace *t)
dc877563 188{
308711e5 189 return t->t;
dc877563 190}
308711e5 191
2176f952 192guint lttv_trace_get_ref_number(LttvTrace * t)
193{
194 return t->ref_count;
195}
a43d67ba 196
197guint lttv_trace_ref(LttvTrace * t)
198{
199 t->ref_count++;
200
201 return t->ref_count;
202}
203
204guint lttv_trace_unref(LttvTrace * t)
205{
1d1df11d 206 if(likely(t->ref_count > 0))
a43d67ba 207 t->ref_count--;
208
209 return t->ref_count;
210}
211
This page took 0.040755 seconds and 4 git commands to generate.