Exemple #1
0
    def read_logs(self, files):
        self.name = files
        current_file = open(files, 'rU')
        lines = current_file.readlines()
        for line in lines:
            r = RateControlUtil.SETTING_TYPE_RE.search(line)
            if r is not None:
                cur_dt = RateControlUtil.extract_timestamp(line)
                self.usage_type = int(r.groups()[0])
                continue

            r = RateControlUtil.LAYER_SETTING_RE.search(line)
            if r is not None:
                cur_dt = RateControlUtil.extract_timestamp(line)
                self.get_settings(cur_dt, r)
                continue

            r = RateControlUtil.SETOPTION_BR_RE.search(line)
            if r is not None:
                cur_dt = RateControlUtil.extract_timestamp(line)
                RateControlUtil.option_br_update(self.settings, cur_dt,
                                                 int(r.group(1)))
                continue

            r = RateControlUtil.SETOPTION_MAXBR_RE.search(line)
            if r is not None:
                cur_dt = RateControlUtil.extract_timestamp(line)
                RateControlUtil.option_max_br_update(self.settings, cur_dt,
                                                     int(r.group(1)))
                continue

            r = RateControlUtil.ENCODER_STAT_LOG_RE.search(line)
            if r is not None:
                cur_dt = RateControlUtil.extract_timestamp(line)
                ts = self.check_ts(r.group(14))
                encoded_bytes = int(r.group(13))
                self.stats.append((cur_dt, ts, encoded_bytes))

                self.idr.append(int(r.group(12)))
                self.frame_skipped.append(int(r.group(9)))
                continue

            r = RateControlUtil.VIDEO_LAYER_LOG_RE.search(line)
            if r is not None:
                cur_dt = RateControlUtil.extract_timestamp(line)
                did = __init__.get_did_from_resolution(int(r.group(1)),
                                                       int(r.group(2)))
                br = int(r.group(4))
                if br > 0:
                    self.layer_stats.append((cur_dt, did, br))
                continue

        current_file.close()
    def get_settings(self, time, r):
        cur_settings = {}
        RateControlUtil.settings_log(time, r, cur_settings)
        if self.usage_type == 0:
            cur_settings['timewindow'] = 5000  # ms
            cur_settings['fluctuation_range'] = 0.1
        elif self.usage_type == 1:
            cur_settings['timewindow'] = 10000  # ms
            cur_settings['fluctuation_range'] = 0.3

        cur_settings['target_bit_rate_upper'] = int(cur_settings['target_bit_rate'] * (1+cur_settings['fluctuation_range']) + 0.5)

        self.settings.append(cur_settings)
    def read_logs(self, files):
        self.name = files
        current_file = open(files, 'rU')
        lines = current_file.readlines()
        for line in lines:
            r = RateControlUtil.SETTING_TYPE_RE.search(line)
            if r is not None:
                cur_dt = RateControlUtil.extract_timestamp(line)
                self.usage_type = int(r.groups()[0])
                continue

            r = RateControlUtil.LAYER_SETTING_RE.search(line)
            if r is not None:
                cur_dt = RateControlUtil.extract_timestamp(line)
                self.get_settings(cur_dt, r)
                continue

            r = RateControlUtil.SETOPTION_BR_RE.search(line)
            if r is not None:
                cur_dt = RateControlUtil.extract_timestamp(line)
                RateControlUtil.option_br_update(self.settings, cur_dt, int(r.group(1)))
                continue

            r = RateControlUtil.SETOPTION_MAXBR_RE.search(line)
            if r is not None:
                cur_dt = RateControlUtil.extract_timestamp(line)
                RateControlUtil.option_max_br_update(self.settings, cur_dt, int(r.group(1)))
                continue

            r = RateControlUtil.ENCODER_STAT_LOG_RE.search(line)
            if r is not None:
                cur_dt = RateControlUtil.extract_timestamp(line)
                ts = self.check_ts(r.group(14))
                encoded_bytes = int(r.group(13))
                self.stats.append((cur_dt, ts, encoded_bytes))

                self.idr.append(int(r.group(12)))
                self.frame_skipped.append(int(r.group(9)))
                continue

            r = RateControlUtil.VIDEO_LAYER_LOG_RE.search(line)
            if r is not None:
                cur_dt = RateControlUtil.extract_timestamp(line)
                did = __init__.get_did_from_resolution(int(r.group(1)),int(r.group(2)))
                br = int(r.group(4))
                if br>0:
                    self.layer_stats.append((cur_dt, did, br))
                continue

        current_file.close()
    def read_logs(self, files):
        self.name = files
        current_file = open(files, 'rU')
        lines = current_file.readlines()
        for line in lines:
            r = self.basic_setting_match_re1.search(line)
            if r is not None:
                self.usage_type = int(r.groups()[0])
                continue

            r = self.setting_match_re.search(line)
            if r is not None:
                setting_time = 0
                if len(self.frames[0]['timestamp']) > 0:
                    setting_time = self.frames[-1].ts
                self.get_settings(setting_time, r)
                continue

            r = self.rc_log_match_re.search(line)
            if r is not None:
                self.add_one_frame(self.check_ts(r.group(1)), [int( r.group(i)) for i in range(2,9)] )
                continue

            r = self.rc_m_log_match_re.search(line)
            if r is not None:
                self.add_one_multi_layer_frame(self.check_ts(r.group(2)), int(r.group(1)), [int( r.group(i)) for i in range(3,10)])
                continue

            r = self.rc_skip_frame_match_re.search(line)
            if r is not None:
                self.add_one_skipped_frame(self.check_ts(r.group(1)), r)
                continue

            r = self.setoption_br_match.search(line)
            if r is not None:
                setting_time = self.get_last_frame_ts()
                RateControlUtil.option_br_update(self.settings, setting_time, int(r.group(1)))
                continue

            r = self.setoption_maxbr_match.search(line)
            if r is not None:
                setting_time = self.get_last_frame_ts()
                RateControlUtil.option_max_br_update(self.settings, setting_time, int(r.group(1)))
                continue

        current_file.close()
