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)
    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
示例#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)
示例#4
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
def start_silent_test():
    # 1. 判断是否满足采集数据的条件
    can_collect, tip_message = Collecter.can_collect_data()
    if not can_collect:
        print(tip_message)
        return

    # 2.将标志位设置为start
    config.run_silent_state = config.SlientState.START
    Collecter.clear_silent_data()

    # 3. 应用置于后台,灭屏
    AndroidUtil.make_app_silent()

    Collecter.auto_silent_collect_process()

    LogUtil.log_i('silent performance data collect success')
    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)
示例#8
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
示例#10
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)
    def get_cpu_data_silent(package_name, pic_name='cpu'):
        i = 0
        while i < config.collect_data_count:
            LogUtil.log_i('Inspect cpu')
            current_page, cpu_data = AndroidUtil.get_cpu_data(package_name)  # 当前采集到的数据
            if cpu_data >= 50.00:

                AdbUtil.screenshot(pic_name)
            else:
                pass
            PerformanceControl.cpu_datas.append([current_page, cpu_data])
            time.sleep(config.collect_data_interval)  # 设定多久采集一次数据
            i += 1
        LogUtil.log_i('Inspect cpu finish')
示例#12
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)
    def can_collect_data(package_name):
        # 1. 判断手机是否连接
        mobile_connect = AdbUtil().attach_devices()
        tips = ''
        if not mobile_connect:
            tips = '请连接设备,当前无设备可用'
            return mobile_connect, tips

        # 2. 判断当前进程是否还活着
        process_alive = AndroidUtil.process_alive(package_name)
        if not process_alive:
            tips = 'app进程已被杀死,请打开app后再开始测试'
            return process_alive, tips

        return True, tips
 def run(self):
     exec_count = 0
     while True:
         LogUtil.log_i('Inspect cpu')
         if exec_count > config.collect_data_count:
             break
         current_page, cpu_datas = AndroidUtil.get_cpu_data(self.package_name)#当前采集到的数据
         if cpu_datas >= 50.00:
             # 对错误进行处理
             AdbUtil.screenshot(self.pic_name)
         else:
             pass
         GetCpuDataThread.cpu_datas.append([current_page, cpu_datas])
         # 设定多久采集一次数据
         time.sleep(config.collect_data_interval)
         exec_count += 1
     LogUtil.log_i('Inspect cpu finish')
示例#15
0
 def run(self):
     i = 0
     pkgName = config.test_package_name
     while i < config.collect_data_count:
         LogUtil.log_i('Inspect cpu')
         cpudata = AndroidUtil.get_cpu_data(pkgName)  #当前采集到的数据
         if cpudata >= 50.00:
             cpuerror = cpudata
             self.CPUerror.append(cpuerror)
             AdbUtil.screenshot()
         else:
             pass
         self.CPUdata.append(cpudata)
         time.sleep(config.collect_data_interval)  #设定多久采集一次数据
         i += 1
     print "CPUerror:", self.CPUerror, "CPUdata:", self.CPUdata
     GetCpuDataThread.task_finish = True
     LogUtil.log_i('Inspect cpu finish')
示例#16
0
    def run(self):
        i = 0
        pkgName = config.test_package_name
        while i < config.collect_data_count:
            LogUtil.log_i('Inspect memory')
            memorydata = int(AndroidUtil.get_memory_data(pkgName))  #当前采集到的数据
            if memorydata >= 50 * 1024:
                memoryerror = memorydata
                self.Memoryerror.append(memoryerror)
                AdbUtil.screenshot()
                LogUtil.log_i('Inspect memory 12')
            LogUtil.log_i('Inspect memory 13')
            self.Memorydata.append(memorydata)
            # time.sleep(self.interval)#设定多久采集一次数据
            i += 1

        GetMemoryDataThread.task_finish = True
        print self.Memoryerror, self.Memorydata
示例#17
0
def get_silent_cpu_data(pic_name='silent_cpu'):
    exec_count = 0
    while True:
        if exec_count > config.collect_data_count:
            __pre_silent_cpu_data()
            __publish_silent_cpu_data()
            break
        # if config.run_finish or config.run_silent_state == config.SlientState.FINISH:
        #     break
        LogUtil.log_i('silent Inspect cpu')
        current_page, cpu_data = AndroidUtil.get_cpu_data(
            package_name)  # 当前采集到的数据
        if cpu_data >= 50.00:

            AdbUtil.screenshot(pic_name)
        else:
            pass
        cpu_datas_silent.append([current_page, cpu_data])
        time.sleep(config.collect_data_interval)  # 设定多久采集一次数据
        exec_count += 1
    LogUtil.log_i('silent Inspect cpu finish')
示例#18
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])
示例#19
0
# -*- coding: utf-8 -*-
import threading
import time
from util.AndroidUtil import AndroidUtil
from util.AdbUtil import AdbUtil
from util.LogUtil import LogUtil
import common.GlobalConfig as config

__author__ = 'lzz'
"""
function: 采集内存数据的逻辑
date:2016/11/23

"""
AdbUtil = AdbUtil()
AndroidUtil = AndroidUtil()


class GetMemoryDataThread(threading.Thread):
    # 用于收集所有的内存数据
    memory_datas = []

    def __init__(self, thread_id, package_name, pic_name='memory'):
        threading.Thread.__init__(self)
        self.threadId = thread_id

        GetMemoryDataThread.clear_data()
        self.pic_name = pic_name
        self.package_name = package_name

    """