Exemple #1
0
def changeSceneTimer(env, filelist, scenelist, testModel, _TimeValue, index,
                     intervalVar):
    global sceneTimer
    info = get_info()
    sceneTimer = Timer(
        info.change_pcm_list_interval, scenePro,
        (env, filelist, scenelist, testModel, _TimeValue, index, intervalVar))
    sceneTimer.start()
Exemple #2
0
def deleteOldCrashfile(env):
    from androidanalysis.constant.Process_Constant import get_info
    info = get_info()
    if info.need_delete_old_file:
        runAdbCommand(env, ['shell', 'rm', '/sdcard/txz/report/*'])
        runAdbCommand(env, ['shell', 'rm', '/sdcard/preburning/asr/*'])
        runAdbCommand(env, ['shell', 'rm', '/sdcard/preburning/pcm/*'])
        runAdbCommand(env, ['shell', 'rm', '/sdcard/hprof/*'])
        runAdbCommand(env, ['shell', 'rm', '/data/anr'])
        runAdbCommand(env, ['shell', 'rm', '/data/tombstones/'])
Exemple #3
0
def changeScene(env, filelist, scenelist, testModel, _TimeValue, index,
                intervalVar):
    stopPreburn(env, testModel)
    orgPath = filelist[index]
    scenelist.append(orgPath)
    runAdbCommand(env, ['shell', 'rm', '/sdcard/preburning/pcm/*'])
    pushfiletoandroid(env, orgPath, _ENV_PCM + 'pcm/')
    writeLog(env, 'Current Scene:{0}'.format(orgPath))
    if intervalVar:
        info = get_info()
        time.sleep(info.change_pcm_interval)
    obtainHprof(env, filelist[index - 1])
    startPreburn(env, testModel, _TimeValue)
Exemple #4
0
def mytimer(env, _StopMark):
    global txzlogtimer
    global pidtimer
    global memtimer
    from androidanalysis.constant.Process_Constant import get_info
    info = get_info()
    txzlogtimer = Timer(info.interval_pull_log, getReport, (env, 'txzlog_', info.interval_pull_log))
    pidtimer = Timer(info.interval_pid_fd_task, pidPro, (
        env, _StopMark, info.interval_pid_fd_task
    ))
    memtimer = Timer(info.interval_mem, memPro, (env, _StopMark, info.interval_mem))
    memtimer.start()
    pidtimer.start()
    txzlogtimer.start()
Exemple #5
0
def scenePro(env, filelist, scenelist, testModel, _TimeValue, index,
             intervalVar):
    global sceneTimer
    threading.Thread(target=changeScene,
                     args=(env, filelist, scenelist, testModel, _TimeValue,
                           index, intervalVar)).start()
    index += 1
    if index == len(filelist):
        index = 0
    info = get_info()
    sceneTimer = Timer(
        info.change_pcm_list_interval, scenePro,
        (env, filelist, scenelist, testModel, _TimeValue, index, intervalVar))
    sceneTimer.start()
def init_env(_StopMark):
    info = get_info()
    setObservedLists(info.process_names)  # 取出 被观察的 包名
    env = genEnv(info.dev)
    writeLog(env, "开启所有日志开关")
    openlog(env)  # 开启所有的日志
    writeLog(env, "强杀 Core 的进程:com.txznet.txz")
    killApkPid(env, 'com.txznet.txz')
    writeLog(env, "删除设备原有的 crash pcm asr hprof 的数据")
    deleteOldCrashfile(env)
    if info.need_pull_core_apk:
        writeLog(env, "取出当前设备的Core 的apk")
        pullInitialAPK(env)  # 取出 core 的apk  #FIXME: 耗时太久
    if info.mode != 3:
        writeLog(env, "您选择了 模式" + str(info.mode))
        writeLog(env, "开始为您取出本目录所有的pcm文件夹")
        fileList = obtainPcmList()
        if len(fileList) == 0:
            writeLog(env, "请更改当前的模式 或者 导入您需要 老化的音频数据到 pcm文件夹")
            return None
        writeLog(env, "size : " + str(fileList[0]))
        ret = 0
        ret = prepareDevice(env, _StopMark, fileList[0])
        if ret == -1:
            writeLog(env, "请确定 老化工具的apk 在当前目录上面")
            return None
        if ret == -2:
            writeLog(env, "已被中断执行")
            return None
        # 如果 打开切换音频集 的开关选项, 则需要每隔一定的时间进行音频集的切换
        if info.is_open_change_pcm_list():
            scene_list = [fileList[0]]
            changeSceneTimer(env, fileList, scene_list, info.mode,
                             info.wifi_change_interval, 1,
                             info.is_open_change_pcm_list_interval())
    writeLog(env, "开始在设备中创建文件夹")
    runAdbCommand(env, ['shell', 'mkdir', '-p', '/sdcard/hprof'])
    runAdbCommand(env, [
        'pull', '/proc/net/xt_qtaguid/stats',
        os.path.join(env['flow'], 'stats_' + str(time.time()))
    ])
    writeLog(env, "开始为您拉取 hprof 文件")
    start_hprof(env)
    writeLog(env, "正在为您发送广播")
    startPreburn(env, info.mode, info.wifi_change_interval)

    return env
