1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
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;
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.
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,
23 #include <lttv/traceset.h>
24 #include <lttv/iattribute.h>
26 #include <babeltrace/context.h>
28 /* A trace is a sequence of events gathered in the same tracing session. The
29 events may be stored in several tracefiles in the same directory.
30 A trace set is defined when several traces are to be analyzed together,
31 possibly to study the interactions between events in the different traces.
34 struct _LttvTraceset
{
37 struct bt_context
*context
;
43 // Trace id for babeltrace
49 LttvTraceset
*lttv_traceset_new()
53 s
= g_new(LttvTraceset
, 1);
55 s
->traces
= g_ptr_array_new();
56 s
->context
= bt_context_create();
57 s
->a
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
61 char * lttv_traceset_name(LttvTraceset
* s
)
67 LttvTrace
*lttv_trace_new(LttTrace
*t
)
71 new_trace
= g_new(LttvTrace
, 1);
72 new_trace
->a
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
74 new_trace
->ref_count
= 0;
80 * lttv_trace_create : Create a trace from a path
82 * ts is the traceset in which will be contained the trace
84 * path is the path where to find a trace. It is not recursive.
86 * This function is static since a trace should always be contained in a
89 * return the created trace or NULL on failure
91 static LttvTrace
*lttv_trace_create(LttvTraceset
*ts
, const char *path
)
93 int id
= bt_context_add_trace(lttv_traceset_get_context(ts
),
102 // Create the trace and save the trace handle id returned by babeltrace
103 LttvTrace
*new_trace
;
105 new_trace
= g_new(LttvTrace
, 1);
106 new_trace
->a
= g_object_new(LTTV_ATTRIBUTE_TYPE
, NULL
);
108 new_trace
->ref_count
= 0;
113 * lttv_trace_create : Create and add a single trace to a traceset
115 * ts is the traceset in which will be contained the trace
117 * path is the path where to find a trace. It is not recursive.
119 * return a positive integer (>=0)on success or -1 on failure
121 static int lttv_traceset_create_trace(LttvTraceset
*ts
, const char *path
)
123 LttvTrace
*trace
= lttv_trace_create(ts
, path
);
127 lttv_traceset_add(ts
, trace
);
131 LttvTraceset
*lttv_traceset_copy(LttvTraceset
*s_orig
)
137 s
= g_new(LttvTraceset
, 1);
139 s
->traces
= g_ptr_array_new();
140 for(i
=0;i
<s_orig
->traces
->len
;i
++)
142 trace
= g_ptr_array_index(s_orig
->traces
, i
);
145 g_ptr_array_add(s
->traces
, trace
);
147 s
->context
= s_orig
->context
;
148 bt_context_get(s
->context
);
149 s
->a
= LTTV_ATTRIBUTE(lttv_iattribute_deep_copy(LTTV_IATTRIBUTE(s_orig
->a
)));
154 LttvTraceset
*lttv_traceset_load(const gchar
*filename
)
156 LttvTraceset
*s
= g_new(LttvTraceset
,1);
159 s
->filename
= g_strdup(filename
);
160 tf
= fopen(filename
,"r");
162 g_critical("NOT IMPLEMENTED : load traceset data from a XML file");
168 gint
lttv_traceset_save(LttvTraceset
*s
)
172 tf
= fopen(s
->filename
, "w");
174 g_critical("NOT IMPLEMENTED : save traceset data in a XML file");
180 void lttv_traceset_destroy(LttvTraceset
*s
)
184 for(i
=0;i
<s
->traces
->len
;i
++) {
185 LttvTrace
*trace
= g_ptr_array_index(s
->traces
, i
);
186 lttv_trace_unref(trace
);
187 // todo mdenis 2012-03-27: uncomment when babeltrace gets fixed
188 //bt_context_remove_trace(lttv_traceset_get_context(s), trace->id);
189 if(lttv_trace_get_ref_number(trace
) == 0)
190 lttv_trace_destroy(trace
);
192 g_ptr_array_free(s
->traces
, TRUE
);
193 bt_context_put(s
->context
);
194 g_object_unref(s
->a
);
198 struct bt_context
*lttv_traceset_get_context(LttvTraceset
*s
)
203 void lttv_trace_destroy(LttvTrace
*t
)
205 g_object_unref(t
->a
);
210 void lttv_traceset_add(LttvTraceset
*s
, LttvTrace
*t
)
213 g_ptr_array_add(s
->traces
, t
);
216 int lttv_traceset_add_path(LttvTraceset
*ts
, const char *trace_path
)
218 // todo mdenis 2012-03-27: add trace recursively and update comment
219 int ret
= lttv_traceset_create_trace(ts
, trace_path
);
223 unsigned lttv_traceset_number(LttvTraceset
*s
)
225 return s
->traces
->len
;
229 LttvTrace
*lttv_traceset_get(LttvTraceset
*s
, unsigned i
)
231 g_assert(s
->traces
->len
> i
);
232 return ((LttvTrace
*)s
->traces
->pdata
[i
]);
236 void lttv_traceset_remove(LttvTraceset
*s
, unsigned i
)
239 g_assert(s
->traces
->len
> i
);
240 t
= (LttvTrace
*)s
->traces
->pdata
[i
];
242 bt_context_remove_trace(lttv_traceset_get_context(s
), t
->id
);
243 g_ptr_array_remove_index(s
->traces
, i
);
247 /* A set of attributes is attached to each trace set, trace and tracefile
248 to store user defined data as needed. */
250 LttvAttribute
*lttv_traceset_attribute(LttvTraceset
*s
)
256 LttvAttribute
*lttv_trace_attribute(LttvTrace
*t
)
262 LttTrace
*lttv_trace(LttvTrace
*t
)
268 gint
lttv_trace_get_id(LttvTrace
*t
)
273 guint
lttv_trace_get_ref_number(LttvTrace
* t
)
275 // todo mdenis: adapt to babeltrace
279 guint
lttv_trace_ref(LttvTrace
* t
)
286 guint
lttv_trace_unref(LttvTrace
* t
)
288 if(likely(t
->ref_count
> 0))
This page took 0.038405 seconds and 5 git commands to generate.