Esempio n. 1
0
    def summary(self, a=None, depth=0):
        '''Yield string(s) summarizing this segment and all of its subrecords
        a (StreamRecord or None)
            StreamRecord to produce summary from. Uses self if None.

        depth (int)
            Indentation level for this summary
        '''
        if a is None:
            a = self

        field_name = ''
        if 'name' in a.fields:
            field_name = '({})'.format(a.fields['name'])

        yield '{}{} - {}: {} {}'.format('  '*depth, eng_si(a.start_time, 's'), eng_si(a.end_time, 's'), a, field_name)
        for sr in a.subrecords:
            for s in self.summary(sr, depth+1):
                yield s
Esempio n. 2
0
    def wrapper(self, *args, **kwargs):
        gc.disable()
        try:
            t_start = time.time()
            result = f(self, *args, **kwargs)
            t_end = time.time()
            try:
                _t_start = self._t_start
                t_start = _t_start if isinstance(_t_start, float) else t_start
                self._t_start = None
            except:
                pass

        finally:
            gc.enable()

        delta = t_end - t_start

        iterations = None
        units_processed = 1
        unit_name = 'units'
        if result:
            try:
                if len(result) >= 2:
                    iterations = result[0]
                    units_processed = result[1]

                    if len(result) >= 3:
                        unit_name = result[2]
            except TypeError:
                iterations = result
            

        if iterations:
            per_iter = delta / iterations
        else:
            per_iter = delta

        processing_rate = units_processed / delta

        print('*   Test duration: total {}, per iteration {}, rate {}'.format( \
            eng_si(delta, 's'), eng_si(per_iter, 's'), eng_si(processing_rate, unit_name + '/s') ))
Esempio n. 3
0
    def wrapper(self, *args, **kwargs):
        gc.disable()
        try:
            t_start = time.time()
            result = f(self, *args, **kwargs)
            t_end = time.time()
            try:
                _t_start = self._t_start
                t_start = _t_start if isinstance(_t_start, float) else t_start
                self._t_start = None
            except:
                pass

        finally:
            gc.enable()

        delta = t_end - t_start

        iterations = None
        units_processed = 1
        unit_name = 'units'
        if result:
            try:
                if len(result) >= 2:
                    iterations = result[0]
                    units_processed = result[1]

                    if len(result) >= 3:
                        unit_name = result[2]
            except TypeError:
                iterations = result

        if iterations:
            per_iter = delta / iterations
        else:
            per_iter = delta

        processing_rate = units_processed / delta

        print('*   Test duration: total {}, per iteration {}, rate {}'.format( \
            eng_si(delta, 's'), eng_si(per_iter, 's'), eng_si(processing_rate, unit_name + '/s') ))
    def summary(self, a=None, depth=0):
        '''Yield string(s) summarizing this segment and all of its subrecords
        a (StreamRecord or None)
            StreamRecord to produce summary from. Uses self if None.

        depth (int)
            Indentation level for this summary
        '''
        if a is None:
            a = self

        field_name = ''
        if 'name' in a.fields:
            field_name = '({})'.format(a.fields['name'])

        yield '{}{} - {}: {} {}'.format('  ' * depth,
                                        eng_si(a.start_time, 's'),
                                        eng_si(a.end_time, 's'), a, field_name)
        for sr in a.subrecords:
            for s in self.summary(sr, depth + 1):
                yield s
Esempio n. 5
0
def ethernet_decode(rxtx,
                    tag_ethertypes=None,
                    logic_levels=None,
                    stream_type=stream.StreamType.Samples):
    '''Decode an ethernet data stream

    This is a generator function that can be used in a pipeline of waveform
    procesing operations.

    Sample streams are a sequence of SampleChunk Objects. Edge streams are a sequence
    of 2-tuples of (time, int) pairs. The type of stream is identified by the stream_type
    parameter. Sample streams will be analyzed to find edge transitions representing
    0 and 1 logic states of the waveforms. With sample streams, an initial block of data
    is consumed to determine the most likely logic levels in the signal.

    rxtx (iterable of SampleChunk objects or (float, int) pairs)
        A sample stream or edge stream representing a differential ethernet signal.

    tag_ethertypes (sequence of int or None)
        The ethertypes to use for identifying 802.1Q tags. Default is 0x8100, 0x88a8, and 0x9100.

    logic_levels ((float, float) or None)
        Optional pair that indicates (low, high) logic levels of the sample
        stream. When present, auto level detection is disabled. This has no effect on
        edge streams.
    
    stream_type (streaming.StreamType)
        A StreamType value indicating that the can parameter represents either Samples
        or Edges

    Yields a series of EthernetStreamFrame objects. Each frame contains subrecords marking the location
      of sub-elements within the frame. CRC errors are recorded as an error status in their
      respective subrecords.
      
    Raises AutoLevelError if stream_type = Samples and the logic levels cannot
      be determined.
    Raises StreamError if ethernet speed cannot be determined.
    '''

    if stream_type == stream.StreamType.Samples:
        if logic_levels is None:
            s_rxtx_it, logic_levels = decode.check_logic_levels(rxtx)
        else:
            s_rxtx_it = rxtx

        hyst_thresholds = decode.gen_hyst_thresholds(logic_levels,
                                                     expand=3,
                                                     hysteresis=0.05)
        rxtx_it = decode.find_multi_edges(s_rxtx_it, hyst_thresholds)

        #print('## logic levels:', logic_levels, hyst_thresholds)

    else:  # The streams are already lists of edges
        rxtx_it = rxtx

    # Detect speed of ethernet
    buf_edges = 150
    min_edges = 100
    # tee off an iterator to determine speed class
    rxtx_it, speed_check_it = itertools.tee(rxtx_it)

    # Remove Diff-0's #FIX: need to modify to work with 100Mb and 1Gb Enet
    speed_check_it = (edge for edge in speed_check_it if edge[1] != 0)

    symbol_rate_edges = itertools.islice(speed_check_it, buf_edges)

    # We need to ensure that we can pull out enough edges from the iterator slice
    # Just consume them all for a count
    sre_list = list(symbol_rate_edges)
    if len(sre_list) < min_edges:
        raise stream.StreamError(
            'Unable to determine Ethernet speed (not enough edge transitions)')
    del speed_check_it

    #print('## sym. rate edges len:', len(sre_list))

    raw_symbol_rate = decode.find_symbol_rate(iter(sre_list), spectra=2)
    #print('### raw sym rate:', raw_symbol_rate)

    # For 10baseT (10MHz Manchester) the symbol rate will be 20MHz
    # For 100BaseTX the symbol rate will be 31.25MHz?

    if raw_symbol_rate < 25e6:
        bit_period = 1.0 / 10.0e6
    else:
        raise stream.StreamError('Unsupported Ethernet speed: {}'.format(
            eng_si(raw_symbol_rate, 'Hz')))

    if stream_type == stream.StreamType.Samples:
        # We needed the bus speed before we could properly strip just
        # the anomalous SE0s
        min_se0 = bit_period * 0.2
        rxtx_it = decode.remove_transitional_states(rxtx_it, min_se0)

    mstates = manchester_decode(rxtx_it, bit_period)

    for r in _ethernet_generic_decode(mstates, tag_ethertypes=tag_ethertypes):
        yield r
