Add babeltrace libs to configure script
[lttv.git] / 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
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>
dc877563 26
27/* A trace is a sequence of events gathered in the same tracing session. The
28 events may be stored in several tracefiles in the same directory.
29 A trace set is defined when several traces are to be analyzed together,
30 possibly to study the interactions between events in the different traces.
31*/
32
33struct _LttvTraceset {
90e19f82
AM
34 char * filename;
35 GPtrArray *traces;
36 LttvAttribute *a;
308711e5 37};
38
39
40struct _LttvTrace {
90e19f82
AM
41 LttTrace *t;
42 LttvAttribute *a;
43 guint ref_count;
dc877563 44};
45
46
d83f6739 47LttvTraceset *lttv_traceset_new()
dc877563 48{
90e19f82 49 LttvTraceset *s;
dc877563 50
90e19f82
AM
51 s = g_new(LttvTraceset, 1);
52 s->filename = NULL;
53 s->traces = g_ptr_array_new();
54 s->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
55 return s;
dc877563 56}
57
49bf71b5 58char * lttv_traceset_name(LttvTraceset * s)
59{
90e19f82 60 return s->filename;
49bf71b5 61}
62
308711e5 63LttvTrace *lttv_trace_new(LttTrace *t)
64{
90e19f82 65 LttvTrace *new_trace;
308711e5 66
90e19f82
AM
67 new_trace = g_new(LttvTrace, 1);
68 new_trace->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL);
69 new_trace->t = t;
70 new_trace->ref_count = 0;
71 return new_trace;
308711e5 72}
73
74
f7afe191 75LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig)
76{
90e19f82
AM
77 guint i;
78 LttvTraceset *s;
79 LttvTrace * trace;
f7afe191 80
90e19f82
AM
81 s = g_new(LttvTraceset, 1);
82 s->filename = NULL;
83 s->traces = g_ptr_array_new();
84 for(i=0;i<s_orig->traces->len;i++)
85 {
86 trace = g_ptr_array_index(s_orig->traces, i);
87 trace->ref_count++;
2176f952 88
90e19f82
AM
89 g_ptr_array_add(s->traces, trace);
90 }
91 s->a = LTTV_ATTRIBUTE(lttv_iattribute_deep_copy(LTTV_IATTRIBUTE(s_orig->a)));
92 return s;
f7afe191 93}
dc877563 94
f7afe191 95
96LttvTraceset *lttv_traceset_load(const gchar *filename)
97{
90e19f82
AM
98 LttvTraceset *s = g_new(LttvTraceset,1);
99 FILE *tf;
f7afe191 100
90e19f82
AM
101 s->filename = g_strdup(filename);
102 tf = fopen(filename,"r");
103
104 g_critical("NOT IMPLEMENTED : load traceset data from a XML file");
105
106 fclose(tf);
107 return s;
f7afe191 108}
109
110gint lttv_traceset_save(LttvTraceset *s)
111{
90e19f82 112 FILE *tf;
f7afe191 113
90e19f82 114 tf = fopen(s->filename, "w");
f7afe191 115
90e19f82
AM
116 g_critical("NOT IMPLEMENTED : save traceset data in a XML file");
117
118 fclose(tf);
119 return 0;
f7afe191 120}
308711e5 121
ba576a78 122void lttv_traceset_destroy(LttvTraceset *s)
dc877563 123{
90e19f82 124 guint i;
5e2c04a2 125
90e19f82
AM
126 for(i=0;i<s->traces->len;i++) {
127 LttvTrace *trace = g_ptr_array_index(s->traces, i);
128 lttv_trace_unref(trace);
129 if(lttv_trace_get_ref_number(trace) == 0)
130 lttv_trace_destroy(trace);
131 }
132 g_ptr_array_free(s->traces, TRUE);
133 g_object_unref(s->a);
134 g_free(s);
dc877563 135}
136
308711e5 137void lttv_trace_destroy(LttvTrace *t)
138{
90e19f82
AM
139 g_object_unref(t->a);
140 g_free(t);
308711e5 141}
142
143
144void lttv_traceset_add(LttvTraceset *s, LttvTrace *t)
dc877563 145{
90e19f82
AM
146 t->ref_count++;
147 g_ptr_array_add(s->traces, t);
dc877563 148}
149
150
151unsigned lttv_traceset_number(LttvTraceset *s)
152{
90e19f82 153 return s->traces->len;
dc877563 154}
155
156
308711e5 157LttvTrace *lttv_traceset_get(LttvTraceset *s, unsigned i)
dc877563 158{
90e19f82
AM
159 g_assert(s->traces->len > i);
160 return ((LttvTrace *)s->traces->pdata[i]);
dc877563 161}
162
163
ba576a78 164void lttv_traceset_remove(LttvTraceset *s, unsigned i)
dc877563 165{
90e19f82
AM
166 LttvTrace * t;
167 g_assert(s->traces->len > i);
168 t = (LttvTrace *)s->traces->pdata[i];
169 t->ref_count--;
170 g_ptr_array_remove_index(s->traces, i);
dc877563 171}
172
173
174/* A set of attributes is attached to each trace set, trace and tracefile
90e19f82 175 to store user defined data as needed. */
dc877563 176
177LttvAttribute *lttv_traceset_attribute(LttvTraceset *s)
178{
90e19f82 179 return s->a;
dc877563 180}
181
182
308711e5 183LttvAttribute *lttv_trace_attribute(LttvTrace *t)
184{
90e19f82 185 return t->a;
308711e5 186}
187
188
189LttTrace *lttv_trace(LttvTrace *t)
dc877563 190{
90e19f82 191 return t->t;
dc877563 192}
308711e5 193
2176f952 194guint lttv_trace_get_ref_number(LttvTrace * t)
195{
90e19f82 196 return t->ref_count;
2176f952 197}
a43d67ba 198
199guint lttv_trace_ref(LttvTrace * t)
200{
90e19f82
AM
201 t->ref_count++;
202
203 return t->ref_count;
a43d67ba 204}
205
206guint lttv_trace_unref(LttvTrace * t)
207{
90e19f82
AM
208 if(likely(t->ref_count > 0))
209 t->ref_count--;
a43d67ba 210
90e19f82 211 return t->ref_count;
a43d67ba 212}
213
This page took 0.077508 seconds and 4 git commands to generate.