1 /* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Michel Dagenais
3 * Copyright (C) 2012 Yannick Brosseau
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License Version 2 as
7 * published by the Free Software Foundation;
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
23 #include <lttv/traceset-process.h>
24 #include <lttv/traceset.h>
25 #include <lttv/event.h>
26 #include <babeltrace/context.h>
27 #include <babeltrace/iterator.h>
28 #include <babeltrace/trace-handle.h>
29 #include <babeltrace/ctf/events.h>
30 #include <babeltrace/ctf/iterator.h>
32 void lttv_process_traceset_begin(LttvTraceset
*traceset
,
33 LttvHooks
*before_traceset
,
34 LttvHooks
*before_trace
,
37 struct bt_iter_pos begin_pos
;
38 /* simply add hooks in context. _before hooks are called by add_hooks. */
39 /* It calls all before_traceset, before_trace, and before_tracefile hooks. */
40 lttv_traceset_add_hooks(traceset
,
47 begin_pos
.type
= BT_SEEK_BEGIN
;
50 traceset
->iter
= bt_ctf_iter_create(lttv_traceset_get_context(traceset
),
56 guint
lttv_process_traceset_middle(LttvTraceset
*traceset
,
59 const LttvTracesetPosition
*end_position
)
63 LttvTracesetPosition
*currentPos
;
65 struct bt_ctf_event
*bt_event
;
71 if(last_ret
== TRUE
|| ((count
>= nb_events
) && (nb_events
!= G_MAXULONG
))) {
75 if((bt_event
= bt_ctf_iter_read_event(traceset
->iter
)) != NULL
) {
77 LttTime time
= ltt_time_from_uint64(bt_ctf_get_timestamp_raw(bt_event
));
78 if(ltt_time_compare(end
, time
) <= 0) {
82 currentPos
= lttv_traceset_create_current_position(traceset
);
83 if(lttv_traceset_position_compare(currentPos
,end_position
) == 0){
84 lttv_traceset_destroy_position(currentPos
);
87 lttv_traceset_destroy_position(currentPos
);
90 event
.bt_event
= bt_event
;
92 /* Retreive the associated state */
93 event
.state
= g_ptr_array_index(traceset
->state_trace_handle_index
,
94 bt_ctf_event_get_handle_id(bt_event
));
96 last_ret
= lttv_hooks_call(traceset
->event_hooks
, &event
);
98 if(bt_iter_next(bt_ctf_get_iter(traceset
->iter
)) < 0) {
99 printf("ERROR NEXT\n");
112 void lttv_process_traceset_end(LttvTraceset
*traceset
,
113 LttvHooks
*after_traceset
,
114 LttvHooks
*after_trace
,
117 /* Remove hooks from context. _after hooks are called by remove_hooks. */
118 /* It calls all after_traceset, after_trace, and after_tracefile hooks. */
119 lttv_traceset_remove_hooks(traceset
,
127 void lttv_traceset_add_hooks(LttvTraceset
*traceset
,
128 LttvHooks
*before_traceset
,
129 LttvHooks
*before_trace
,
136 lttv_hooks_call(before_traceset
, traceset
);
138 lttv_hooks_add_list(traceset
->event_hooks
, event
);
140 nb_trace
= lttv_traceset_number(traceset
);
142 for(i
= 0 ; i
< nb_trace
; i
++) {
143 trace
= (LttvTrace
*)g_ptr_array_index(traceset
->traces
,i
);
144 lttv_trace_add_hooks(trace
,
150 void lttv_traceset_remove_hooks(LttvTraceset
*traceset
,
151 LttvHooks
*after_traceset
,
152 LttvHooks
*after_trace
,
159 nb_trace
= lttv_traceset_number(traceset
);
161 for(i
= 0 ; i
< nb_trace
; i
++) {
162 trace
= (LttvTrace
*)g_ptr_array_index(traceset
->traces
,i
);
163 lttv_trace_remove_hooks(trace
,
169 lttv_hooks_remove_list(traceset
->event_hooks
, event
);
170 lttv_hooks_call(after_traceset
, traceset
);
176 void lttv_trace_add_hooks(LttvTrace
*trace
,
177 LttvHooks
*before_trace
,
180 lttv_hooks_call(before_trace
, trace
);
183 void lttv_trace_remove_hooks(LttvTrace
*trace
,
184 LttvHooks
*after_trace
,
188 lttv_hooks_call(after_trace
, trace
);
191 void lttv_process_traceset_seek_time(LttvTraceset
*traceset
, LttTime start
)
193 struct bt_iter_pos seekpos
;
195 if (traceset
->iter
== NULL
) {
196 g_warning("Iterator not valid in seek_time");
199 seekpos
.type
= BT_SEEK_TIME
;
200 seekpos
.u
.seek_time
= ltt_time_to_uint64(start
);
202 ret
= bt_iter_set_pos(bt_ctf_get_iter(traceset
->iter
), &seekpos
);
204 printf("Seek by time error: %s,\n",strerror(-ret
));
208 guint
lttv_process_traceset_seek_n_forward(LttvTraceset
*traceset
,
210 check_handler
*check
,
219 if(bt_iter_next(bt_ctf_get_iter(traceset
->iter
)) < 0) {
220 printf("ERROR NEXT\n");
228 guint
lttv_process_traceset_seek_n_backward(LttvTraceset
*ts
,
231 check_handler
*check
,
240 guint64 initialTimeStamp
, previousTimeStamp
;
241 LttvTracesetPosition
*initialPos
, *previousPos
, *currentPos
;
243 /*Save initial position of the traceset*/
244 initialPos
= lttv_traceset_create_current_position (ts
);
246 /*Get the timespan of the initial position*/
247 initialTimeStamp
= lttv_traceset_position_get_timestamp(initialPos
);
249 * Create a position before the initial timestamp according
250 * to the ratio of nanosecond/event hopefully before the
251 * the desired seek position
254 previousTimeStamp
= initialTimeStamp
- n
*(guint
)ceil(ratio
);
256 previousPos
= lttv_traceset_create_time_position(ts
,ltt_time_from_uint64(previousTimeStamp
));
257 if(initialTimeStamp
== previousTimeStamp
)
260 currentPos
= lttv_traceset_create_time_position(ts
,ltt_time_from_uint64(previousTimeStamp
));
261 /*move traceset position */
262 lttv_state_traceset_seek_position(ts
, previousPos
);
263 /* iterate to the initial position counting the number of event*/
266 if((ret
= lttv_traceset_position_compare(currentPos
,initialPos
)) == 1){
267 bt_iter_next(bt_ctf_get_iter(ts
->iter
));
268 lttv_traceset_destroy_position(currentPos
);
269 currentPos
= lttv_traceset_create_current_position(ts
);
273 lttv_traceset_destroy_position(currentPos
);
274 /*substract the desired number of event to the count*/
275 extraEvent
= count
- n
;
277 //if the extraEvent is over 0 go back to previousPos and
278 //move forward the value of extraEvent times
279 lttv_state_traceset_seek_position(ts
, previousPos
);
281 for(i
= 0 ; i
< extraEvent
; i
++){
282 if(bt_iter_next(bt_ctf_get_iter(ts
->iter
)) < 0){
283 printf("ERROR NEXT\n");
288 break; /* we successfully seeked backward */
290 else{ /* if the extraEvent is below 0 create a position before and start over*/
This page took 0.040747 seconds and 5 git commands to generate.