X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=lttv%2Flttv%2Ftraceset-process.c;h=b49542f9fb7aea400464c472fbb562f6931fdc49;hb=88bf15f0f2a239186b5cf6fcf8711786907ca483;hp=edb7463b3453ade3c6d6a2075c5990c9730010be;hpb=68573dd0176817ad827ed9e292faaa933f0093bc;p=lttv.git diff --git a/lttv/lttv/traceset-process.c b/lttv/lttv/traceset-process.c index edb7463b..b49542f9 100644 --- a/lttv/lttv/traceset-process.c +++ b/lttv/lttv/traceset-process.c @@ -238,8 +238,11 @@ 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; /*Save initial position of the traceset*/ initialPos = lttv_traceset_create_current_position (ts); @@ -258,8 +261,15 @@ 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_traceset_seek_to_position(previousPos); + lttv_state_traceset_seek_position(ts, previousPos); /* iterate to the initial position counting the number of event*/ count = 0; do { @@ -270,13 +280,13 @@ guint lttv_process_traceset_seek_n_backward(LttvTraceset *ts, count++; } }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_traceset_seek_to_position(previousPos); + lttv_state_traceset_seek_position(ts, previousPos); for(i = 0 ; i < extraEvent ; i++){ if(bt_iter_next(bt_ctf_get_iter(ts->iter)) < 0){ @@ -287,9 +297,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; }