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> |
f7afe191 |
21 | #include <stdio.h> |
dc877563 |
22 | |
23 | /* A trace is a sequence of events gathered in the same tracing session. The |
24 | events may be stored in several tracefiles in the same directory. |
25 | A trace set is defined when several traces are to be analyzed together, |
26 | possibly to study the interactions between events in the different traces. |
27 | */ |
28 | |
29 | struct _LttvTraceset { |
f7afe191 |
30 | char * filename; |
dc877563 |
31 | GPtrArray *traces; |
308711e5 |
32 | LttvAttribute *a; |
33 | }; |
34 | |
35 | |
36 | struct _LttvTrace { |
37 | LttTrace *t; |
dc877563 |
38 | LttvAttribute *a; |
2176f952 |
39 | guint ref_count; |
dc877563 |
40 | }; |
41 | |
42 | |
d83f6739 |
43 | LttvTraceset *lttv_traceset_new() |
dc877563 |
44 | { |
ba576a78 |
45 | LttvTraceset *s; |
dc877563 |
46 | |
47 | s = g_new(LttvTraceset, 1); |
f7afe191 |
48 | s->filename = NULL; |
dc877563 |
49 | s->traces = g_ptr_array_new(); |
ba576a78 |
50 | s->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
d83f6739 |
51 | return s; |
dc877563 |
52 | } |
53 | |
49bf71b5 |
54 | char * lttv_traceset_name(LttvTraceset * s) |
55 | { |
56 | return s->filename; |
57 | } |
58 | |
308711e5 |
59 | LttvTrace *lttv_trace_new(LttTrace *t) |
60 | { |
61 | LttvTrace *new_trace; |
62 | |
63 | new_trace = g_new(LttvTrace, 1); |
64 | new_trace->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
65 | new_trace->t = t; |
2176f952 |
66 | new_trace->ref_count = 0; |
308711e5 |
67 | return new_trace; |
68 | } |
69 | |
70 | |
f7afe191 |
71 | LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig) |
72 | { |
73 | int i; |
74 | LttvTraceset *s; |
2176f952 |
75 | LttvTrace * trace; |
f7afe191 |
76 | |
77 | s = g_new(LttvTraceset, 1); |
78 | s->filename = NULL; |
79 | s->traces = g_ptr_array_new(); |
80 | for(i=0;i<s_orig->traces->len;i++) |
81 | { |
2176f952 |
82 | trace = g_ptr_array_index(s_orig->traces, i); |
83 | trace->ref_count++; |
84 | |
308711e5 |
85 | /*CHECK this used ltt_trace_copy while it may not be needed. Need to |
86 | define how traces and tracesets are shared */ |
f7afe191 |
87 | g_ptr_array_add( |
88 | s->traces, |
308711e5 |
89 | g_ptr_array_index(s_orig->traces, i)); |
f7afe191 |
90 | } |
f7afe191 |
91 | s->a = LTTV_ATTRIBUTE(lttv_iattribute_deep_copy(LTTV_IATTRIBUTE(s_orig->a))); |
92 | return s; |
93 | } |
dc877563 |
94 | |
f7afe191 |
95 | |
96 | LttvTraceset *lttv_traceset_load(const gchar *filename) |
97 | { |
98 | LttvTraceset *s = g_new(LttvTraceset,1); |
99 | FILE *tf; |
100 | |
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; |
108 | } |
109 | |
110 | gint lttv_traceset_save(LttvTraceset *s) |
111 | { |
112 | FILE *tf; |
113 | |
114 | tf = fopen(s->filename, "w"); |
115 | |
116 | g_critical("NOT IMPLEMENTED : save traceset data in a XML file"); |
117 | |
118 | fclose(tf); |
119 | return 0; |
120 | } |
308711e5 |
121 | |
ba576a78 |
122 | void lttv_traceset_destroy(LttvTraceset *s) |
dc877563 |
123 | { |
ba576a78 |
124 | g_ptr_array_free(s->traces, TRUE); |
125 | g_object_unref(s->a); |
126 | g_free(s); |
dc877563 |
127 | } |
128 | |
308711e5 |
129 | void lttv_trace_destroy(LttvTrace *t) |
130 | { |
131 | g_object_unref(t->a); |
132 | g_free(t); |
133 | } |
134 | |
135 | |
136 | void lttv_traceset_add(LttvTraceset *s, LttvTrace *t) |
dc877563 |
137 | { |
2176f952 |
138 | t->ref_count++; |
dc877563 |
139 | g_ptr_array_add(s->traces, t); |
dc877563 |
140 | } |
141 | |
142 | |
143 | unsigned lttv_traceset_number(LttvTraceset *s) |
144 | { |
ba576a78 |
145 | return s->traces->len; |
dc877563 |
146 | } |
147 | |
148 | |
308711e5 |
149 | LttvTrace *lttv_traceset_get(LttvTraceset *s, unsigned i) |
dc877563 |
150 | { |
151 | g_assert(s->traces->len > i); |
308711e5 |
152 | return ((LttvTrace *)s->traces->pdata[i]); |
dc877563 |
153 | } |
154 | |
155 | |
ba576a78 |
156 | void lttv_traceset_remove(LttvTraceset *s, unsigned i) |
dc877563 |
157 | { |
2176f952 |
158 | LttvTrace * t; |
159 | g_assert(s->traces->len > i); |
160 | t = (LttvTrace *)s->traces->pdata[i]; |
161 | t->ref_count--; |
ba576a78 |
162 | g_ptr_array_remove_index(s->traces, i); |
dc877563 |
163 | } |
164 | |
165 | |
166 | /* A set of attributes is attached to each trace set, trace and tracefile |
167 | to store user defined data as needed. */ |
168 | |
169 | LttvAttribute *lttv_traceset_attribute(LttvTraceset *s) |
170 | { |
171 | return s->a; |
172 | } |
173 | |
174 | |
308711e5 |
175 | LttvAttribute *lttv_trace_attribute(LttvTrace *t) |
176 | { |
177 | return t->a; |
178 | } |
179 | |
180 | |
181 | LttTrace *lttv_trace(LttvTrace *t) |
dc877563 |
182 | { |
308711e5 |
183 | return t->t; |
dc877563 |
184 | } |
308711e5 |
185 | |
2176f952 |
186 | guint lttv_trace_get_ref_number(LttvTrace * t) |
187 | { |
188 | return t->ref_count; |
189 | } |