global traces works, interaction with mainwindow seems ok
[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{
74 int i;
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
308711e5 86 /*CHECK this used ltt_trace_copy while it may not be needed. Need to
87 define how traces and tracesets are shared */
f7afe191 88 g_ptr_array_add(
89 s->traces,
308711e5 90 g_ptr_array_index(s_orig->traces, i));
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
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}
308711e5 122
ba576a78 123void lttv_traceset_destroy(LttvTraceset *s)
dc877563 124{
ba576a78 125 g_ptr_array_free(s->traces, TRUE);
126 g_object_unref(s->a);
127 g_free(s);
dc877563 128}
129
308711e5 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)
dc877563 138{
2176f952 139 t->ref_count++;
dc877563 140 g_ptr_array_add(s->traces, t);
dc877563 141}
142
143
144unsigned lttv_traceset_number(LttvTraceset *s)
145{
ba576a78 146 return s->traces->len;
dc877563 147}
148
149
308711e5 150LttvTrace *lttv_traceset_get(LttvTraceset *s, unsigned i)
dc877563 151{
152 g_assert(s->traces->len > i);
308711e5 153 return ((LttvTrace *)s->traces->pdata[i]);
dc877563 154}
155
156
ba576a78 157void lttv_traceset_remove(LttvTraceset *s, unsigned i)
dc877563 158{
2176f952 159 LttvTrace * t;
160 g_assert(s->traces->len > i);
161 t = (LttvTrace *)s->traces->pdata[i];
162 t->ref_count--;
ba576a78 163 g_ptr_array_remove_index(s->traces, i);
dc877563 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
308711e5 176LttvAttribute *lttv_trace_attribute(LttvTrace *t)
177{
178 return t->a;
179}
180
181
182LttTrace *lttv_trace(LttvTrace *t)
dc877563 183{
308711e5 184 return t->t;
dc877563 185}
308711e5 186
2176f952 187guint lttv_trace_get_ref_number(LttvTrace * t)
188{
189 return t->ref_count;
190}
a43d67ba 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.03575 seconds and 4 git commands to generate.