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
)
64 struct bt_ctf_event
*bt_event
;
67 LttTime endPositionTime
;
69 //TODO ybrosseau 2013-10-17: Compare with end_position directly when its possible
71 endPositionTime
= lttv_traceset_position_get_time(end_position
);
75 if(last_ret
== TRUE
|| ((count
>= nb_events
) && (nb_events
!= G_MAXULONG
))) {
79 if((bt_event
= bt_ctf_iter_read_event(traceset
->iter
)) != NULL
) {
81 LttTime time
= ltt_time_from_uint64(bt_ctf_get_timestamp(bt_event
));
82 if(ltt_time_compare(end
, time
) <= 0) {
85 //TODO ybrosseau 2013-10-17: Compare with end_position directly when its possible
86 if(end_position
&& (ltt_time_compare(endPositionTime
, time
) <= 0)) {
91 event
.bt_event
= bt_event
;
93 /* Retrieve the associated state */
94 event
.state
= g_ptr_array_index(traceset
->state_trace_handle_index
,
95 bt_ctf_event_get_handle_id(bt_event
));
97 last_ret
= lttv_hooks_call(traceset
->event_hooks
, &event
);
99 if(bt_iter_next(bt_ctf_get_iter(traceset
->iter
)) < 0) {
100 printf("ERROR NEXT\n");
113 void lttv_process_traceset_end(LttvTraceset
*traceset
,
114 LttvHooks
*after_traceset
,
115 LttvHooks
*after_trace
,
118 /* Remove hooks from context. _after hooks are called by remove_hooks. */
119 /* It calls all after_traceset, after_trace, and after_tracefile hooks. */
120 lttv_traceset_remove_hooks(traceset
,
128 void lttv_traceset_add_hooks(LttvTraceset
*traceset
,
129 LttvHooks
*before_traceset
,
130 LttvHooks
*before_trace
,
137 lttv_hooks_call(before_traceset
, traceset
);
139 lttv_hooks_add_list(traceset
->event_hooks
, event
);
141 nb_trace
= lttv_traceset_number(traceset
);
143 for(i
= 0 ; i
< nb_trace
; i
++) {
144 trace
= (LttvTrace
*)g_ptr_array_index(traceset
->traces
,i
);
145 lttv_trace_add_hooks(trace
,
151 void lttv_traceset_remove_hooks(LttvTraceset
*traceset
,
152 LttvHooks
*after_traceset
,
153 LttvHooks
*after_trace
,
160 nb_trace
= lttv_traceset_number(traceset
);
162 for(i
= 0 ; i
< nb_trace
; i
++) {
163 trace
= (LttvTrace
*)g_ptr_array_index(traceset
->traces
,i
);
164 lttv_trace_remove_hooks(trace
,
170 lttv_hooks_remove_list(traceset
->event_hooks
, event
);
171 lttv_hooks_call(after_traceset
, traceset
);
177 void lttv_trace_add_hooks(LttvTrace
*trace
,
178 LttvHooks
*before_trace
,
181 lttv_hooks_call(before_trace
, trace
);
184 void lttv_trace_remove_hooks(LttvTrace
*trace
,
185 LttvHooks
*after_trace
,
189 lttv_hooks_call(after_trace
, trace
);
192 void lttv_process_traceset_seek_time(LttvTraceset
*traceset
, LttTime start
)
194 struct bt_iter_pos seekpos
;
196 if (traceset
->iter
== NULL
) {
197 g_warning("Iterator not valid in seek_time");
200 seekpos
.type
= BT_SEEK_TIME
;
201 seekpos
.u
.seek_time
= ltt_time_to_uint64(start
);
203 ret
= bt_iter_set_pos(bt_ctf_get_iter(traceset
->iter
), &seekpos
);
205 printf("Seek by time error: %s,\n",strerror(-ret
));
209 guint
lttv_process_traceset_seek_n_forward(LttvTraceset
*traceset
,
211 check_handler
*check
,
220 if(bt_iter_next(bt_ctf_get_iter(traceset
->iter
)) < 0) {
221 printf("ERROR NEXT\n");
229 guint
lttv_process_traceset_seek_n_backward(LttvTraceset
*ts
,
232 check_handler
*check
,
241 guint64 initialTimeStamp
, previousTimeStamp
;
242 LttvTracesetPosition
*initialPos
, *previousPos
, *currentPos
, beginPos
;
243 struct bt_iter_pos pos
;
244 beginPos
.bt_pos
= &pos
;
245 beginPos
.iter
= ts
->iter
;
246 beginPos
.bt_pos
->type
= BT_SEEK_BEGIN
;
247 beginPos
.timestamp
= G_MAXUINT64
;
248 beginPos
.cpu_id
= INT_MAX
;
249 /*Save initial position of the traceset*/
250 initialPos
= lttv_traceset_create_current_position (ts
);
252 /*Get the timespan of the initial position*/
253 initialTimeStamp
= lttv_traceset_position_get_timestamp(initialPos
);
255 * Create a position before the initial timestamp according
256 * to the ratio of nanosecond/event hopefully before the
257 * the desired seek position
260 previousTimeStamp
= initialTimeStamp
- n
*(guint
)ceil(ratio
);
262 previousPos
= lttv_traceset_create_time_position(ts
,ltt_time_from_uint64(previousTimeStamp
));
263 if(initialTimeStamp
== previousTimeStamp
)
266 currentPos
= lttv_traceset_create_time_position(ts
,ltt_time_from_uint64(previousTimeStamp
));
267 /*Corner case: When we are near the beginning of the trace and the previousTimeStamp is before
268 * the beginning of the trace. We have to seek to the first event.
270 if((lttv_traceset_position_compare(currentPos
,&beginPos
) == 0)){
271 lttv_traceset_seek_to_position(&beginPos
);
274 /*move traceset position */
275 lttv_state_traceset_seek_position(ts
, previousPos
);
276 /* iterate to the initial position counting the number of event*/
279 if((ret
= lttv_traceset_position_compare(currentPos
,initialPos
)) == 1){
280 if(bt_iter_next(bt_ctf_get_iter(ts
->iter
)) == 0) {
281 if(bt_ctf_iter_read_event(ts
->iter
) > 0) {
282 lttv_traceset_destroy_position(currentPos
);
283 currentPos
= lttv_traceset_create_current_position(ts
);
291 //No more event available
297 /*substract the desired number of event to the count*/
298 extraEvent
= count
- n
;
299 if (extraEvent
>= 0) {
300 //if the extraEvent is over 0 go back to previousPos and
301 //move forward the value of extraEvent times
302 lttv_state_traceset_seek_position(ts
, previousPos
);
304 for(i
= 0 ; i
< extraEvent
; i
++){
305 if(bt_iter_next(bt_ctf_get_iter(ts
->iter
)) < 0){
306 printf("ERROR NEXT\n");
311 break; /* we successfully seeked backward */
314 /* if the extraEvent is below 0 create a position before and start over*/
317 lttv_traceset_destroy_position(currentPos
);
This page took 0.037308 seconds and 4 git commands to generate.