Example #1
0
def do_instrumentation_point_graph_instrumentation(control_flow_graph,
                                                   trace,
                                                   actual_execution_counts):    
    instrumentation_point_graph = InstrumentationPointGraph.\
                                    instrument_but_maintain_path_reconstructibility\
                                        (control_flow_graph)
    instrumentation_points = set({vertex.program_point 
                                  for vertex in instrumentation_point_graph})
    
    # Add a sentinel value to the end of the trace so that we transition to a final
    # state and count correctly.
    filtered_trace = [program_point for program_point in trace 
                      if program_point in instrumentation_points] +\
                      [None]
    debug.debug_message('Post-filter: {}'.format(filtered_trace), 
                        __name__)
    inferred_execution_counts = {}
    
    vertex = instrumentation_point_graph.get_entry_vertex()
    for program_point in filtered_trace:
        inferred_execution_counts[program_point] = 1 + inferred_execution_counts.\
                                                        setdefault(program_point, 0)
        for succ_edge in vertex.successor_edge_iterator():
            succ_vertex = instrumentation_point_graph.get_vertex(succ_edge.vertex_id)
            if succ_vertex.program_point == program_point:
                for tree_succ_edge in succ_edge.path_expression.root_vertex.successor_edge_iterator():
                    program_point_vertex = succ_edge.path_expression.get_vertex(tree_succ_edge.vertex_id)
                    inferred_execution_counts[program_point_vertex.
                                              program_point] = 1 + inferred_execution_counts.\
                                                                setdefault(program_point_vertex.program_point, 0)
                vertex = succ_vertex
                break
    
    for key in actual_execution_counts.keys():
        if inferred_execution_counts[key] != actual_execution_counts[key]:
            print('MISMATCH:',
                  key, 
                  actual_execution_counts[key], 
                  inferred_execution_counts[key])
Example #2
0
                        action='store_true',
                        help='use instrumentation point graph to work out '
                        'where to place instrumentaton',
                        default=False)
    
    globals.add_common_command_line_arguments(parser)
    globals.args = vars(parser.parse_args())
    globals.set_filename_prefix(globals.args['program_file'])


if __name__ == '__main__': 
    parse_the_command_line()
    program = environment.create_program_from_input_file()

    for control_flow_graph in program:
        debug.debug_message('======> function {}'.format(control_flow_graph.name),
                            __name__)
        if globals.args['instrument'] == 'vertices':
            control_flow_graph.instrument_all_basic_blocks()
        elif globals.args['instrument'] == 'edges':
            control_flow_graph.instrument_all_control_flow_edges()
        elif globals.args['instrument'] == 'mixed':
            control_flow_graph.instrument_all_basic_blocks()
            control_flow_graph.instrument_all_control_flow_edges()
        else:
            assert False
    
        for repetition in range(1, globals.args['repeat']+1):
            trace = control_flow_graph.generate_trace(executions=10)
            debug.debug_message('Pre-filter: {}'.format(trace), 
                                __name__)
            actual_execution_counts = Counter(trace)