当前位置:网站首页>App performance test: (II) CPU

App performance test: (II) CPU

2022-06-13 06:16:00 Ming ruoxiao River

app Performance testing :( Two )CPU

Following pair CPU Analyze :

  • see CPU usage ( First, you need to open the corresponding app)
    command :adb shell top -n 1 | findstr Package name
    Running results

      PID  	UID 		PR 	CPU% S  #THR     VSS     RS	 PCY 	packageName
      28210 u0_a129  10 -10  18% S    42 1814932K 160848K  fg  Package name 
    
Name meaning
PID process ID
UID process ID
PR priority
CPU% The present moment takes up CPU percentage
S Process status (R= function ,S= sleep ,T= track / stop it ,Z= Zombie process )
#THR Number of threads
VSSVirtual Set Size Virtual memory consumption ( Contains the memory used by the shared library )
RSSResident Set Size Actually using physical memory ( Contains the memory used by the shared library )
PCY Scheduling policy priority ,SP_BACKGROUND/SPFOREGROUND
NAME Process name

top The command also supports some command line parameters , The detailed usage is as follows :

Usage: top [ -m max_procs ] [ -n iterations ] [ -d delay ] [ -s sort_column ] [ -t ] [ -h ]
    -m num   Show at most how many processes 
    -n num   Refresh how many times and exit 
    -d num   Refresh interval ( Unit second , The default value is  5)
    -s col   Sort by a column ( You can use  col  value :cpu, vss, rss, thr)
    -t       Show thread information 
    -h       Show help documents 

Monitoring script code

#/usr/bin/python
#encoding:utf-8
import csv
import os
import time

# The control class 
class Controller(object):
    def __init__(self, count):
        self.counter = count
        self.alldata = [("timestamp", "cpustatus")]

    # Single test process 
    def testprocess(self):
        result = os.popen("adb shell top  -n 1  | findstr com.zahd.agriculturaltraceability.debug")
        # Run the command to get : 30464 u0_a129  10 -10  22% S    44 1823308K 158792K  fg ...
        for line in result.readlines():
            cpuvalue =  line.split("%")[0]  #30464 u0_a129  10 -10  24 for line in result.readlines():
        	result1 =  line.split("%")[0]# obtain    30464 u0_a129  10 -10  24
        	result2=result1.split(" ")# Separate by spaces 
        	cpuvalue=result2[len(result2)-1]# Get the last... Of the array , That is to say cpu%

        currenttime = self.getCurrentTime()
        self.alldata.append((currenttime, cpuvalue))

    # Perform the test process multiple times 
    def run(self):
        while self.counter >0:
            self.testprocess()
            self.counter = self.counter - 1
            time.sleep(3)

    # Get the current timestamp 
    def getCurrentTime(self):
        currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        return currentTime

    # Data storage 
    def SaveDataToCSV(self):
        csvfile = open('cpustatus.csv', 'w')
        writer = csv.writer(csvfile)
        writer.writerows(self.alldata)
        csvfile.close()

if __name__ == "__main__":
    controller = Controller(10)
    controller.run()
    controller.SaveDataToCSV()

Monitoring process , Manual operation required app

原网站

版权声明
本文为[Ming ruoxiao River]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270556299993.html