Exemple #5
0
    def plot_overall_graph(self):
        max_d_layer = max([item['did'] for item in self.settings])
        axes_count = 2 if max_d_layer == 0 else (1 + self.MAX_D_LAYER)
        axes_count += 1 if max(self.idr) > 0 else 0
        axes_count += 1 if max(self.frame_skipped) > 0 else 0
        print('draw %d charts\n' % axes_count)
        fig, axes = plt.subplots(axes_count, 1, sharex=True)
        plt.xlabel('time')

        axes[0].plot(self.dt_list, self.br_list, label='actual_bit_rate')
        axes[0].legend()

        if max_d_layer > 0:
            for layer_idx in range(self.MAX_D_LAYER):
                cur_list = [
                    item for item in self.settings
                    if layer_idx == __init__.get_did_from_resolution(
                        item['width'], item['height'])
                ]
                if cur_list == []:
                    axes[layer_idx + 1].plot(self.dt_list,
                                             self.br_list,
                                             label='actual_bit_rate')
                else:
                    for info in ('max_bit_rate', 'target_bit_rate_upper'):
                        axes[layer_idx +
                             1].plot([item['ts'] for item in cur_list],
                                     [item[info] for item in cur_list],
                                     label=info + '_%d' % layer_idx)

                cur_list = [
                    item for item in self.layer_stats if item[1] == layer_idx
                ]
                if cur_list == []:
                    axes[layer_idx + 1].plot(self.dt_list,
                                             self.br_list,
                                             label='actual_bit_rate')
                    axes[layer_idx + 1].legend()
                else:
                    axes[layer_idx + 1].plot([item[0] for item in cur_list],
                                             [item[2] for item in cur_list],
                                             label='layer_%d' % layer_idx)
                    axes[layer_idx + 1].legend()

        else:
            cur_list = [item for item in self.settings]
            for info in ('max_bit_rate', 'target_bit_rate_upper',
                         'target_bit_rate'):
                axes[0].plot([item['ts'] for item in cur_list],
                             [item[info] for item in cur_list],
                             label=info)
            axes[1].plot(
                [item['ts'] for item in self.settings],
                [item['width'] + item['height'] for item in self.settings],
                label='resolution')
            axes[1].legend()

        axes_idx = 2 if max_d_layer == 0 else (1 + self.MAX_D_LAYER)
        if max(self.idr) > 0:
            axes[axes_idx].plot([item[0] for item in self.stats[1:]],
                                RateControlUtil.get_derive(self.idr),
                                '-o',
                                label='idr_count')
            axes[axes_idx].legend()
            axes_idx += 1

        if max(self.frame_skipped) > 0:
            axes[axes_idx].plot([item[0] for item in self.stats[1:]],
                                RateControlUtil.get_derive(self.frame_skipped),
                                '-o',
                                label='frame_skipped_count')
            axes[axes_idx].legend()
        x = [item[0] for item in self.stats[1:]]
        y = RateControlUtil.get_derive(self.frame_skipped)
        for p1, p2 in zip(x, y):
            print("%s,%d\n" % (p1, p2))

        plt.savefig('RatesinLog.png')
        plt.show()
    def plot_overall_graph(self):
        max_d_layer = max([item['did'] for item in self.settings])
        axes_count = 2 if max_d_layer == 0 else (1+self.MAX_D_LAYER)
        axes_count += 1 if max(self.idr) > 0 else 0
        axes_count += 1 if max(self.frame_skipped) > 0 else 0
        print('draw %d charts\n' %axes_count)
        fig, axes = plt.subplots(axes_count, 1, sharex=True)
        plt.xlabel('time')

        axes[0].plot(self.dt_list, self.br_list, label='actual_bit_rate')
        axes[0].legend()

        if max_d_layer>0:
            for layer_idx in range(self.MAX_D_LAYER):
                cur_list = [item for item in self.settings
                            if layer_idx == __init__.get_did_from_resolution(item['width'],item['height'])]
                if cur_list == []:
                    axes[layer_idx+1].plot(self.dt_list, self.br_list, label='actual_bit_rate')
                else:
                    for info in ('max_bit_rate', 'target_bit_rate_upper'):
                        axes[layer_idx+1].plot([item['ts'] for item in cur_list],
                                 [item[info] for item in cur_list],
                                 label=info+'_%d' %layer_idx)

                cur_list = [item for item in self.layer_stats if item[1]==layer_idx]
                if cur_list == []:
                    axes[layer_idx+1].plot(self.dt_list, self.br_list, label='actual_bit_rate')
                    axes[layer_idx+1].legend()
                else:
                    axes[layer_idx+1].plot([item[0] for item in cur_list],
                                 [item[2] for item in cur_list],
                                 label='layer_%d' %layer_idx)
                    axes[layer_idx+1].legend()

        else:
            cur_list = [item for item in self.settings]
            for info in ('max_bit_rate', 'target_bit_rate_upper', 'target_bit_rate'):
                axes[0].plot([item['ts'] for item in cur_list],
                                 [item[info] for item in cur_list],
                                 label=info)
            axes[1].plot([item['ts'] for item in self.settings],
                     [item['width']+item['height'] for item in self.settings], label='resolution')
            axes[1].legend()

        axes_idx = 2 if max_d_layer==0 else (1+self.MAX_D_LAYER)
        if max(self.idr) > 0:
            axes[axes_idx].plot([item[0] for item in self.stats[1:]],
                                  RateControlUtil.get_derive(self.idr),
                                  '-o', label='idr_count')
            axes[axes_idx].legend()
            axes_idx += 1

        if max(self.frame_skipped) > 0:
            axes[axes_idx].plot([item[0] for item in self.stats[1:]],
                                  RateControlUtil.get_derive(self.frame_skipped),
                                  '-o', label='frame_skipped_count')
            axes[axes_idx].legend()
        x=[item[0] for item in self.stats[1:]]
        y=RateControlUtil.get_derive(self.frame_skipped)
        for p1,p2 in zip(x,y):
            print("%s,%d\n" %(p1,p2))

        plt.savefig('RatesinLog.png')
        plt.show()