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
예제 #2
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
예제 #3
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
예제 #4
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)