X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=lttv%2Flttv%2Ftraceset-process.c;h=dc45b17d3a88c043f23f5bdfed06ceae150b7f4f;hb=993046ef12d5b804119ef2f742cb7fa2f9835218;hp=54a68c07777d85e891b305352342dbd96a953803;hpb=58b4e4ae6fe118dbf6b441692eae833df2229d3e;p=lttv.git diff --git a/lttv/lttv/traceset-process.c b/lttv/lttv/traceset-process.c index 54a68c07..dc45b17d 100644 --- a/lttv/lttv/traceset-process.c +++ b/lttv/lttv/traceset-process.c @@ -74,7 +74,7 @@ guint lttv_process_traceset_middle(LttvTraceset *traceset, if((bt_event = bt_ctf_iter_read_event(traceset->iter)) != NULL) { - LttTime time = ltt_time_from_uint64(bt_ctf_get_timestamp_raw(bt_event)); + LttTime time = ltt_time_from_uint64(bt_ctf_get_timestamp(bt_event)); if(ltt_time_compare(end, time) <= 0) { break; } @@ -238,8 +238,13 @@ guint lttv_process_traceset_seek_n_backward(LttvTraceset *ts, guint i, count, ret; gint extraEvent = 0; guint64 initialTimeStamp, previousTimeStamp; - LttvTracesetPosition *initialPos, *previousPos, *currentPos; - + LttvTracesetPosition *initialPos, *previousPos, *currentPos, beginPos; + struct bt_iter_pos pos; + beginPos.bt_pos = &pos; + beginPos.iter = ts->iter; + beginPos.bt_pos->type = BT_SEEK_BEGIN; + beginPos.timestamp = G_MAXUINT64; + beginPos.cpu_id = INT_MAX; /*Save initial position of the traceset*/ initialPos = lttv_traceset_create_current_position (ts); @@ -258,22 +263,39 @@ guint lttv_process_traceset_seek_n_backward(LttvTraceset *ts, break; currentPos = lttv_traceset_create_time_position(ts,ltt_time_from_uint64(previousTimeStamp)); + /*Corner case: When we are near the beginning of the trace and the previousTimeStamp is before + * the beginning of the trace. We have to seek to the first event. + */ + if((lttv_traceset_position_compare(currentPos,&beginPos ) == 0)){ + lttv_traceset_seek_to_position(&beginPos); + break; + } /*move traceset position */ lttv_state_traceset_seek_position(ts, previousPos); /* iterate to the initial position counting the number of event*/ count = 0; do { if((ret = lttv_traceset_position_compare(currentPos,initialPos)) == 1){ - bt_iter_next(bt_ctf_get_iter(ts->iter)); - lttv_traceset_destroy_position(currentPos); - currentPos = lttv_traceset_create_current_position(ts); - count++; + if(bt_iter_next(bt_ctf_get_iter(ts->iter)) == 0) { + if(bt_ctf_iter_read_event(ts->iter) != NULL) { + lttv_traceset_destroy_position(currentPos); + currentPos = lttv_traceset_create_current_position(ts); + count++; + } else { + break; + } + + } else { + + //No more event available + break; + } } }while(ret != 0); - lttv_traceset_destroy_position(currentPos); + /*substract the desired number of event to the count*/ extraEvent = count - n; - if(extraEvent >= 0){ + if (extraEvent >= 0) { //if the extraEvent is over 0 go back to previousPos and //move forward the value of extraEvent times lttv_state_traceset_seek_position(ts, previousPos); @@ -287,9 +309,11 @@ guint lttv_process_traceset_seek_n_backward(LttvTraceset *ts, } break; /* we successfully seeked backward */ } - else{ /* if the extraEvent is below 0 create a position before and start over*/ - ratio = ratio * 16; + else{ + /* if the extraEvent is below 0 create a position before and start over*/ + ratio = ratio * 16; } + lttv_traceset_destroy_position(currentPos); } return 0; }