def get_memory_data(package_name, pic_name='memory'):
        i = 0
        last_page_name = ''
        last_memory_data = 0
        memory_increase = 0
        while i < config.collect_data_count:
            LogUtil.log_i('Inspect memory')
            memory_data = int(AndroidUtil.get_memory_data(package_name))  # 当前采集到的数据
            now_page_name = AndroidUtil.get_cur_activity()
            # 目前暂时粗略的计算增量,当页面不一样时,计算增量
            if now_page_name != last_page_name:
                memory_increase = memory_data - last_memory_data
                if memory_increase < 0:
                    # 对于发生GC的情况,内存增量可能是负值, 暂时先不做处理
                    pass
                PerformanceControl.memory_datas.append([now_page_name, last_page_name, memory_increase])
                last_page_name = now_page_name
            else:
                last_memory_data = memory_data
                i += 1
                continue
            # 内存增量大于某个值就认为是有问题
            if memory_increase >= 10 * 1024:
                AdbUtil.screenshot(pic_name)
                LogUtil.log_i('Inspect memory 12')
            LogUtil.log_i('Inspect memory 13')

            # 设定多久采集一次数据
            time.sleep(config.collect_data_interval)
            i += 1
    def get_fps_data(package_name, pic_name='fps'):
        # 处理可能有问题的场景
        def handle_error_data(jank_count, fps):
            # 暂时当fps < 50 或者 jank_count > 10 我们认为是不达标的
            if fps < 50 or jank_count > 10:
                # 截图
                AdbUtil.screenshot(pic_name)
                # 保存日志

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

            # 采集数据
            frame_count, jank_count, fps = AndroidUtil.get_fps_data_by_gfxinfo(package_name)
            if frame_count is None and jank_count is None and fps is None:
                exec_count += 1
                continue
            current_page = AndroidUtil.get_cur_activity()
            PerformanceControl.fps_datas.append([frame_count, jank_count, fps, current_page])

            # 处理有问题的数据
            handle_error_data(jank_count, fps)
            exec_count += 1

            # 采集数据时间间隔
            time.sleep(config.collect_data_interval)
Exemple #3
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)
Exemple #6
0
def get_memory_data(pic_name='memory'):
    exec_count = 0
    while True:
        if exec_count > config.collect_data_count:
            __pre_memory_data()
            __publish_memory_data()
            break
        # if config.run_finish:
        #     break

        LogUtil.log_i('Inspect memory' + str(exec_count))
        memory_data = int(
            AndroidUtil.get_memory_data(package_name))  # 当前采集到的数据
        now_page_name = AndroidUtil.get_cur_activity()
        memory_datas.append([now_page_name, memory_data])
        # 内存增量大于某个值就认为是有问题
        if memory_data >= 10 * 1024:
            AdbUtil.screenshot(pic_name)

        # 设定多久采集一次数据
        time.sleep(config.collect_data_interval)
        exec_count += 1
    def run(self):
        # 处理可能有问题的场景
        def handle_error_data(frame_count, jank_count, fps, current_page):
            # 暂时当fps < 50 或者 jank_count > 10 我们认为是不达标的
            if fps < 50 or jank_count > 10:
                # 截图
                AdbUtil.screenshot(self.pic_name)
                # 保存日志

                GetFpsDataThread.fps_error_datas.append([
                    frame_count, jank_count, fps, current_page, self.pic_name
                ])

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

            # 采集数据
            frame_count, jank_count, fps = AndroidUtil.get_fps_data_by_gfxinfo(
                self.package_name)
            if frame_count is None and jank_count is None and fps is None:
                exec_count += 1
                continue
            current_page = AndroidUtil.get_cur_activity()
            GetFpsDataThread.fps_datas.append(
                [frame_count, jank_count, fps, current_page])

            # 处理有问题的数据
            handle_error_data(frame_count, jank_count, fps, current_page)
            exec_count += 1

            # 采集数据时间间隔
            time.sleep(config.collect_data_interval)
        GetFpsDataThread.task_finish = True
Exemple #8
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)
Exemple #9
0
    def run(self):
        exec_count = 0
        last_page_name = ''
        last_memory_data = 0
        try:
            while True:
                LogUtil.log_i('Inspect memory')
                if exec_count > config.collect_data_count:
                    break
                memory_data = int(
                    AndroidUtil.get_memory_data(self.package_name))  #当前采集到的数据
                now_page_name = AndroidUtil.get_cur_activity()
                # 目前暂时粗略的计算增量,当页面不一样时,计算增量
                if now_page_name != last_page_name:
                    memory_increase = memory_data - last_memory_data
                    if memory_increase < 0:
                        # 对于发生GC的情况,内存增量可能是负值, 暂时先不做处理
                        pass
                    GetMemoryDataThread.memory_datas.append(
                        [now_page_name, last_page_name, memory_increase])
                    last_page_name = now_page_name
                else:
                    last_memory_data = memory_data
                    exec_count += 1
                    continue

                # 内存增量大于某个值就认为是有问题
                if memory_increase >= 10 * 1024:
                    AdbUtil.screenshot(self.pic_name)
                    LogUtil.log_i('Inspect memory 12')
                LogUtil.log_i('Inspect memory 13')

                # 设定多久采集一次数据
                time.sleep(config.collect_data_interval)
                exec_count += 1
        except Exception as e:
            LogUtil.log_e('get cpu error' + e.message)
Exemple #10
0
 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])