global traces works, interaction with mainwindow seems ok
[lttv.git] / ltt / branches / poly / 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
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
30struct _LttvTraceset {
31 char * filename;
32 GPtrArray *traces;
33 LttvAttribute *a;
34};
35
36
37struct _LttvTrace {
38 LttTrace *t;
39 LttvAttribute *a;
40 guint ref_count;
41};
42
43
44LttvTraceset *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
55char * lttv_traceset_name(LttvTraceset * s)
56{
57 return s->filename;
58}
59
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;
67 new_trace->ref_count = 0;
68 return new_trace;
69}
70
71
72LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig)
73{
74 int 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 /*CHECK this used ltt_trace_copy while it may not be needed. Need to
87 define how traces and tracesets are shared */
88 g_ptr_array_add(
89 s->traces,
90 g_ptr_array_index(s_orig->traces, i));
91 }
92 s->a = LTTV_ATTRIBUTE(lttv_iattribute_deep_copy(LTTV_IATTRIBUTE(s_orig->a)));
93 return s;
94}
95
96
97LttvTraceset *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
111gint 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}
122
123void lttv_traceset_destroy(LttvTraceset *s)
124{
125 g_ptr_array_free(s->traces, TRUE);
126 g_object_unref(s->a);
127 g_free(s);
128}
129
130void lttv_trace_destroy(LttvTrace *t)
131{
132 g_object_unref(t->a);
133 g_free(t);
134}
135
136
137void lttv_traceset_add(LttvTraceset *s, LttvTrace *t)
138{
139 t->ref_count++;
140 g_ptr_array_add(s->traces, t);
141}
142
143
144unsigned lttv_traceset_number(LttvTraceset *s)
145{
146 return s->traces->len;
147}
148
149
150LttvTrace *lttv_traceset_get(LttvTraceset *s, unsigned i)
151{
152 g_assert(s->traces->len > i);
153 return ((LttvTrace *)s->traces->pdata[i]);
154}
155
156
157void lttv_traceset_remove(LttvTraceset *s, unsigned i)
158{
159 LttvTrace * t;
160 g_assert(s->traces->len > i);
161 t = (LttvTrace *)s->traces->pdata[i];
162 t->ref_count--;
163 g_ptr_array_remove_index(s->traces, i);
164}
165
166
167/* A set of attributes is attached to each trace set, trace and tracefile
168 to store user defined data as needed. */
169
170LttvAttribute *lttv_traceset_attribute(LttvTraceset *s)
171{
172 return s->a;
173}
174
175
176LttvAttribute *lttv_trace_attribute(LttvTrace *t)
177{
178 return t->a;
179}
180
181
182LttTrace *lttv_trace(LttvTrace *t)
183{
184 return t->t;
185}
186
187guint lttv_trace_get_ref_number(LttvTrace * t)
188{
189 return t->ref_count;
190}
191
192guint lttv_trace_ref(LttvTrace * t)
193{
194 t->ref_count++;
195
196 return t->ref_count;
197}
198
199guint lttv_trace_unref(LttvTrace * t)
200{
201 if(t->ref_count > 0)
202 t->ref_count--;
203
204 return t->ref_count;
205}
206
This page took 0.023252 seconds and 4 git commands to generate.