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