Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
7ed2201f89865ce161868669422022630e4a6645
[simgrid.git] / src / mc / mc_compare.c
1 /* Copyright (c) 2008-2012 Da SimGrid Team. All rights reserved.            */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "mc_private.h"
7
8 #include "xbt/mmalloc.h"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_compare, mc,
11                                 "Logging specific to mc_compare");
12
13 static int heap_region_compare(void *d1, void *d2, size_t size);
14
15 static int is_heap_equality(xbt_dynar_t equals, void *a1, void *a2);
16 static size_t heap_ignore_size(void *address);
17
18 static void stack_region_free(stack_region_t s);
19 static void heap_equality_free(heap_equality_t e);
20
21 static int compare_local_variables(char *s1, char *s2);
22 static int compare_global_variables(int region_type, void *d1, void *d2);
23
24 static size_t heap_ignore_size(void *address){
25   unsigned int cursor = 0;
26   int start = 0;
27   int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
28   mc_heap_ignore_region_t region;
29
30   while(start <= end){
31     cursor = (start + end) / 2;
32     region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
33     if(region->address == address)
34       return region->size;
35     if(region->address < address)
36       start = cursor + 1;
37     if(region->address > address)
38       end = cursor - 1;   
39   }
40
41   return 0;
42 }
43
44 static int compare_global_variables(int region_type, void *d1, void *d2){
45
46   unsigned int cursor = 0;
47   size_t offset; 
48   int i = 0;
49   global_variable_t current_var; 
50   int pointer_align; 
51   void *addr_pointed1 = NULL, *addr_pointed2 = NULL;
52   int res_compare = 0;
53
54   if(region_type == 1){ /* libsimgrid */
55     xbt_dynar_foreach(mc_global_variables, cursor, current_var){
56       if(current_var->address < start_data_libsimgrid)
57         continue;
58       offset = (char *)current_var->address - (char *)start_data_libsimgrid;
59       i = 0;
60       while(i < current_var->size){
61         if(memcmp((char*)d1 + offset + i, (char*)d2 + offset + i, 1) != 0){
62           pointer_align = (i / sizeof(void*)) * sizeof(void*); 
63           addr_pointed1 = *((void **)((char *)d1 + offset + pointer_align));
64           addr_pointed2 = *((void **)((char *)d2 + offset + pointer_align));
65           if((addr_pointed1 > start_plt_libsimgrid && addr_pointed1 < end_plt_libsimgrid) 
66              || (addr_pointed2 > start_plt_libsimgrid && addr_pointed2 < end_plt_libsimgrid)){
67             i = current_var->size;
68             continue;
69           }else{
70             if((addr_pointed1 > std_heap) && ((char *)addr_pointed1 < (char *)std_heap + STD_HEAP_SIZE) 
71                && (addr_pointed2 > std_heap) && ((char *)addr_pointed2 < (char *)std_heap + STD_HEAP_SIZE)){
72               res_compare = compare_area(addr_pointed1, addr_pointed2, NULL);
73               if(res_compare == 1){
74                 #ifdef MC_VERBOSE
75                   XBT_VERB("Different global variable in libsimgrid : %s at addresses %p - %p (size = %zu)", current_var->name, (char *)d1+offset, (char *)d2+offset, current_var->size);
76                 #endif
77                 return 1;
78               }
79             }else{
80               #ifdef MC_VERBOSE
81                 XBT_VERB("Different global variable in libsimgrid : %s at addresses %p - %p (size = %zu)", current_var->name, (char *)d1+offset, (char *)d2+offset, current_var->size);
82               #endif
83               return 1;
84             }
85            
86           }
87         } 
88         i++;
89       }
90     }
91   }else{ /* binary */
92     xbt_dynar_foreach(mc_global_variables, cursor, current_var){
93       if(current_var->address > start_data_libsimgrid)
94         break;
95       offset = (char *)current_var->address - (char *)start_data_binary;
96       i = 0;
97       while(i < current_var->size){
98         if(memcmp((char*)d1 + offset + i, (char*)d2 + offset + i, 1) != 0){
99           pointer_align = (i / sizeof(void*)) * sizeof(void*); 
100           addr_pointed1 = *((void **)((char *)d1 + offset + pointer_align));
101           addr_pointed2 = *((void **)((char *)d2 + offset + pointer_align));
102           if((addr_pointed1 > start_plt_binary && addr_pointed1 < end_plt_binary) || (addr_pointed2 > start_plt_binary && addr_pointed2 < end_plt_binary)){
103             i = current_var->size;
104             continue;
105           }else{
106             if((addr_pointed1 > std_heap) && ((char *)addr_pointed1 < (char *)std_heap + STD_HEAP_SIZE) && (addr_pointed2 > std_heap) && ((char *)addr_pointed2 < (char *)std_heap + STD_HEAP_SIZE)){
107               res_compare = compare_area(addr_pointed1, addr_pointed2, NULL);
108               if(res_compare == 1){
109                 #ifdef MC_VERBOSE
110                   XBT_VERB("Different global variable in binary : %s at addresses %p - %p (size = %zu)", current_var->name, (char *)d1+offset, (char *)d2+offset, current_var->size);
111                 #endif
112                 return 1;
113               }
114             }else{
115               #ifdef MC_VERBOSE
116                 XBT_VERB("Different global variable in binary : %s at addresses %p - %p (size = %zu)", current_var->name, (char *)d1+offset, (char *)d2+offset, current_var->size);
117               #endif
118               return 1;
119             }
120           }
121         } 
122         i++;
123       }
124       
125     }
126   }
127
128   return 0;
129 }
130
131 static int heap_region_compare(void *d1, void *d2, size_t size){
132   
133   size_t i = 0;
134   
135   for(i=0; i<size; i++){
136     if(memcmp(((char *)d1) + i, ((char *)d2) + i, 1) != 0){
137       if(XBT_LOG_ISENABLED(mc_compare, xbt_log_priority_verbose)){
138         XBT_VERB("Different byte (offset=%zu) (%p - %p) in heap region", i, (char *)d1 + i, (char *)d2 + i);
139       }
140       return 1;
141     }
142   }
143   
144   return 0;
145 }
146
147 static void stack_region_free(stack_region_t s){
148   if(s){
149     xbt_free(s->process_name);
150     xbt_free(s);
151   }
152 }
153
154 void stack_region_free_voidp(void *s){
155   stack_region_free((stack_region_t) * (void **) s);
156 }
157
158 static void heap_equality_free(heap_equality_t e){
159   xbt_free(e);
160 }
161
162 void heap_equality_free_voidp(void *e){
163   heap_equality_free((heap_equality_t) * (void **) e);
164 }
165
166 int SIMIX_pre_mc_compare_snapshots(smx_simcall_t simcall,
167                                    mc_snapshot_t s1, mc_snapshot_t s2){
168   return snapshot_compare(s1, s2);
169 }
170
171 int snapshot_compare(mc_snapshot_t s1, mc_snapshot_t s2){
172
173   int raw_mem = (mmalloc_get_current_heap() == raw_heap);
174   
175   MC_SET_RAW_MEM;
176      
177   int errors = 0;
178
179   xbt_os_timer_t global_timer = xbt_os_timer_new();
180   xbt_os_timer_t timer = xbt_os_timer_new();
181
182   xbt_os_timer_start(global_timer);
183
184   #ifdef MC_DEBUG
185     xbt_os_timer_start(timer);
186   #endif
187
188   /* Compare number of processes */
189   if(s1->nb_processes != s2->nb_processes){
190     #ifdef MC_DEBUG
191       xbt_os_timer_stop(timer);
192       mc_comp_times->nb_processes_comparison_time =  xbt_os_timer_elapsed(timer);
193       XBT_DEBUG("Different number of processes : %d - %d", s1->nb_processes, s2->nb_processes);
194       errors++;
195     #else
196       #ifdef MC_VERBOSE
197         XBT_VERB("Different number of processes : %d - %d", s1->nb_processes, s2->nb_processes);
198       #endif
199      
200       xbt_os_timer_free(timer);
201       xbt_os_timer_stop(global_timer);
202       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
203       xbt_os_timer_free(global_timer);
204
205       if(!raw_mem)
206         MC_UNSET_RAW_MEM;
207
208       return 1;
209     #endif
210   }
211
212   #ifdef MC_DEBUG
213     xbt_os_timer_start(timer);
214   #endif
215
216   /* Compare number of bytes used in each heap */
217   if(s1->heap_bytes_used != s2->heap_bytes_used){
218     #ifdef MC_DEBUG
219       xbt_os_timer_stop(timer);
220       mc_comp_times->bytes_used_comparison_time = xbt_os_timer_elapsed(timer);
221       XBT_DEBUG("Different number of bytes used in each heap : %zu - %zu", s1->heap_bytes_used, s2->heap_bytes_used);
222       errors++;
223     #else
224       #ifdef MC_VERBOSE
225         XBT_VERB("Different number of bytes used in each heap : %zu - %zu", s1->heap_bytes_used, s2->heap_bytes_used);
226       #endif
227
228       xbt_os_timer_free(timer);
229       xbt_os_timer_stop(global_timer);
230       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
231       xbt_os_timer_free(global_timer);
232
233       if(!raw_mem)
234         MC_UNSET_RAW_MEM;
235
236       return 1;
237     #endif
238   }else{
239     #ifdef MC_DEBUG
240       xbt_os_timer_stop(timer);
241     #endif
242   }
243   
244   #ifdef MC_DEBUG
245     xbt_os_timer_start(timer);
246   #endif
247   
248   /* Compare size of stacks */
249   int i = 0;
250   size_t size_used1, size_used2;
251   int is_diff = 0;
252   while(i < xbt_dynar_length(s1->stacks)){
253     size_used1 = s1->stack_sizes[i];
254     size_used2 = s2->stack_sizes[i];
255     if(size_used1 != size_used2){
256     #ifdef MC_DEBUG
257       if(is_diff == 0){
258         xbt_os_timer_stop(timer);
259         mc_comp_times->stacks_sizes_comparison_time = xbt_os_timer_elapsed(timer);
260       }
261       XBT_DEBUG("Different size used in stacks : %zu - %zu", size_used1, size_used2);
262       errors++;
263       is_diff = 1;
264     #else
265       #ifdef MC_VERBOSE
266         XBT_VERB("Different size used in stacks : %zu - %zu", size_used1, size_used2);
267       #endif
268  
269       xbt_os_timer_free(timer);
270       xbt_os_timer_stop(global_timer);
271       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
272       xbt_os_timer_free(global_timer);
273
274       if(!raw_mem)
275         MC_UNSET_RAW_MEM;
276
277       return 1;
278     #endif  
279     }
280     i++;
281   }
282
283   #ifdef MC_DEBUG
284     if(is_diff == 0)
285       xbt_os_timer_stop(timer);
286     xbt_os_timer_start(timer);
287   #endif
288
289   /* Compare hash of global variables */
290   if(s1->hash_global != NULL && s2->hash_global != NULL){
291     if(strcmp(s1->hash_global, s2->hash_global) != 0){
292       #ifdef MC_DEBUG
293         xbt_os_timer_stop(timer);
294         mc_comp_times->hash_global_variables_comparison_time = xbt_os_timer_elapsed(timer);
295         XBT_DEBUG("Different hash of global variables : %s - %s", s1->hash_global, s2->hash_global); 
296         errors++; 
297       #else
298         #ifdef MC_VERBOSE
299           XBT_VERB("Different hash of global variables : %s - %s", s1->hash_global, s2->hash_global); 
300         #endif
301     
302         xbt_os_timer_free(timer);
303         xbt_os_timer_stop(global_timer);
304         mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
305         xbt_os_timer_free(global_timer);
306     
307         if(!raw_mem)
308           MC_UNSET_RAW_MEM;
309
310         return 1;
311       #endif
312     }
313   }
314
315   #ifdef MC_DEBUG
316     xbt_os_timer_start(timer);
317   #endif
318
319   /* Compare hash of local variables */
320   if(s1->hash_local != NULL && s2->hash_local != NULL){
321     if(strcmp(s1->hash_local, s2->hash_local) != 0){
322       #ifdef MC_DEBUG
323         xbt_os_timer_stop(timer);
324         mc_comp_times->hash_local_variables_comparison_time = xbt_os_timer_elapsed(timer);
325         XBT_DEBUG("Different hash of local variables : %s - %s", s1->hash_local, s2->hash_local); 
326         errors++; 
327       #else
328         #ifdef MC_VERBOSE
329           XBT_VERB("Different hash of local variables : %s - %s", s1->hash_local, s2->hash_local); 
330         #endif
331     
332         xbt_os_timer_free(timer);
333         xbt_os_timer_stop(global_timer);
334         mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
335         xbt_os_timer_free(global_timer);
336         
337         if(!raw_mem)
338           MC_UNSET_RAW_MEM;
339         
340         return 1;
341       #endif
342     }
343   }
344
345   #ifdef MC_DEBUG
346     xbt_os_timer_start(timer);
347   #endif
348
349   /* Init heap information used in heap comparison algorithm */
350   init_heap_information((xbt_mheap_t)s1->regions[0]->data, (xbt_mheap_t)s2->regions[0]->data, s1->to_ignore, s2->to_ignore);
351
352   /* Compare binary global variables */
353   is_diff = compare_global_variables(2, s1->regions[2]->data, s2->regions[2]->data);
354   if(is_diff != 0){
355     #ifdef MC_DEBUG
356       xbt_os_timer_stop(timer);
357       mc_comp_times->binary_global_variables_comparison_time = xbt_os_timer_elapsed(timer);
358       XBT_DEBUG("Different global variables in binary"); 
359       errors++; 
360     #else
361       #ifdef MC_VERBOSE
362         XBT_VERB("Different global variables in binary"); 
363       #endif
364     
365       reset_heap_information();
366       xbt_os_timer_free(timer);
367       xbt_os_timer_stop(global_timer);
368       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
369       xbt_os_timer_free(global_timer);
370     
371       if(!raw_mem)
372         MC_UNSET_RAW_MEM;
373
374       return 1;
375     #endif
376   }
377
378   #ifdef MC_DEBUG
379     if(is_diff == 0)
380       xbt_os_timer_stop(timer);
381     xbt_os_timer_start(timer);
382   #endif
383
384   /* Compare libsimgrid global variables */
385   is_diff = compare_global_variables(1, s1->regions[1]->data, s2->regions[1]->data);
386   if(is_diff != 0){
387     #ifdef MC_DEBUG
388       xbt_os_timer_stop(timer);
389       mc_comp_times->libsimgrid_global_variables_comparison_time = xbt_os_timer_elapsed(timer); 
390       XBT_DEBUG("Different global variables in libsimgrid"); 
391       errors++; 
392     #else
393       #ifdef MC_VERBOSE
394         XBT_VERB("Different global variables in libsimgrid"); 
395       #endif
396         
397       reset_heap_information();
398       xbt_os_timer_free(timer);
399       xbt_os_timer_stop(global_timer);
400       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
401       xbt_os_timer_free(global_timer);
402     
403       if(!raw_mem)
404         MC_UNSET_RAW_MEM;
405
406       return 1;
407     #endif
408   }  
409
410   #ifdef MC_DEBUG
411     if(is_diff == 0)
412       xbt_os_timer_stop(timer);
413     xbt_os_timer_start(timer);
414   #endif
415
416     /* Stacks comparison */
417     unsigned int  cursor = 0;
418     int diff_local = 0;
419     is_diff = 0;
420     
421     while(cursor < xbt_dynar_length(s1->stacks)){
422       diff_local = compare_local_variables(((mc_snapshot_stack_t)xbt_dynar_get_as(s1->stacks, cursor, mc_snapshot_stack_t))->local_variables->data, ((mc_snapshot_stack_t)xbt_dynar_get_as(s2->stacks, cursor, mc_snapshot_stack_t))->local_variables->data);
423       if(diff_local > 0){
424         #ifdef MC_DEBUG
425           if(is_diff == 0){
426             xbt_os_timer_stop(timer);
427             mc_comp_times->stacks_comparison_time = xbt_os_timer_elapsed(timer); 
428           }
429           XBT_DEBUG("Different local variables between stacks %d", cursor + 1);
430           errors++;
431           is_diff = 1;
432         #else
433         
434           #ifdef MC_VERBOSE
435             XBT_VERB("Different local variables between stacks %d", cursor + 1);
436           #endif
437           
438             reset_heap_information();
439             xbt_os_timer_free(timer);
440             xbt_os_timer_stop(global_timer);
441             mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
442             xbt_os_timer_free(global_timer);
443             
444             if(!raw_mem)
445               MC_UNSET_RAW_MEM;
446             
447             return 1;
448         #endif
449       }
450       cursor++;
451     }
452     
453     #ifdef MC_DEBUG
454       xbt_os_timer_start(timer);
455     #endif
456
457   /* Compare heap */
458  
459   if(mmalloc_compare_heap((xbt_mheap_t)s1->regions[0]->data, (xbt_mheap_t)s2->regions[0]->data)){
460
461     #ifdef MC_DEBUG
462       xbt_os_timer_stop(timer);
463       mc_comp_times->heap_comparison_time = xbt_os_timer_elapsed(timer); 
464       XBT_DEBUG("Different heap (mmalloc_compare)");
465       errors++;
466     #else
467
468       xbt_os_timer_free(timer);
469  
470       #ifdef MC_VERBOSE
471         XBT_VERB("Different heap (mmalloc_compare)");
472       #endif
473        
474       reset_heap_information();
475       xbt_os_timer_stop(global_timer);
476       mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
477       xbt_os_timer_free(global_timer);
478
479       if(!raw_mem)
480         MC_UNSET_RAW_MEM;
481
482       return 1;
483     #endif
484   }else{
485     #ifdef MC_DEBUG
486       xbt_os_timer_stop(timer);
487     #endif
488   }
489
490   reset_heap_information();
491    
492   xbt_os_timer_free(timer);
493
494   #ifdef MC_VERBOSE
495     xbt_os_timer_stop(global_timer);
496     mc_snapshot_comparison_time = xbt_os_timer_elapsed(global_timer);
497   #endif
498
499   xbt_os_timer_free(global_timer);
500
501   #ifdef MC_DEBUG
502     print_comparison_times();
503   #endif
504
505   if(!raw_mem)
506     MC_UNSET_RAW_MEM;
507
508   return errors > 0;
509   
510 }
511
512 int is_stack_ignore_variable(char *frame, char *var_name){
513
514   unsigned int cursor = 0;
515   int start = 0;
516   int end = xbt_dynar_length(mc_stack_comparison_ignore) - 1;
517   mc_stack_ignore_variable_t current_var;
518
519   while(start <= end){
520     cursor = (start + end) / 2;
521     current_var = (mc_stack_ignore_variable_t)xbt_dynar_get_as(mc_stack_comparison_ignore, cursor, mc_stack_ignore_variable_t);
522     if(strcmp(current_var->frame, frame) == 0 || strcmp(current_var->frame, "*") == 0){
523       if(strcmp(current_var->var_name, var_name) == 0)
524         return 1;
525       if(strcmp(current_var->var_name, var_name) < 0)
526         start = cursor + 1;
527       if(strcmp(current_var->var_name, var_name) > 0)
528         end = cursor - 1;
529     }else if(strcmp(current_var->frame, frame) < 0){
530       start = cursor + 1;
531     }else if(strcmp(current_var->frame, frame) > 0){
532       end = cursor - 1; 
533     }
534   }
535
536   return 0;
537 }
538
539 static int compare_local_variables(char *s1, char *s2){
540   
541   xbt_dynar_t tokens1 = xbt_str_split(s1, NULL);
542   xbt_dynar_t tokens2 = xbt_str_split(s2, NULL);
543
544   xbt_dynar_t s_tokens1, s_tokens2;
545   unsigned int cursor = 0;
546   void *addr1, *addr2;
547   char *frame_name1 = NULL, *frame_name2 = NULL;
548   int res_compare = 0;
549
550   #ifdef MC_VERBOSE
551     char *var_name;
552   #endif
553
554   while(cursor < xbt_dynar_length(tokens1)){
555     s_tokens1 = xbt_str_split(xbt_dynar_get_as(tokens1, cursor, char *), "=");
556     s_tokens2 = xbt_str_split(xbt_dynar_get_as(tokens2, cursor, char *), "=");
557     if(xbt_dynar_length(s_tokens1) > 1 && xbt_dynar_length(s_tokens2) > 1){
558       #ifdef MC_VERBOSE
559         var_name = xbt_dynar_get_as(s_tokens1, 0, char *);
560       #endif
561       if((strcmp(xbt_dynar_get_as(s_tokens1, 0, char *), "frame_name") == 0) && (strcmp(xbt_dynar_get_as(s_tokens2, 0, char *), "frame_name") == 0)){
562         xbt_free(frame_name1);
563         xbt_free(frame_name2);
564         frame_name1 = strdup(xbt_dynar_get_as(s_tokens1, 1, char *));
565         frame_name2 = strdup(xbt_dynar_get_as(s_tokens2, 1, char *));
566       }
567       addr1 = (void *) strtoul(xbt_dynar_get_as(s_tokens1, 1, char *), NULL, 16);
568       addr2 = (void *) strtoul(xbt_dynar_get_as(s_tokens2, 1, char *), NULL, 16);
569       if(addr1 > std_heap && (char *)addr1 <= (char *)std_heap + STD_HEAP_SIZE && addr2 > std_heap && (char *)addr2 <= (char *)std_heap + STD_HEAP_SIZE){
570         res_compare = compare_area(addr1, addr2, NULL);
571         if(res_compare == 1){
572           if(is_stack_ignore_variable(frame_name1, xbt_dynar_get_as(s_tokens1, 0, char *)) && is_stack_ignore_variable(frame_name2, xbt_dynar_get_as(s_tokens2, 0, char *))){
573             xbt_dynar_free(&s_tokens1);
574             xbt_dynar_free(&s_tokens2);
575             cursor++;
576             continue;
577           }else {
578             #ifdef MC_VERBOSE
579               XBT_VERB("Different local variable : %s at addresses %p - %p", var_name, addr1, addr2);
580             #endif
581             xbt_dynar_free(&s_tokens1);
582             xbt_dynar_free(&s_tokens2);
583             xbt_dynar_free(&tokens1);
584             xbt_dynar_free(&tokens2);
585             xbt_free(frame_name1);
586             xbt_free(frame_name2);
587             return 1;
588           }
589         }
590       }else{
591         if(strcmp(xbt_dynar_get_as(s_tokens1, 1, char *), xbt_dynar_get_as(s_tokens2, 1, char *)) != 0){
592           if(is_stack_ignore_variable(frame_name1, xbt_dynar_get_as(s_tokens1, 0, char *)) && is_stack_ignore_variable(frame_name2, xbt_dynar_get_as(s_tokens2, 0, char *))){
593             xbt_dynar_free(&s_tokens1);
594             xbt_dynar_free(&s_tokens2);
595             cursor++;
596             continue;
597           }else {
598             #ifdef MC_VERBOSE
599               XBT_VERB("Different local variable : %s (%s - %s)", var_name, xbt_dynar_get_as(s_tokens1, 1, char *), xbt_dynar_get_as(s_tokens2, 1, char *));
600             #endif
601             xbt_dynar_free(&s_tokens1);
602             xbt_dynar_free(&s_tokens2);
603             xbt_dynar_free(&tokens1);
604             xbt_dynar_free(&tokens2);
605             xbt_free(frame_name1);
606             xbt_free(frame_name2);
607             return 1;
608           }
609         }
610       }
611     }
612     xbt_dynar_free(&s_tokens1);
613     xbt_dynar_free(&s_tokens2);
614          
615     cursor++;
616   }
617
618   xbt_free(frame_name1);
619   xbt_free(frame_name2);
620   xbt_dynar_free(&tokens1);
621   xbt_dynar_free(&tokens2);
622   return 0;
623   
624 }
625
626 static int is_heap_equality(xbt_dynar_t equals, void *a1, void *a2){
627
628   unsigned int cursor = 0;
629   int start = 0;
630   int end = xbt_dynar_length(equals) - 1;
631   heap_equality_t current_equality;
632
633   while(start <= end){
634     cursor = (start + end) / 2;
635     current_equality = (heap_equality_t)xbt_dynar_get_as(equals, cursor, heap_equality_t);
636     if(current_equality->address1 == a1){
637       if(current_equality->address2 == a2)
638         return 1;
639       if(current_equality->address2 < a2)
640         start = cursor + 1;
641       if(current_equality->address2 > a2)
642         end = cursor - 1;
643     }
644     if(current_equality->address1 < a1)
645       start = cursor + 1;
646     if(current_equality->address1 > a1)
647       end = cursor - 1; 
648   }
649
650   return 0;
651
652 }
653
654 int MC_compare_snapshots(void *s1, void *s2){
655   
656   MC_ignore_stack("self", "simcall_BODY_mc_snapshot");
657
658   return simcall_mc_compare_snapshots(s1, s2);
659
660 }
661
662 void print_comparison_times(){
663   XBT_DEBUG("*** Comparison times ***");
664   XBT_DEBUG("- Nb processes : %f", mc_comp_times->nb_processes_comparison_time);
665   XBT_DEBUG("- Nb bytes used : %f", mc_comp_times->bytes_used_comparison_time);
666   XBT_DEBUG("- Stacks sizes : %f", mc_comp_times->stacks_sizes_comparison_time);
667   XBT_DEBUG("- Binary global variables : %f", mc_comp_times->binary_global_variables_comparison_time);
668   XBT_DEBUG("- Libsimgrid global variables : %f", mc_comp_times->libsimgrid_global_variables_comparison_time);
669   XBT_DEBUG("- Heap : %f", mc_comp_times->heap_comparison_time);
670   XBT_DEBUG("- Stacks : %f", mc_comp_times->stacks_comparison_time);
671 }