Example #1
0
    def run(self):
        # 处理有问题的流量数据,暂定有问题的流量是大于1M时
        def handle_error_data(current_flow):
            if current_flow > 1 * 1024:
                current_page = AndroidUtil.get_cur_activity()
                AdbUtil.screenshot(self.pic_name)
                GetFlowDataThread.flow_error_datas.append(
                    [current_flow, current_page, self.pic_name])

        # 死循环,满足条件后跳出
        exec_count = 0
        while True:
            log.log_i('get flow data' + str(exec_count))
            # 判断执行了多少次
            if exec_count > config.collect_data_count:
                break

            # 采集数据 返回三个值,接收的流量、发送的流量、流量总数据,单位是KB
            flow_recv, flow_send, flow_total = AndroidUtil.get_flow_data(
                self.package_name)

            if exec_count > 0:
                self.current_flow_data = flow_total - self.last_flow_data
                GetFlowDataThread.flow_datas.append(self.current_flow_data)
                handle_error_data(self.current_flow_data)

            exec_count += 1
            self.last_flow_data = flow_total

            # 时间间隔
            time.sleep(config.collect_data_interval)

        GetFlowDataThread.task_finish = True
Example #2
0
def get_flow_data(pic_name='flow'):
    # 处理有问题的流量数据,暂定有问题的流量是大于1M时
    def handle_error_data(current_flow):
        if current_flow > 5 * 1024:
            # 异常处理
            AdbUtil.screenshot(pic_name)

    # 死循环,满足条件后跳出
    exec_count = 0
    last_flow_data = 0
    last_page_name = ''
    first_flow_data = 0
    while True:
        LogUtil.log_i('get flow data' + str(exec_count))
        # 判断执行了多少次
        if exec_count > config.collect_data_count:
            __pre_flow_data()
            __publish_flow_data()
            break

        # if config.run_finish:
        #     break

        # 采集数据 返回三个值,接收的流量、发送的流量、流量总数据,单位是KB
        flow_recv, flow_send, flow_total = AndroidUtil.get_flow_data(
            package_name)
        now_page_name = AndroidUtil.get_cur_activity()
        # print("flow_total" + str(flow_total))
        # print ("last_flow_data" + str(last_flow_data))
        # print ("first_flow_data" + str(first_flow_data))
        # 这里计算每个页面的流量消耗情况
        if exec_count <= 0:
            # 避免第一次少计算一次值造成误差
            first_flow_data = flow_total
        elif exec_count < config.collect_data_count:
            if now_page_name == last_page_name:
                # last_flow_data = flow_total
                exec_count += 1
                continue
            else:
                flow_increase = flow_total - first_flow_data
                handle_error_data(flow_increase)
                flow_datas.append([last_page_name, round(flow_increase, 2)])
                first_flow_data = flow_total
        elif exec_count == config.collect_data_count:
            if last_page_name == now_page_name:
                flow_increase = flow_total - first_flow_data
                handle_error_data(flow_increase)
                flow_datas.append([now_page_name, round(flow_increase, 2)])

        # 用于记录每次的流量增量
        last_page_name = now_page_name
        exec_count += 1
        # 时间间隔
        time.sleep(config.collect_data_interval)
    def run(self):
        # 处理有问题的流量数据,暂定有问题的流量是大于1M时
        def handle_error_data(current_flow):
            if current_flow > 1 * 1024:
                AdbUtil.screenshot(self.pic_name)

        # 死循环,满足条件后跳出
        exec_count = 0
        last_flow_data = 0
        last_page_name = ''
        last_flow = 0
        current_flow_data = 0

        while True:
            log.log_i('get flow data' + str(exec_count))
            # 判断执行了多少次
            if exec_count > config.collect_data_count:
                break

            # 采集数据 返回三个值,接收的流量、发送的流量、流量总数据,单位是KB
            flow_recv, flow_send, flow_total = AndroidUtil.get_flow_data(
                self.package_name)
            now_page_name = AndroidUtil.get_cur_activity()

            if exec_count > 0:
                current_flow_data = flow_total - last_flow_data
                if now_page_name != last_page_name:
                    flow_increase = current_flow_data - last_flow
                    last_page_name = now_page_name
                    GetFlowDataThread.flow_datas.append(
                        [now_page_name, last_page_name, flow_increase])
                    handle_error_data(flow_increase)

            # 用于记录每次的流量增量
            last_flow = current_flow_data
            exec_count += 1
            last_flow_data = flow_total

            # 时间间隔
            time.sleep(config.collect_data_interval)
    def get_flow_data(package_name, pic_name='flow'):
        # 处理有问题的流量数据,暂定有问题的流量是大于1M时
        def handle_error_data(current_flow):
            if current_flow > 5 * 1024:
                # 异常处理
                AdbUtil.screenshot(pic_name)

        # 死循环,满足条件后跳出
        exec_count = 0
        last_flow_data = 0
        last_page_name = ''
        last_flow = 0
        current_flow_data = 0
        while True:
            LogUtil.log_i('get flow data' + str(exec_count))
            # 判断执行了多少次
            if exec_count > config.collect_data_count:
                break

            # 采集数据 返回三个值,接收的流量、发送的流量、流量总数据,单位是KB
            flow_recv, flow_send, flow_total = AndroidUtil.get_flow_data(package_name)
            now_page_name = AndroidUtil.get_cur_activity()

            if exec_count > 0:
                current_flow_data = flow_total - last_flow_data
                if now_page_name != last_page_name:
                    flow_increase = current_flow_data - last_flow
                    last_page_name = now_page_name
                    PerformanceControl.flow_datas.append([now_page_name, last_page_name, flow_increase])
                    handle_error_data(flow_increase)

            # 用于记录每次的流量增量
            last_flow = current_flow_data
            exec_count += 1
            # 用于计算每次采集流量增量
            last_flow_data = flow_total

            # 时间间隔
            time.sleep(config.collect_data_interval)
Example #5
0
def get_flow_silent(pic_name='silentflow'):
    # 处理有问题的流量数据,暂定有问题的流量是大于1M时
    def handle_error_data(current_flow):
        if current_flow > 5 * 1024:
            # 异常处理
            AdbUtil.screenshot(pic_name)

    # 死循环,满足条件后跳出
    exec_count = 0
    last_flow_data = 0
    while True:
        LogUtil.log_i('get flow data' + str(exec_count))
        # 判断执行了多少次
        if exec_count > config.collect_data_count:
            __pre_silent_flow_data()
            __publish_silent_flow_data()
            break

        # if config.run_silent_state == config.SlientState.FINISH:
        #     break

        # 采集数据 返回三个值,接收的流量、发送的流量、流量总数据,单位是KB
        flow_recv, flow_send, flow_total = AndroidUtil.get_flow_data(
            package_name)

        if exec_count > 0:
            now_page_name = AndroidUtil.get_cur_activity()
            current_flow_data = flow_total - last_flow_data

            flow_datas_silent.append([now_page_name, current_flow_data])
            handle_error_data(current_flow_data)

        exec_count += 1
        # 用于计算每次采集流量增量
        last_flow_data = flow_total

        # 时间间隔
        time.sleep(config.collect_data_interval)