Exemple #7
0
def prepareDevice(env, _StopMark, curpath):
    writeLog(env, '>>>准备环境')
    obtainRoot(env)
    from androidanalysis.constant.Process_Constant import get_info
    info = get_info()
    if info.need_replace_burning_apk:
        if not checkenv(env, Preburning, 'preburning.apk', _StopMark):
            return -1
    if _StopMark.value:
        return -2
    launch_apk(env, 'com.txznet.txz')
    launch_apk(env, 'com.txznet.preburning')
    runAdbCommand(env, ['shell', 'mkdir', '-p', _ENV_PCM + 'pcm'])
    pushfiletoandroid(env, curpath, _ENV_PCM + 'pcm/')
    writeLog(env, 'Current Scene:{0}'.format(curpath))
    runAdbCommand(env, ['push', './command.txt', _ENV_PCM])
    return 0
Exemple #8
0
def excute(env, _StopMark, testModel):
    from androidanalysis.utils.CpuUtils import start_monitor_pid_cpu_usage, start_monitor_thread_cpu_usage
    from androidanalysis.constant.ObservedProcess import getObservedLists
    from AnalysisPid import getPidFromPackage
    from androidanalysis.constant.Process_Constant import get_info

    global errorstauts
    global sceneTimer
    info = get_info()
    writeLog(env, '>>>开始抓取TOP数据')
    # 定时启动项
    mytimer(env, _StopMark)  # FIXMe 暂时注释
    timerMark = True
    # _top_thread_cmd = ['adb', '-s', env['dev'], 'shell', 'top', '-t', '-d', '1', '-n', '1']
    # _top_thread_p = subprocess.Popen(_top_thread_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    # _syslog_cmd = ['adb', '-s', env['dev'], 'logcat', '-v', 'time']
    # _syslog_p = subprocess.Popen(_syslog_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    # _top_process_cmd = ['adb', '-s', env['dev'], 'shell', 'top', '-d', '1', '-n', '1']
    # _top_process_p = subprocess.Popen(_top_process_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

    from androidanalysis.utils.DeviceInfo import start_get_sys_log
    start_get_sys_log(env, _StopMark)

    count = 51200
    while not _StopMark.value:
        if os.path.exists(stopApkMark):
            try:
                sceneTimer.cancel()
            except:
                pass
            stopPreburn(env, testModel)
            os.remove(stopApkMark)
            obtainHprof(env)
        easytime = time.strftime('%Y%m%d_%H%M%S', time.localtime())
        Top_thread_file_name = 'Top_thread_data_%s.log' % (easytime)
        Top_process_file_name = 'Top_process_data_%s.log' % (easytime)
        with open(os.path.join(env['top_thread_logpath'], Top_thread_file_name), 'wb') as top_thread_file, \
                open(os.path.join(env['top_process_logpath'], Top_process_file_name), 'wb') as top_process_file:
            while count:
                writeLog(env, ">>>------------抓取cpu数据------------")
                if os.path.exists(stopApkMark):
                    try:
                        sceneTimer.cancel()
                    except:
                        pass
                    stopPreburn(env, testModel)
                    os.remove(stopApkMark)
                    obtainHprof(env)
                count -= 1
                if _StopMark.value:
                    break
                else:
                    def write2File(log_file, content):
                        log_file.writelines(content)
                        log_file.flush()

                    def writeCpuThreadCallback(process, parent_pid, pid, usage):
                        recordtime = time.strftime('%Y%m%d_%H%M%S', time.localtime())
                        write2File(top_thread_file,
                                   "{0},{1},{2},{3},{4}\n".format(recordtime, process, parent_pid, pid, usage))

                    def writeCpuPidCallback(process, parent_pid, pid, usage):
                        recordtime = time.strftime('%Y%m%d_%H%M%S', time.localtime())
                        write2File(top_process_file,
                                   "{0},{1},{2},{3},{4}\n".format(recordtime, process, parent_pid, pid, usage))

                    for process in getObservedLists():
                        pid = getPidFromPackage(env, process)
                        if pid == -1:
                            # writeLog(env, "can't find process:" + process)
                            continue
                        start_monitor_pid_cpu_usage("", 0.1, pid, writeCpuPidCallback)
                        start_monitor_thread_cpu_usage("", 0.1, pid, writeCpuThreadCallback)

                top_process_file.write("\n")
                top_thread_file.write("\n")
                if errorstauts:
                    _StopMark.value = True

            time.sleep(info.interval_cpu)
            if _StopMark.value:
                try:
                    sceneTimer.cancel()
                except:
                    pass
                from androidanalysis.utils.TimerUtils import mytimercancel
                mytimercancel(env, timerMark)
                break
            top_thread_file.close()
            top_process_file.close()
            count = 51200
            if errorstauts:
                _StopMark.value = True
        writeLog(env, ">>>------------抓取cpu数据------------ 完成")