Esempio n. 6
0
def ethernet_decode(rxtx, tag_ethertypes=None, logic_levels=None, stream_type=stream.StreamType.Samples):
    '''Decode an ethernet data stream

    This is a generator function that can be used in a pipeline of waveform
    procesing operations.

    Sample streams are a sequence of SampleChunk Objects. Edge streams are a sequence
    of 2-tuples of (time, int) pairs. The type of stream is identified by the stream_type
    parameter. Sample streams will be analyzed to find edge transitions representing
    0 and 1 logic states of the waveforms. With sample streams, an initial block of data
    is consumed to determine the most likely logic levels in the signal.

    rxtx (iterable of SampleChunk objects or (float, int) pairs)
        A sample stream or edge stream representing a differential ethernet signal.

    tag_ethertypes (sequence of int or None)
        The ethertypes to use for identifying 802.1Q tags. Default is 0x8100, 0x88a8, and 0x9100.

    logic_levels ((float, float) or None)
        Optional pair that indicates (low, high) logic levels of the sample
        stream. When present, auto level detection is disabled. This has no effect on
        edge streams.
    
    stream_type (streaming.StreamType)
        A StreamType value indicating that the can parameter represents either Samples
        or Edges

    Yields a series of EthernetStreamFrame objects. Each frame contains subrecords marking the location
      of sub-elements within the frame. CRC errors are recorded as an error status in their
      respective subrecords.
      
    Raises AutoLevelError if stream_type = Samples and the logic levels cannot
      be determined.
    Raises StreamError if ethernet speed cannot be determined.
    '''

    if stream_type == stream.StreamType.Samples:
        if logic_levels is None:
            s_rxtx_it, logic_levels = decode.check_logic_levels(rxtx)
        else:
            s_rxtx_it = rxtx

        hyst_thresholds = decode.gen_hyst_thresholds(logic_levels, expand=3, hysteresis=0.05)
        rxtx_it = decode.find_multi_edges(s_rxtx_it, hyst_thresholds)

        #print('## logic levels:', logic_levels, hyst_thresholds)

    else: # The streams are already lists of edges
        rxtx_it = rxtx

    # Detect speed of ethernet
    buf_edges = 150
    min_edges = 100
    # tee off an iterator to determine speed class
    rxtx_it, speed_check_it = itertools.tee(rxtx_it)

    # Remove Diff-0's #FIX: need to modify to work with 100Mb and 1Gb Enet
    speed_check_it = (edge for edge in speed_check_it if edge[1] != 0)


    symbol_rate_edges = itertools.islice(speed_check_it, buf_edges)
    
    # We need to ensure that we can pull out enough edges from the iterator slice
    # Just consume them all for a count        
    sre_list = list(symbol_rate_edges)
    if len(sre_list) < min_edges:
        raise stream.StreamError('Unable to determine Ethernet speed (not enough edge transitions)')
    del speed_check_it
        
    #print('## sym. rate edges len:', len(sre_list))
    
    raw_symbol_rate = decode.find_symbol_rate(iter(sre_list), spectra=2)
    #print('### raw sym rate:', raw_symbol_rate)

    # For 10baseT (10MHz Manchester) the symbol rate will be 20MHz
    # For 100BaseTX the symbol rate will be 31.25MHz?

    if raw_symbol_rate < 25e6:
        bit_period = 1.0 / 10.0e6
    else:
        raise stream.StreamError('Unsupported Ethernet speed: {}'.format(eng_si(raw_symbol_rate, 'Hz')))


    if stream_type == stream.StreamType.Samples:
        # We needed the bus speed before we could properly strip just
        # the anomalous SE0s
        min_se0 = bit_period * 0.2
        rxtx_it = decode.remove_transitional_states(rxtx_it, min_se0)


    mstates = manchester_decode(rxtx_it, bit_period)

    for r in _ethernet_generic_decode(mstates, tag_ethertypes=tag_ethertypes):
        yield r