Commit | Line | Data |
---|---|---|
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> |
7a4bdb54 | 25 | #include <lttv/state.h> |
9a366873 | 26 | #include <lttv/event.h> |
7a4bdb54 | 27 | #include <lttv/hook.h> |
f7afe191 | 28 | #include <stdio.h> |
451aaf27 | 29 | #include <babeltrace/babeltrace.h> |
cbb811b3 | 30 | #include <babeltrace/context.h> |
451aaf27 | 31 | #include <babeltrace/ctf/iterator.h> |
7a4bdb54 | 32 | #include <babeltrace/ctf/events.h> |
3685e022 | 33 | |
34 | /* To traverse a tree recursively */ | |
35 | #include <fcntl.h> | |
36 | #include <fts.h> | |
451aaf27 FD |
37 | /* For the use of realpath*/ |
38 | #include <limits.h> | |
39 | #include <stdlib.h> | |
40 | /* For strcpy*/ | |
41 | #include <string.h> | |
3685e022 | 42 | |
dc877563 | 43 | /* A trace is a sequence of events gathered in the same tracing session. The |
44 | events may be stored in several tracefiles in the same directory. | |
45 | A trace set is defined when several traces are to be analyzed together, | |
46 | possibly to study the interactions between events in the different traces. | |
47 | */ | |
48 | ||
dc877563 | 49 | |
7a4bdb54 | 50 | LttvTraceset *lttv_traceset_new(void) |
dc877563 | 51 | { |
9a366873 FD |
52 | LttvTraceset *ts; |
53 | struct bt_iter_pos begin_pos; | |
dc877563 | 54 | |
9a366873 FD |
55 | ts = g_new(LttvTraceset, 1); |
56 | ts->filename = NULL; | |
57 | ts->traces = g_ptr_array_new(); | |
58 | ts->context = bt_context_create(); | |
59 | ts->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); | |
7a4bdb54 YB |
60 | //TODO remove this when we have really mecanism |
61 | //s->tmpState = g_new(LttvTraceState *, 1); | |
62 | //lttv_trace_state_init(s->tmpState,0); | |
7a4bdb54 | 63 | |
9a366873 FD |
64 | /*Initialize iterator to the beginning of the traces*/ |
65 | begin_pos.type = BT_SEEK_BEGIN; | |
66 | ts->iter = bt_ctf_iter_create(ts->context, &begin_pos, NULL); | |
7a4bdb54 | 67 | |
9a366873 FD |
68 | ts->event_hooks = lttv_hooks_new(); |
69 | ||
70 | ts->state_trace_handle_index = g_ptr_array_new(); | |
58b4e4ae | 71 | ts->has_precomputed_states = FALSE; |
9a366873 FD |
72 | |
73 | return ts; | |
dc877563 | 74 | } |
75 | ||
49bf71b5 | 76 | char * lttv_traceset_name(LttvTraceset * s) |
77 | { | |
90e19f82 | 78 | return s->filename; |
49bf71b5 | 79 | } |
80 | ||
2bc1bcfb | 81 | #ifdef BABEL_CLEANUP |
82 | LttvTrace *lttv_trace_new(LttTrace *t) | |
308711e5 | 83 | { |
90e19f82 | 84 | LttvTrace *new_trace; |
308711e5 | 85 | |
90e19f82 AM |
86 | new_trace = g_new(LttvTrace, 1); |
87 | new_trace->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); | |
2bc1bcfb | 88 | new_trace->id = t; |
90e19f82 AM |
89 | new_trace->ref_count = 0; |
90 | return new_trace; | |
308711e5 | 91 | } |
2bc1bcfb | 92 | #endif |
451aaf27 FD |
93 | /* |
94 | * get_absolute_pathname : Return the unique pathname in the system | |
95 | * | |
96 | * pathname is the relative path. | |
97 | * | |
98 | * abs_pathname is being set to the absolute path. | |
99 | * | |
100 | */ | |
101 | void get_absolute_pathname(const gchar *pathname, gchar * abs_pathname) | |
102 | { | |
103 | abs_pathname[0] = '\0'; | |
104 | ||
105 | if (realpath(pathname, abs_pathname) != NULL) | |
106 | return; | |
107 | else | |
108 | { | |
109 | /* error, return the original path unmodified */ | |
110 | strcpy(abs_pathname, pathname); | |
111 | return; | |
112 | } | |
113 | return; | |
114 | } | |
115 | ||
116 | ||
308711e5 | 117 | |
2bc1bcfb | 118 | /* |
119 | * lttv_trace_create : Create a trace from a path | |
120 | * | |
121 | * ts is the traceset in which will be contained the trace | |
122 | * | |
123 | * path is the path where to find a trace. It is not recursive. | |
124 | * | |
125 | * This function is static since a trace should always be contained in a | |
126 | * traceset. | |
127 | * | |
128 | * return the created trace or NULL on failure | |
129 | */ | |
130 | static LttvTrace *lttv_trace_create(LttvTraceset *ts, const char *path) | |
131 | { | |
9a366873 FD |
132 | int id = bt_context_add_trace(lttv_traceset_get_context(ts), |
133 | path, | |
134 | "ctf", | |
135 | NULL, | |
136 | NULL, | |
137 | NULL); | |
138 | if (id < 0) { | |
139 | return NULL; | |
140 | } | |
141 | // Create the trace and save the trace handle id returned by babeltrace | |
142 | LttvTrace *new_trace; | |
2bc1bcfb | 143 | |
9a366873 FD |
144 | new_trace = g_new(LttvTrace, 1); |
145 | new_trace->a = g_object_new(LTTV_ATTRIBUTE_TYPE, NULL); | |
146 | new_trace->id = id; | |
147 | new_trace->ref_count = 0; | |
148 | new_trace->traceset = ts; | |
149 | new_trace->state = g_new(LttvTraceState,1); | |
150 | lttv_trace_state_init(new_trace->state,new_trace); | |
115c78c2 | 151 | |
9a366873 FD |
152 | /* Add the state to the trace_handle to state index */ |
153 | g_ptr_array_set_size(ts->state_trace_handle_index,id+1); | |
154 | g_ptr_array_index(ts->state_trace_handle_index,id) = new_trace->state; | |
115c78c2 | 155 | |
9a366873 | 156 | return new_trace; |
2bc1bcfb | 157 | } |
158 | ||
159 | /* | |
160 | * lttv_trace_create : Create and add a single trace to a traceset | |
161 | * | |
162 | * ts is the traceset in which will be contained the trace | |
163 | * | |
164 | * path is the path where to find a trace. It is not recursive. | |
165 | * | |
166 | * return a positive integer (>=0)on success or -1 on failure | |
167 | */ | |
168 | static int lttv_traceset_create_trace(LttvTraceset *ts, const char *path) | |
169 | { | |
9a366873 FD |
170 | LttvTrace *trace = lttv_trace_create(ts, path); |
171 | if (trace == NULL) { | |
172 | return -1; | |
173 | } | |
174 | lttv_traceset_add(ts, trace); | |
175 | return 0; | |
2bc1bcfb | 176 | } |
308711e5 | 177 | |
f7afe191 | 178 | LttvTraceset *lttv_traceset_copy(LttvTraceset *s_orig) |
179 | { | |
90e19f82 AM |
180 | guint i; |
181 | LttvTraceset *s; | |
182 | LttvTrace * trace; | |
f7afe191 | 183 | |
90e19f82 AM |
184 | s = g_new(LttvTraceset, 1); |
185 | s->filename = NULL; | |
186 | s->traces = g_ptr_array_new(); | |
115c78c2 | 187 | s->state_trace_handle_index = g_ptr_array_new(); |
90e19f82 AM |
188 | for(i=0;i<s_orig->traces->len;i++) |
189 | { | |
190 | trace = g_ptr_array_index(s_orig->traces, i); | |
191 | trace->ref_count++; | |
2176f952 | 192 | |
7a4bdb54 | 193 | /* WARNING: this is an alias, not a copy. */ |
90e19f82 | 194 | g_ptr_array_add(s->traces, trace); |
115c78c2 YB |
195 | |
196 | g_ptr_array_set_size(s->state_trace_handle_index,trace->id+1); | |
197 | g_ptr_array_index(s->state_trace_handle_index,trace->id) = trace->state; | |
198 | ||
90e19f82 | 199 | } |
cbb811b3 YB |
200 | s->context = s_orig->context; |
201 | bt_context_get(s->context); | |
90e19f82 AM |
202 | s->a = LTTV_ATTRIBUTE(lttv_iattribute_deep_copy(LTTV_IATTRIBUTE(s_orig->a))); |
203 | return s; | |
f7afe191 | 204 | } |
dc877563 | 205 | |
f7afe191 | 206 | |
207 | LttvTraceset *lttv_traceset_load(const gchar *filename) | |
208 | { | |
90e19f82 AM |
209 | LttvTraceset *s = g_new(LttvTraceset,1); |
210 | FILE *tf; | |
f7afe191 | 211 | |
90e19f82 AM |
212 | s->filename = g_strdup(filename); |
213 | tf = fopen(filename,"r"); | |
214 | ||
215 | g_critical("NOT IMPLEMENTED : load traceset data from a XML file"); | |
216 | ||
217 | fclose(tf); | |
218 | return s; | |
f7afe191 | 219 | } |
220 | ||
221 | gint lttv_traceset_save(LttvTraceset *s) | |
222 | { | |
90e19f82 | 223 | FILE *tf; |
f7afe191 | 224 | |
90e19f82 | 225 | tf = fopen(s->filename, "w"); |
f7afe191 | 226 | |
90e19f82 AM |
227 | g_critical("NOT IMPLEMENTED : save traceset data in a XML file"); |
228 | ||
229 | fclose(tf); | |
230 | return 0; | |
f7afe191 | 231 | } |
308711e5 | 232 | |
ba576a78 | 233 | void lttv_traceset_destroy(LttvTraceset *s) |
dc877563 | 234 | { |
90e19f82 | 235 | guint i; |
5e2c04a2 | 236 | |
90e19f82 AM |
237 | for(i=0;i<s->traces->len;i++) { |
238 | LttvTrace *trace = g_ptr_array_index(s->traces, i); | |
239 | lttv_trace_unref(trace); | |
2bc1bcfb | 240 | // todo mdenis 2012-03-27: uncomment when babeltrace gets fixed |
241 | //bt_context_remove_trace(lttv_traceset_get_context(s), trace->id); | |
90e19f82 AM |
242 | if(lttv_trace_get_ref_number(trace) == 0) |
243 | lttv_trace_destroy(trace); | |
244 | } | |
245 | g_ptr_array_free(s->traces, TRUE); | |
cbb811b3 | 246 | bt_context_put(s->context); |
90e19f82 AM |
247 | g_object_unref(s->a); |
248 | g_free(s); | |
dc877563 | 249 | } |
250 | ||
922581a4 YB |
251 | struct bt_context *lttv_traceset_get_context(LttvTraceset *s) |
252 | { | |
253 | return s->context; | |
254 | } | |
255 | ||
7a4bdb54 YB |
256 | LttvTraceset *lttv_trace_get_traceset(LttvTrace *trace) |
257 | { | |
258 | return trace->traceset; | |
259 | } | |
260 | ||
261 | LttvHooks *lttv_traceset_get_hooks(LttvTraceset *s) | |
262 | { | |
263 | return s->event_hooks; | |
264 | } | |
265 | ||
308711e5 | 266 | void lttv_trace_destroy(LttvTrace *t) |
267 | { | |
90e19f82 AM |
268 | g_object_unref(t->a); |
269 | g_free(t); | |
308711e5 | 270 | } |
271 | ||
308711e5 | 272 | void lttv_traceset_add(LttvTraceset *s, LttvTrace *t) |
dc877563 | 273 | { |
90e19f82 AM |
274 | t->ref_count++; |
275 | g_ptr_array_add(s->traces, t); | |
dc877563 | 276 | } |
277 | ||
3685e022 | 278 | int lttv_traceset_add_path(LttvTraceset *ts, char *trace_path) |
2bc1bcfb | 279 | { |
3685e022 | 280 | FTS *tree; |
281 | FTSENT *node; | |
282 | char * const paths[2] = { trace_path, NULL }; | |
283 | int ret = -1; | |
861fbe5f FD |
284 | |
285 | gboolean metaFileFound = FALSE; | |
451aaf27 | 286 | |
3685e022 | 287 | tree = fts_open(paths, FTS_NOCHDIR | FTS_LOGICAL, 0); |
288 | if (tree == NULL) { | |
289 | g_warning("Cannot traverse \"%s\" for reading.\n", | |
290 | trace_path); | |
291 | return ret; | |
292 | } | |
293 | ||
294 | int dirfd, metafd; | |
295 | while ((node = fts_read(tree))) { | |
296 | ||
297 | if (!(node->fts_info & FTS_D)) | |
298 | continue; | |
299 | ||
300 | dirfd = open(node->fts_accpath, 0); | |
301 | if (dirfd < 0) { | |
302 | g_warning("Unable to open trace " | |
303 | "directory file descriptor : %s.", node->fts_accpath); | |
304 | ret = dirfd; | |
305 | goto error; | |
306 | } | |
307 | ||
308 | // Check if a metadata file exists in the current directory | |
309 | metafd = openat(dirfd, "metadata", O_RDONLY); | |
310 | if (metafd < 0) { | |
311 | ret = close(dirfd); | |
312 | if (ret < 0) { | |
313 | g_warning("Unable to open metadata " | |
314 | "file descriptor : %s.", node->fts_accpath); | |
315 | goto error; | |
316 | } | |
317 | } else { | |
318 | ret = close(metafd); | |
319 | if (ret < 0) { | |
320 | g_warning("Unable to close metadata " | |
321 | "file descriptor : %s.", node->fts_accpath); | |
322 | goto error; | |
323 | } | |
324 | ret = close(dirfd); | |
325 | if (ret < 0) { | |
326 | g_warning("Unable to close trace " | |
327 | "directory file descriptor : %s.", node->fts_accpath); | |
328 | goto error; | |
329 | } | |
330 | ||
331 | ret = lttv_traceset_create_trace(ts, node->fts_accpath); | |
332 | if (ret < 0) { | |
333 | g_warning("Opening trace \"%s\" from %s " | |
334 | "for reading.", node->fts_accpath, trace_path); | |
335 | goto error; | |
336 | } | |
861fbe5f | 337 | metaFileFound = TRUE; |
3685e022 | 338 | } |
339 | } | |
340 | ||
341 | error: | |
342 | ret = fts_close(tree); | |
343 | if (ret < 0) { | |
344 | g_warning("Unable to close tree " | |
345 | "file descriptor : %s.", trace_path); | |
346 | } | |
861fbe5f FD |
347 | if(metaFileFound) |
348 | return ret; | |
349 | else | |
350 | return -1; | |
2bc1bcfb | 351 | } |
dc877563 | 352 | |
861fbe5f | 353 | |
dc877563 | 354 | unsigned lttv_traceset_number(LttvTraceset *s) |
355 | { | |
90e19f82 | 356 | return s->traces->len; |
dc877563 | 357 | } |
358 | ||
359 | ||
308711e5 | 360 | LttvTrace *lttv_traceset_get(LttvTraceset *s, unsigned i) |
dc877563 | 361 | { |
90e19f82 AM |
362 | g_assert(s->traces->len > i); |
363 | return ((LttvTrace *)s->traces->pdata[i]); | |
dc877563 | 364 | } |
365 | ||
366 | ||
ba576a78 | 367 | void lttv_traceset_remove(LttvTraceset *s, unsigned i) |
dc877563 | 368 | { |
90e19f82 AM |
369 | LttvTrace * t; |
370 | g_assert(s->traces->len > i); | |
371 | t = (LttvTrace *)s->traces->pdata[i]; | |
372 | t->ref_count--; | |
2bc1bcfb | 373 | bt_context_remove_trace(lttv_traceset_get_context(s), t->id); |
90e19f82 | 374 | g_ptr_array_remove_index(s->traces, i); |
dc877563 | 375 | } |
376 | ||
377 | ||
378 | /* A set of attributes is attached to each trace set, trace and tracefile | |
90e19f82 | 379 | to store user defined data as needed. */ |
dc877563 | 380 | |
381 | LttvAttribute *lttv_traceset_attribute(LttvTraceset *s) | |
382 | { | |
90e19f82 | 383 | return s->a; |
dc877563 | 384 | } |
385 | ||
386 | ||
308711e5 | 387 | LttvAttribute *lttv_trace_attribute(LttvTrace *t) |
388 | { | |
90e19f82 | 389 | return t->a; |
308711e5 | 390 | } |
391 | ||
2bc1bcfb | 392 | |
393 | gint lttv_trace_get_id(LttvTrace *t) | |
394 | { | |
9a366873 | 395 | return t->id; |
2bc1bcfb | 396 | } |
308711e5 | 397 | |
2176f952 | 398 | guint lttv_trace_get_ref_number(LttvTrace * t) |
399 | { | |
2bc1bcfb | 400 | // todo mdenis: adapt to babeltrace |
90e19f82 | 401 | return t->ref_count; |
2176f952 | 402 | } |
a43d67ba | 403 | |
404 | guint lttv_trace_ref(LttvTrace * t) | |
405 | { | |
90e19f82 AM |
406 | t->ref_count++; |
407 | ||
408 | return t->ref_count; | |
a43d67ba | 409 | } |
410 | ||
411 | guint lttv_trace_unref(LttvTrace * t) | |
412 | { | |
90e19f82 AM |
413 | if(likely(t->ref_count > 0)) |
414 | t->ref_count--; | |
a43d67ba | 415 | |
90e19f82 | 416 | return t->ref_count; |
a43d67ba | 417 | } |
418 | ||
7a4bdb54 YB |
419 | guint lttv_trace_get_num_cpu(LttvTrace *t) |
420 | { | |
421 | #warning "TODO - Set the right number of CPU" | |
422 | return 24; | |
423 | } | |
424 | ||
68573dd0 | 425 | LttvTracesetPosition *lttv_traceset_create_current_position(LttvTraceset *traceset) |
7a4bdb54 | 426 | { |
3d1e7ee5 YB |
427 | LttvTracesetPosition *traceset_pos; |
428 | ||
429 | traceset_pos = g_new(LttvTracesetPosition, 1); | |
430 | ||
9a366873 | 431 | /* Check if the new passed */ |
3d1e7ee5 YB |
432 | if(traceset_pos == NULL) { |
433 | return NULL; | |
434 | } | |
435 | ||
436 | traceset_pos->iter = traceset->iter; | |
437 | traceset_pos->bt_pos = bt_iter_get_pos(bt_ctf_get_iter(traceset->iter)); | |
438 | ||
439 | return traceset_pos; | |
7a4bdb54 YB |
440 | } |
441 | ||
9a366873 FD |
442 | LttvTracesetPosition *lttv_traceset_create_time_position(LttvTraceset *traceset, |
443 | LttTime timestamp) | |
444 | { | |
445 | LttvTracesetPosition *traceset_pos; | |
446 | ||
447 | traceset_pos = g_new(LttvTracesetPosition, 1); | |
448 | ||
449 | /* Check if the new passed */ | |
450 | if(traceset_pos == NULL) { | |
451 | return NULL; | |
452 | } | |
453 | ||
454 | traceset_pos->iter = traceset->iter; | |
455 | traceset_pos->bt_pos = bt_iter_create_time_pos( | |
456 | bt_ctf_get_iter(traceset_pos->iter), | |
457 | ltt_time_to_uint64(timestamp)); | |
458 | ||
459 | return traceset_pos; | |
460 | } | |
461 | ||
7a4bdb54 YB |
462 | void lttv_traceset_destroy_position(LttvTracesetPosition *traceset_pos) |
463 | { | |
3d1e7ee5 YB |
464 | bt_iter_free_pos(traceset_pos->bt_pos); |
465 | g_free(traceset_pos); | |
7a4bdb54 YB |
466 | } |
467 | ||
9a366873 | 468 | void lttv_traceset_seek_to_position(const LttvTracesetPosition *traceset_pos) |
7a4bdb54 | 469 | { |
9a366873 | 470 | bt_iter_set_pos(bt_ctf_get_iter(traceset_pos->iter), traceset_pos->bt_pos); |
7a4bdb54 YB |
471 | } |
472 | ||
473 | guint lttv_traceset_get_cpuid_from_event(LttvEvent *event) | |
474 | { | |
7a4bdb54 YB |
475 | unsigned long timestamp; |
476 | unsigned int cpu_id; | |
477 | ||
478 | struct bt_ctf_event *ctf_event = event->bt_event; | |
479 | timestamp = bt_ctf_get_timestamp(ctf_event); | |
480 | if (timestamp == -1ULL) { | |
481 | return 0; | |
482 | } | |
9a366873 | 483 | const struct definition *scope = bt_ctf_get_top_level_scope(ctf_event, BT_STREAM_PACKET_CONTEXT); |
7a4bdb54 YB |
484 | if (bt_ctf_field_get_error()) { |
485 | return 0; | |
486 | } | |
487 | cpu_id = bt_ctf_get_uint64(bt_ctf_get_field(ctf_event, scope, "cpu_id")); | |
488 | if (bt_ctf_field_get_error()) { | |
489 | return 0; | |
490 | } else { | |
491 | return cpu_id; | |
492 | } | |
493 | } | |
9a366873 FD |
494 | |
495 | guint64 lttv_traceset_get_timestamp_first_event(LttvTraceset *ts) | |
496 | { | |
497 | LttvTracesetPosition begin_position; | |
498 | struct bt_iter_pos pos; | |
499 | begin_position.bt_pos = &pos; | |
500 | ||
501 | /* Assign iterator to the beginning of the traces */ | |
502 | begin_position.bt_pos->type = BT_SEEK_BEGIN; | |
503 | begin_position.iter = ts->iter; | |
504 | ||
505 | return lttv_traceset_position_get_timestamp(&begin_position); | |
506 | } | |
507 | ||
451aaf27 FD |
508 | /* |
509 | * lttv_traceset_get_timestamp_begin : returns the minimum timestamp of | |
510 | * all the traces in the traceset. | |
511 | * | |
512 | */ | |
451aaf27 FD |
513 | guint64 lttv_traceset_get_timestamp_begin(LttvTraceset *traceset) |
514 | { | |
9a366873 FD |
515 | struct bt_context *bt_ctx; |
516 | bt_ctx = lttv_traceset_get_context(traceset); | |
517 | guint64 timestamp_min, timestamp_cur = 0; | |
518 | int i; | |
519 | int trace_count; | |
520 | LttvTrace *currentTrace; | |
521 | trace_count = traceset->traces->len; | |
522 | if(trace_count == 0) | |
523 | timestamp_min = 0; | |
524 | else{ | |
525 | timestamp_min = G_MAXUINT64; | |
526 | for(i = 0; i < trace_count;i++) | |
527 | { | |
528 | currentTrace = g_ptr_array_index(traceset->traces,i); | |
529 | timestamp_cur = bt_trace_handle_get_timestamp_begin(bt_ctx, | |
530 | currentTrace->id); | |
531 | if(timestamp_cur < timestamp_min) | |
532 | timestamp_min = timestamp_cur; | |
533 | } | |
534 | } | |
535 | return timestamp_min; | |
451aaf27 FD |
536 | } |
537 | ||
538 | /* | |
539 | * lttv_traceset_get_timestamp_end: returns the maximum timestamp of | |
540 | * all the traces in the traceset. | |
541 | * | |
542 | */ | |
543 | guint64 lttv_traceset_get_timestamp_end(LttvTraceset *traceset) | |
544 | { | |
9a366873 FD |
545 | struct bt_context *bt_ctx; |
546 | bt_ctx = lttv_traceset_get_context(traceset); | |
547 | guint64 timestamp_max, timestamp_cur = 0; | |
548 | int i; | |
549 | int trace_count; | |
550 | LttvTrace *currentTrace; | |
551 | trace_count = traceset->traces->len; | |
552 | ||
553 | if(trace_count == 0){ | |
554 | timestamp_max = 1; | |
555 | } | |
556 | else{ | |
557 | timestamp_max = 0; | |
558 | for(i =0; i < trace_count;i++) | |
559 | { | |
560 | currentTrace = g_ptr_array_index(traceset->traces,i); | |
561 | timestamp_cur = bt_trace_handle_get_timestamp_end(bt_ctx, | |
562 | currentTrace->id); | |
563 | if(timestamp_cur > timestamp_max){ | |
564 | timestamp_max = timestamp_cur; | |
565 | } | |
566 | } | |
567 | } | |
568 | return timestamp_max; | |
569 | } | |
570 | /* | |
571 | * lttv_traceset_get_time_span_real : return a TimeInterval representing the | |
572 | * minimum timestamp dans le maximum timestamp of the traceset. | |
573 | * | |
574 | */ | |
575 | TimeInterval lttv_traceset_get_time_span_real(LttvTraceset *ts) | |
576 | { | |
577 | TimeInterval time_span; | |
578 | time_span.start_time =ltt_time_from_uint64(lttv_traceset_get_timestamp_first_event(ts)); | |
579 | time_span.end_time = ltt_time_from_uint64(lttv_traceset_get_timestamp_end(ts)); | |
580 | return time_span; | |
9aaa78dc FD |
581 | } |
582 | ||
583 | /* | |
584 | * lttv_traceset_get_time_span : return a TimeInterval representing the | |
585 | * minimum timestamp dans le maximum timestamp of the traceset. | |
586 | * | |
587 | */ | |
588 | TimeInterval lttv_traceset_get_time_span(LttvTraceset *ts) | |
589 | { | |
590 | TimeInterval time_span; | |
9a366873 | 591 | time_span.start_time =ltt_time_from_uint64(lttv_traceset_get_timestamp_begin(ts)); |
9aaa78dc FD |
592 | time_span.end_time = ltt_time_from_uint64(lttv_traceset_get_timestamp_end(ts)); |
593 | return time_span; | |
451aaf27 | 594 | } |
7a4bdb54 YB |
595 | |
596 | const char *lttv_traceset_get_name_from_event(LttvEvent *event) | |
597 | { | |
598 | return bt_ctf_event_name(event->bt_event); | |
599 | } | |
9a366873 FD |
600 | |
601 | guint64 lttv_traceset_position_get_timestamp(const LttvTracesetPosition *pos) | |
602 | { | |
603 | guint64 timestamp = 0; | |
604 | /*We save the current iterator,so we can reassign it after the seek*/ | |
605 | LttvTracesetPosition previous_pos; | |
606 | previous_pos.iter = pos->iter; | |
607 | previous_pos.bt_pos = bt_iter_get_pos(bt_ctf_get_iter(pos->iter)); | |
608 | /* Seek to the new desired position */ | |
609 | lttv_traceset_seek_to_position(pos); | |
610 | /*Read the event*/ | |
611 | struct bt_ctf_event *event = bt_ctf_iter_read_event(pos->iter); | |
612 | ||
613 | if(event != NULL){ | |
614 | timestamp = bt_ctf_get_timestamp_raw(event); | |
615 | } | |
616 | /* Reassign the previously saved position */ | |
617 | lttv_traceset_seek_to_position(&previous_pos); | |
618 | return timestamp; | |
619 | } | |
620 | ||
621 | LttTime lttv_traceset_position_get_time(const LttvTracesetPosition *pos) | |
622 | { | |
623 | return ltt_time_from_uint64(lttv_traceset_position_get_timestamp(pos)); | |
624 | } | |
625 | ||
ff5c41f1 YB |
626 | |
627 | ||
9a366873 FD |
628 | int lttv_traceset_position_compare(const LttvTracesetPosition *pos1, const LttvTracesetPosition *pos2) |
629 | { | |
630 | #warning " TODO :Rename for lttv_traceset_position_equals && Must return COMPARAISON OF THE 2 POSITION && verify if it is the best way to compare position" | |
631 | if(pos1 == NULL || pos2 == NULL){ | |
632 | return -1; | |
633 | } | |
634 | ||
635 | guint64 timeStampPos1,timeStampPos2; | |
636 | guint cpuId1, cpuId2; | |
637 | LttvEvent event1, event2; | |
638 | int ret; | |
639 | ||
640 | timeStampPos1 = lttv_traceset_position_get_timestamp(pos1); | |
641 | timeStampPos2 = lttv_traceset_position_get_timestamp(pos2); | |
642 | ||
643 | event1.bt_event = bt_ctf_iter_read_event(pos1->iter); | |
644 | event2.bt_event = bt_ctf_iter_read_event(pos2->iter); | |
645 | ||
646 | if(event1.bt_event == NULL || event2.bt_event == NULL){ | |
647 | return -1; | |
648 | } | |
649 | ||
650 | cpuId1 = lttv_traceset_get_cpuid_from_event(&event1); | |
651 | cpuId2 = lttv_traceset_get_cpuid_from_event(&event2); | |
652 | ||
653 | if(timeStampPos1 == timeStampPos2 && cpuId1 == cpuId2){ | |
654 | return 0; | |
655 | } | |
656 | else{ | |
657 | return 1; | |
658 | } | |
659 | } | |
ff5c41f1 YB |
660 | |
661 | int lttv_traceset_position_time_compare(const LttvTracesetPosition *pos1, | |
662 | const LttvTracesetPosition *pos2) | |
663 | { | |
664 | guint64 timeStampPos1,timeStampPos2; | |
665 | ||
666 | timeStampPos1 = lttv_traceset_position_get_timestamp(pos1); | |
667 | timeStampPos2 = lttv_traceset_position_get_timestamp(pos2); | |
668 | ||
669 | return timeStampPos1 - timeStampPos2; | |
670 | } | |
671 | int lttv_traceset_position_compare_current(const LttvTraceset *ts, | |
672 | const LttvTracesetPosition *pos) | |
673 | { | |
674 | int result = 0; | |
675 | LttvTracesetPosition *curPos = lttv_traceset_create_current_position(ts); | |
676 | ||
677 | result = lttv_traceset_position_compare(curPos,pos); | |
678 | ||
679 | lttv_traceset_destroy_position(curPos); | |
680 | ||
681 | return result; | |
682 | } | |
683 | ||
684 | LttTime lttv_traceset_get_current_time(const LttvTraceset *ts) | |
685 | { | |
686 | LttvTracesetPosition *curPos = lttv_traceset_create_current_position(ts); | |
687 | guint64 currentTimestamp = lttv_traceset_position_get_timestamp(curPos); | |
688 | lttv_traceset_destroy_position(curPos); | |
689 | ||
690 | return ltt_time_from_uint64(currentTimestamp); | |
691 | } |