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; |
14 | GPtrArray *attributes; |
15 | LttvAttribute *a; |
16 | }; |
17 | |
18 | |
d83f6739 |
19 | LttvTraceset *lttv_traceset_new() |
dc877563 |
20 | { |
ba576a78 |
21 | LttvTraceset *s; |
dc877563 |
22 | |
23 | s = g_new(LttvTraceset, 1); |
f7afe191 |
24 | s->filename = NULL; |
dc877563 |
25 | s->traces = g_ptr_array_new(); |
26 | s->attributes = g_ptr_array_new(); |
ba576a78 |
27 | s->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); |
d83f6739 |
28 | return s; |
dc877563 |
29 | } |
30 | |
f7afe191 |
31 | LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig) |
32 | { |
33 | int i; |
34 | LttvTraceset *s; |
35 | |
36 | s = g_new(LttvTraceset, 1); |
37 | s->filename = NULL; |
38 | s->traces = g_ptr_array_new(); |
39 | for(i=0;i<s_orig->traces->len;i++) |
40 | { |
41 | g_ptr_array_add( |
42 | s->traces, |
43 | ltt_trace_copy(g_ptr_array_index(s_orig->traces, i))); |
44 | } |
45 | s->attributes = g_ptr_array_new(); |
46 | for(i=0;i<s_orig->attributes->len;i++) |
47 | { |
48 | g_ptr_array_add( |
49 | s->attributes, |
50 | lttv_iattribute_deep_copy(g_ptr_array_index(s_orig->attributes, i))); |
51 | } |
52 | |
53 | s->a = LTTV_ATTRIBUTE(lttv_iattribute_deep_copy(LTTV_IATTRIBUTE(s_orig->a))); |
54 | return s; |
55 | } |
dc877563 |
56 | |
f7afe191 |
57 | |
58 | LttvTraceset *lttv_traceset_load(const gchar *filename) |
59 | { |
60 | LttvTraceset *s = g_new(LttvTraceset,1); |
61 | FILE *tf; |
62 | |
63 | s->filename = g_strdup(filename); |
64 | tf = fopen(filename,"r"); |
65 | |
66 | g_critical("NOT IMPLEMENTED : load traceset data from a XML file"); |
67 | |
68 | fclose(tf); |
69 | return s; |
70 | } |
71 | |
72 | gint lttv_traceset_save(LttvTraceset *s) |
73 | { |
74 | FILE *tf; |
75 | |
76 | tf = fopen(s->filename, "w"); |
77 | |
78 | g_critical("NOT IMPLEMENTED : save traceset data in a XML file"); |
79 | |
80 | fclose(tf); |
81 | return 0; |
82 | } |
ba576a78 |
83 | void lttv_traceset_destroy(LttvTraceset *s) |
dc877563 |
84 | { |
85 | int i, nb; |
86 | |
87 | for(i = 0 ; i < s->attributes->len ; i++) { |
ba576a78 |
88 | g_object_unref((LttvAttribute *)s->attributes->pdata[i]); |
dc877563 |
89 | } |
ba576a78 |
90 | g_ptr_array_free(s->attributes, TRUE); |
91 | g_ptr_array_free(s->traces, TRUE); |
92 | g_object_unref(s->a); |
93 | g_free(s); |
dc877563 |
94 | } |
95 | |
dc877563 |
96 | void lttv_traceset_add(LttvTraceset *s, LttTrace *t) |
97 | { |
98 | g_ptr_array_add(s->traces, t); |
ba576a78 |
99 | g_ptr_array_add(s->attributes, g_object_new(LTTV_ATTRIBUTE_TYPE, NULL)); |
dc877563 |
100 | } |
101 | |
102 | |
103 | unsigned lttv_traceset_number(LttvTraceset *s) |
104 | { |
ba576a78 |
105 | return s->traces->len; |
dc877563 |
106 | } |
107 | |
108 | |
109 | LttTrace *lttv_traceset_get(LttvTraceset *s, unsigned i) |
110 | { |
111 | g_assert(s->traces->len > i); |
ba576a78 |
112 | return ((LttTrace *)s->traces->pdata[i]); |
dc877563 |
113 | } |
114 | |
115 | |
ba576a78 |
116 | void lttv_traceset_remove(LttvTraceset *s, unsigned i) |
dc877563 |
117 | { |
ba576a78 |
118 | g_ptr_array_remove_index(s->traces, i); |
119 | g_object_unref(s->attributes->pdata[i]); |
120 | g_ptr_array_remove_index(s->attributes,i); |
dc877563 |
121 | } |
122 | |
123 | |
124 | /* A set of attributes is attached to each trace set, trace and tracefile |
125 | to store user defined data as needed. */ |
126 | |
127 | LttvAttribute *lttv_traceset_attribute(LttvTraceset *s) |
128 | { |
129 | return s->a; |
130 | } |
131 | |
132 | |
133 | LttvAttribute *lttv_traceset_trace_attribute(LttvTraceset *s, unsigned i) |
134 | { |
ba576a78 |
135 | return (LttvAttribute *)s->attributes->pdata[i]; |
dc877563 |
136 | } |