def print_last_stats_entry(self): """ Print sum stats over all time intervals. """ # Get reference to the last entry stats = self._stat_objs[-1] # Format strings size_str = data_size_formatter(int(stats['bytes'])*8, in_bytes=True) speed_str = data_size_formatter(int(stats['bits_per_second'])) base_str = '[{}] {:.2f}-{:.2f} sec {} {}/sec'.format( stats['socket'], stats['start'], stats['end'], size_str, speed_str) # Sender / receiver specific if self._test.sender: stat_str = '{} {}'.format(base_str, stats['packets']) else: # TODO: Jitter et. al. stat_str = '{} {:.4f} ms {}/{}'.format( base_str, stats['jitter'] * 1000, stats['errors'], stats['packets']) # Print entry self._logger.info(stat_str)
def test_exact_formatter(self): """Test correct formatter with given prefix""" self.assertEqual(data_size_formatter(10000, False, False, 'k'), '10 Kibs') self.assertEqual(data_size_formatter(80000, False, False, 'K'), '10 KiBytes')
def print_last_stats_entry(self): """ Print sum stats over all time intervals. """ # Get reference to the last entry stats = self._stat_objs[-1] # Format strings size_str = data_size_formatter(int(stats['bytes']) * 8, in_bytes=True) speed_str = data_size_formatter(int(stats['bits_per_second'])) # Print entry self._logger.info('[{}] {:.2f}-{:.2f} sec {} B {}/sec'.format( stats['socket'], stats['start'], stats['end'], size_str, speed_str))
def print_sum_stats(self, stat_list): """Given a list of stats objects print a sum""" # Ignore if empty if not stat_list: return sum_bytes = sum([x['bytes'] for x in stat_list]) sum_bytes_str = data_size_formatter(sum_bytes * 8, in_bytes=True) t_start = stat_list[0]['start'] t_end = stat_list[0]['end'] t_dif = stat_list[0]['seconds'] speed_str = data_size_formatter(int(sum_bytes * 8 / t_dif), dimmension='m') self._logger.info('[{}] {:.2f}-{:.2f} sec {} B {}/sec'.format( 'SUM', t_start, t_end, sum_bytes_str, speed_str)) self._logger.info('- - - - - - - - - - - - - - - - - - - - - - - - -')
def test_size_formatter(self): """Test correct formatting of size strings""" self.assertEqual(data_size_formatter(0, True, False), '0 bit') self.assertEqual(data_size_formatter(100, True, False), '100 bits') self.assertEqual(data_size_formatter(1200, True, False), '1.2 Kibs') self.assertEqual(data_size_formatter(1220000, True, False), '1.22 Mibs') self.assertEqual(data_size_formatter(1226000000, True, False), '1.23 Gibs') self.assertEqual(data_size_formatter(800, True, True), '100 Byte') self.assertEqual(data_size_formatter(167654, False, False), '163.72 Kbits') self.assertEqual(data_size_formatter(76894335, False, False), '73.33 Mbits') self.assertEqual(data_size_formatter(80000, False, True), '9.77 KBytes') # Test negatives: self.assertEqual(data_size_formatter(-800, True, True), '100 Byte')
def display_results(self): """ Display results after the test TODO: Final/Sum results should be generated by each stream """ self._logger.debug('Received results: %s', self.remote_results) self._logger.info('- - - - - - - - - - - - - - - - - - - - - - - - -') self._logger.info('Test Complete. Summary Results:') header = self._streams[0].get_stats_header() self._logger.info(header) local_stats_list = [] remote_stats_list = [] # Get starts from us and remote for stream in self._streams: our_stats = stream.get_final_stats() remote_stats = None # Filter required stream for stat_ob in self.remote_results['streams']: if stat_ob['id'] == our_stats['id']: remote_stats = stat_ob # TODO: Use each streams time length test_len = self._stream_stop_time - self._stream_start_time # Format our numbers our_data_str = data_size_formatter( our_stats['bytes'], None, None, 'm') our_speed_str = data_size_formatter( int(our_stats['bytes'] * 8 / test_len), None, None, 'm') # Format remote numbers remote_data_str = data_size_formatter( remote_stats['bytes'], None, None, 'm') remote_speed_str = data_size_formatter( int(remote_stats['bytes'] * 8 / test_len), None, None, 'm') # Print entry self._logger.info('[{}] 0.00-{:.2f} sec {} {}/sec local'.format( stream.socket_id, test_len, our_data_str, our_speed_str)) self._logger.info('[{}] 0.00-{:.2f} sec {} {}/sec remote'.format( stream.socket_id, test_len, remote_data_str, remote_speed_str)) # Add for later usage (if num stream > 1) local_stats_list.append(our_stats) remote_stats_list.append(remote_stats) # Calculate sum stats if required if len(self._streams) > 1: test_len = self._stream_stop_time - self._stream_start_time sum_local = sum([x['bytes'] for x in local_stats_list]) sum_remote = sum([x['bytes'] for x in remote_stats_list]) # Format our numbers our_data_str = data_size_formatter( sum_local, None, None, 'm') our_speed_str = data_size_formatter( int(sum_local * 8 / test_len), None, None, 'm') # Format remote numbers remote_data_str = data_size_formatter( sum_remote, None, None, 'm') remote_speed_str = data_size_formatter( int(sum_remote * 8 / test_len), None, None, 'm') # Print entry self._logger.info('[SUM] 0.00-{:.2f} sec {} {}/sec local'.format( test_len, our_data_str, our_speed_str)) self._logger.info('[SUM] 0.00-{:.2f} sec {} {}/sec remote'.format( test_len, remote_data_str, remote_speed_str))