Update FSF address
[lttv.git] / lttv / lttv / traceset-process.c
index edb7463b3453ade3c6d6a2075c5990c9730010be..ef9d80a8a5c310cdc50cdaa8b08e9d8c5dfc44d7 100644 (file)
@@ -13,8 +13,8 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, 
- * MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
+ * MA 02110-1301, USA.
  */
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -60,12 +60,16 @@ guint lttv_process_traceset_middle(LttvTraceset *traceset,
 {
        unsigned count = 0;
        gint last_ret = 0;
-       LttvTracesetPosition *currentPos;
         
        struct bt_ctf_event *bt_event;
        
        LttvEvent event;
-  
+       LttTime endPositionTime;
+
+       //TODO ybrosseau 2013-10-17: Compare with end_position directly when its possible
+       if(end_position) {
+               endPositionTime = lttv_traceset_position_get_time(end_position);
+       }
        while(TRUE) {
 
                if(last_ret == TRUE || ((count >= nb_events) && (nb_events != G_MAXULONG))) {
@@ -74,22 +78,19 @@ 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;
                        }
-                       
-                       currentPos = lttv_traceset_create_current_position(traceset);
-                       if(lttv_traceset_position_compare(currentPos,end_position ) == 0){
-                               lttv_traceset_destroy_position(currentPos);
+                       //TODO ybrosseau 2013-10-17: Compare with end_position directly when its possible
+                       if(end_position && (ltt_time_compare(endPositionTime, time) <= 0)) {
                                break;
                        }
-                       lttv_traceset_destroy_position(currentPos);
                        count++;
 
                        event.bt_event = bt_event;
 
-                       /* Retreive the associated state */
+                       /* Retrieve the associated state */
                        event.state = g_ptr_array_index(traceset->state_trace_handle_index,
                                                        bt_ctf_event_get_handle_id(bt_event));
                        
@@ -238,8 +239,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,25 +264,42 @@ 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 {
                         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) > 0) {
+                                               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_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 +310,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;
 }
This page took 0.024302 seconds and 4 git commands to generate.