X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d048b00742e6a2e9f0fe5d82d8e44747f34a5a8b..f35db13138682b1be530a509d1eeadeafff84ca7:/src/mc/compare.cpp diff --git a/src/mc/compare.cpp b/src/mc/compare.cpp index 72e930ba0d..404b384591 100644 --- a/src/mc/compare.cpp +++ b/src/mc/compare.cpp @@ -1,10 +1,9 @@ -/* Copyright (c) 2008-2016. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2008-2017. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -/** \file mc_compare.cpp Memory snapshooting and comparison */ +/** \file compare.cpp Memory snapshooting and comparison */ #include @@ -24,7 +23,6 @@ #include "src/internal_config.h" #include "src/xbt/mmalloc/mmprivate.h" -#include "src/xbt/ex_interface.h" #if HAVE_SMPI #include "src/smpi/private.h" @@ -94,10 +92,10 @@ struct HeapLocation { static inline HeapLocationPair makeHeapLocationPair(int block1, int fragment1, int block2, int fragment2) { - return simgrid::mc::HeapLocationPair({ + return simgrid::mc::HeapLocationPair{{ simgrid::mc::HeapLocation(block1, fragment1), simgrid::mc::HeapLocation(block2, fragment2) - }); + }}; } struct HeapArea : public HeapLocation { @@ -195,7 +193,6 @@ struct StateComparator { /** Check whether two blocks are known to be matching * - * @param state State used * @param b1 Block of state 1 * @param b2 Block of state 2 * @return if the blocks are known to be matching @@ -208,7 +205,6 @@ struct StateComparator { /** Check whether two fragments are known to be matching * - * @param state State used * @param b1 Block of state 1 * @param f1 Fragment of state 1 * @param b2 Block of state 2 @@ -595,7 +591,7 @@ int mmalloc_compare_heap( } if (i1 == state.heaplimit) - XBT_DEBUG("Number of blocks/fragments not found in heap1 : %d", nb_diff1); + XBT_DEBUG("Number of blocks/fragments not found in heap1: %d", nb_diff1); for (i=1; i < state.heaplimit; i++) { const malloc_info* heapinfo2 = (const malloc_info*) MC_region_read( @@ -624,7 +620,7 @@ int mmalloc_compare_heap( } if (i1 == state.heaplimit) - XBT_DEBUG("Number of blocks/fragments not found in heap2 : %d", nb_diff2); + XBT_DEBUG("Number of blocks/fragments not found in heap2: %d", nb_diff2); return nb_diff1 > 0 || nb_diff2 > 0; } @@ -978,7 +974,7 @@ static simgrid::mc::Type* get_offset_type(void *real_base_address, simgrid::mc:: return nullptr; default: - /* FIXME : other cases ? */ + /* FIXME: other cases ? */ return nullptr; } @@ -1016,7 +1012,7 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, int new_size1 = -1, new_size2 = -1; simgrid::mc::Type *new_type1 = nullptr, *new_type2 = nullptr; - int match_pairs = 0; + bool match_pairs = false; // This is the address of std_heap->heapinfo in the application process: void* heapinfo_address = &((xbt_mheap_t) process->heap_address)->heapinfo; @@ -1028,9 +1024,10 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, malloc_info heapinfo_temp1, heapinfo_temp2; + simgrid::mc::HeapLocationPairs current; if (previous == nullptr) { - previous = new HeapLocationPairs(); - match_pairs = 1; + previous = ¤t; + match_pairs = true; } // Get block number: @@ -1045,10 +1042,8 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, if (is_block_stack((int) block1) && is_block_stack((int) block2)) { previous->insert(simgrid::mc::makeHeapLocationPair( block1, -1, block2, -1)); - if (match_pairs) { + if (match_pairs) state.match_equals(previous); - delete previous; - } return 0; } @@ -1057,8 +1052,6 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, || (block1 > (ssize_t) state.processStates[0].heapsize) || (block1 < 1) || ((char *) area2 < (char *) state.std_heap_copy.heapbase) || (block2 > (ssize_t) state.processStates[1].heapsize) || (block2 < 1)) { - if (match_pairs) - delete previous; return 1; } @@ -1098,10 +1091,8 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, if ((heapinfo1->type == MMALLOC_TYPE_FREE || heapinfo1->type==MMALLOC_TYPE_HEAPINFO) && (heapinfo2->type == MMALLOC_TYPE_FREE || heapinfo2->type ==MMALLOC_TYPE_HEAPINFO)) { /* Free block */ - if (match_pairs) { + if (match_pairs) state.match_equals(previous); - delete previous; - } return 0; } @@ -1117,10 +1108,8 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, if (state.equals_to1_(block1, 0).valid && state.equals_to2_(block2, 0).valid && state.blocksEqual(block1, block2)) { - if (match_pairs) { + if (match_pairs) state.match_equals(previous); - delete previous; - } return 0; } @@ -1128,32 +1117,21 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, if (type_size != (ssize_t) heapinfo1->busy_block.busy_size && type_size != (ssize_t) heapinfo2->busy_block.busy_size && (type->name.empty() || type->name == "struct s_smx_context")) { - if (match_pairs) { + if (match_pairs) state.match_equals(previous); - delete previous; - } return -1; } } - if (heapinfo1->busy_block.size != heapinfo2->busy_block.size) { - if (match_pairs) - delete previous; + if (heapinfo1->busy_block.size != heapinfo2->busy_block.size) return 1; - } - - if (heapinfo1->busy_block.busy_size != heapinfo2->busy_block.busy_size) { - if (match_pairs) - delete previous; + if (heapinfo1->busy_block.busy_size != heapinfo2->busy_block.busy_size) return 1; - } if (!previous->insert(simgrid::mc::makeHeapLocationPair( block1, -1, block2, -1)).second) { - if (match_pairs) { + if (match_pairs) state.match_equals(previous); - delete previous; - } return 0; } @@ -1167,10 +1145,8 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, state.types2_(block2, 0) = type; if (size <= 0) { - if (match_pairs) { + if (match_pairs) state.match_equals(previous); - delete previous; - } return 0; } @@ -1201,19 +1177,15 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, if (type_size != -1) { if (heapinfo1->busy_frag.frag_size[frag1] == -1 || heapinfo2->busy_frag.frag_size[frag2] == -1) { - if (match_pairs) { + if (match_pairs) state.match_equals(previous); - delete previous; - } return -1; } // ? if (type_size != heapinfo1->busy_frag.frag_size[frag1] || type_size != heapinfo2->busy_frag.frag_size[frag2]) { - if (match_pairs) { + if (match_pairs) state.match_equals(previous); - delete previous; - } return -1; } } @@ -1222,10 +1194,8 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, if (state.equals_to1_(block1, frag1).valid && state.equals_to2_(block2, frag2).valid) { if (offset1==offset2 && state.fragmentsEqual(block1, frag1, block2, frag2)) { - if (match_pairs) { + if (match_pairs) state.match_equals(previous); - delete previous; - } return 0; } } @@ -1233,16 +1203,11 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, if (heapinfo1->busy_frag.frag_size[frag1] != heapinfo2->busy_frag.frag_size[frag2]) { if (type_size == -1) { - if (match_pairs) { + if (match_pairs) state.match_equals(previous); - delete previous; - } return -1; - } else { - if (match_pairs) - delete previous; + } else return 1; - } } // Size of the fragment: @@ -1290,10 +1255,8 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, get_offset_type(real_addr_frag2, state.types2_(block2, frag2), offset2, size, snapshot2, process_index); } else { - if (match_pairs) { + if (match_pairs) state.match_equals(previous); - delete previous; - } return -1; } @@ -1310,10 +1273,8 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, new_size2 = type->byte_size; } else { - if (match_pairs) { + if (match_pairs) state.match_equals(previous); - delete previous; - } return -1; } } @@ -1326,18 +1287,14 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, if (offset1 == 0 && offset2 == 0 && !previous->insert(simgrid::mc::makeHeapLocationPair( block1, frag1, block2, frag2)).second) { - if (match_pairs) { + if (match_pairs) state.match_equals(previous); - delete previous; - } return 0; } if (size <= 0) { - if (match_pairs) { + if (match_pairs) state.match_equals(previous); - delete previous; - } return 0; } @@ -1346,11 +1303,8 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, heapinfo1->busy_frag.ignore[frag1])) check_ignore = heapinfo1->busy_frag.ignore[frag1]; - } else { - if (match_pairs) - delete previous; + } else return 1; - } /* Start comparison */ @@ -1364,17 +1318,11 @@ int compare_heap_area(simgrid::mc::StateComparator& state, int process_index, compare_heap_area_without_type(state, process_index, area1, area2, snapshot1, snapshot2, previous, size, check_ignore); - if (res_compare == 1) { - if (match_pairs) - delete previous; + if (res_compare == 1) return res_compare; - } - if (match_pairs) { + if (match_pairs) state.match_equals(previous); - delete previous; - } - return 0; } @@ -1534,7 +1482,7 @@ static int compare_areas_with_type(simgrid::mc::StateComparator& state, return -1; break; default: - XBT_VERB("Unknown case : %d", type->type); + XBT_VERB("Unknown case: %d", type->type); break; } @@ -1685,13 +1633,12 @@ int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc: if (_sg_mc_hash) { hash_result = (s1->hash != s2->hash); if (hash_result) { - XBT_VERB("(%d - %d) Different hash : 0x%" PRIx64 "--0x%" PRIx64, num1, - num2, s1->hash, s2->hash); + XBT_VERB("(%d - %d) Different hash: 0x%" PRIx64 "--0x%" PRIx64, num1, num2, s1->hash, s2->hash); #ifndef MC_DEBUG return 1; #endif } else - XBT_VERB("(%d - %d) Same hash : 0x%" PRIx64, num1, num2, s1->hash); + XBT_VERB("(%d - %d) Same hash: 0x%" PRIx64, num1, num2, s1->hash); } /* Compare enabled processes */ @@ -1710,14 +1657,12 @@ int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc: size_used2 = s2->stack_sizes[i]; if (size_used1 != size_used2) { #ifdef MC_DEBUG - XBT_DEBUG("(%d - %d) Different size used in stacks : %zu - %zu", num1, - num2, size_used1, size_used2); + XBT_DEBUG("(%d - %d) Different size used in stacks: %zu - %zu", num1, num2, size_used1, size_used2); errors++; is_diff = 1; #else #ifdef MC_VERBOSE - XBT_VERB("(%d - %d) Different size used in stacks : %zu - %zu", num1, - num2, size_used1, size_used2); + XBT_VERB("(%d - %d) Different size used in stacks: %zu - %zu", num1, num2, size_used1, size_used2); #endif return 1; #endif @@ -1751,15 +1696,13 @@ int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc: } /* Stacks comparison */ - unsigned cursor = 0; int diff_local = 0; #ifdef MC_DEBUG is_diff = 0; #endif - mc_snapshot_stack_t stack1, stack2; - while (cursor < s1->stacks.size()) { - stack1 = &s1->stacks[cursor]; - stack2 = &s2->stacks[cursor]; + for (unsigned int cursor = 0; cursor < s1->stacks.size(); cursor++) { + mc_snapshot_stack_t stack1 = &s1->stacks[cursor]; + mc_snapshot_stack_t stack2 = &s2->stacks[cursor]; if (stack1->process_index != stack2->process_index) { diff_local = 1; @@ -1784,7 +1727,6 @@ int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc: return 1; #endif } - cursor++; } size_t regions_count = s1->snapshot_regions.size(); @@ -1838,7 +1780,6 @@ int snapshot_compare(int num1, simgrid::mc::Snapshot* s1, int num2, simgrid::mc: #ifdef MC_VERBOSE XBT_VERB("(%d - %d) Different heap (mmalloc_compare)", num1, num2); #endif - return 1; #endif }