def getProcessAndTaskInfo(pkg): cpuProcessInfo = cpu_info_process.CpuProcessInfo() pid = utils.getPid(pkg) log_utils.log(pid) cmd = "adb shell cat proc/%s/task/*/stat" % (pid).replace("\n", "") content = utils.excuteCmd(cmd) cpuProcessInfo.getCpuInfo(pid) taskCpuLineArr = content.splitlines() tasksTotal = 0 threadCpuArr = [] for i in range(len(taskCpuLineArr)): threadCpuInfo = cpu_info_thread.CpuThreadsInfo() threadCpuInfo.parseThreadData(taskCpuLineArr[i]) tasksTotal = tasksTotal + threadCpuInfo.getTotal() threadCpuArr.append(threadCpuInfo) threadCpuArr = sorted(threadCpuArr, key=lambda x: x.total, reverse=True) for i in range(len(threadCpuArr)): item = threadCpuArr[i] log_utils.log("%s\t[%s][%s]\tused cpu \t%.2f %% \t\t%s" % (item.threadName.ljust(20), str( item.threadId).ljust(4), item.threadStatus, (item.getTotal() * 100 / cpuProcessInfo.getTotal()), item.getTotal())) log_utils.log("tasksTotal / processTotal : %.5f" % (tasksTotal / cpuProcessInfo.getTotal())) log_utils.log("cout %d : taskTotal %d processTotal %d" % (len(threadCpuArr), tasksTotal, cpuProcessInfo.getTotal()))
def execute(pkgArr, filePath): for pkgName in pkgArr: pid = utils.getPid(pkgName) if len(pid) == 0: log_utils.log("process %s not run" % (pkgName)) else: recordMem(pid, pkgName, filePath)
def execute(pkgNameArr, filePath): for pkgName in pkgNameArr: pid = utils.getPid(pkgName) if len(pid) == 0: log_utils.log("process %s not run" % (pkgName)) else: content = utils.getTime() + "|" + pid + "\n" file_utils.writeFileAdd(filePath + pkgName + "_pid.txt", content)
def execute(pkgArr, filePath): time = utils.getTime() log_utils.log("------------catch fdcount------------") for pkg in pkgArr: pid = utils.getPid(pkg) fdCommand = 'adb shell ls proc/' + pid + '/fd | wc -l' fdCount = utils.excuteCmd(fdCommand) content = time + "|" + fdCount fdPath = filePath + pkg + "_fd.txt" file_utils.writeFileAdd(fdPath, content)
def dumpCpu(self, time, totalCpu, filePath): pid = utils.getPid(self.pkgName) if self.pid != 0 and pid != 0 and self.pid != pid: # pid有变化,需要清空上一次的的取值,从新取值 self.lastProcessCpuInfo = None cpuProcessInfo = cpu_info_process.CpuProcessInfo() cpuProcessInfo.getCpuInfo(pid) self.lastProcessCpuInfo = cpuProcessInfo self.pid = pid return cpuProcessInfo = cpu_info_process.CpuProcessInfo() cpuProcessInfo.getCpuInfo(pid) if self.lastProcessCpuInfo: processTotal = cpuProcessInfo.getTotal() - self.lastProcessCpuInfo.getTotal() processPrecent = processTotal * 100 / totalCpu log_utils.log(self.pkgName + " CPU : %d " % (processPrecent)) cpuFile = filePath + self.pkgName + "_cpu.txt" content = time + "|" + str(int(processPrecent)) file_utils.writeFileAdd(cpuFile, content + "\n") self.lastProcessCpuInfo = cpuProcessInfo
def initData(self): self.pid = utils.getPid(self.pkgName) cpuProcessInfo = cpu_info_process.CpuProcessInfo() cpuProcessInfo.getCpuInfo(self.pid) self.lastProcessCpuInfo = cpuProcessInfo