当前位置:网站首页>App performance test: (III) traffic monitoring
App performance test: (III) traffic monitoring
2022-06-13 06:16:00 【Ming ruoxiao River】
app Performance testing :( 3、 ... and ) Traffic monitoring
The flow monitoring is analyzed below :
- Acquisition process ID Instructions
adb shell “ps | grep Package name ” - Acquisition process ID Traffic
- adb shell cat /proc/pid/net/dev
pid Change to the process obtained in the first step ID
receive It refers to the data received by the current process ,transmit It refers to the data requested by the current process , Flow is the sum of the two
In the end wlan0 representative wifi Upload and download volume identification ! The unit of upload and download is bytes /1024 The conversion KB
Here you can see the number of bytes downloaded 、 Data packets and Number of bytes sent 、 Data packets
rmnet_data0: On behalf of the mobile network
wlan0 These values are initialized 0 Turn on the mobile phone flight mode and then turn it off 0 了
Monitoring code :
#/usr/bin/python
#encoding:utf-8
import csv
import os
import string
import time
# The control class
class Controller(object):
def __init__(self, count):
# Define the number of tests
self.counter = count
# Define an array to collect data
self.alldata = [("timestamp", "traffic")]
# Single test process
def testprocess(self):
# Execute the command to get the process
result = os.popen("adb shell \"ps | grep com.zahd.agriculturaltraceability.debug\"")
print()
# Acquisition process ID
pid = result.readlines()[0].split(" ")[3]
# Acquisition process ID Used flow
traffic = os.popen("adb shell cat /proc/"+pid+"/net/dev")
for line in traffic:
if "wlan0" in line:
# Replace all spaces with #
line = "#".join(line.split())
# Press # No. split , Get the traffic received and sent
receive = line.split("#")[1]
transmit = line.split("#")[9]
elif "rmnet_data0" in line:
# Replace all spaces with #
line = "#".join(line.split())
# Press # No. split , Get the traffic received and sent
receive2 = line.split("#")[1]
transmit2 = line.split("#")[9]
# Calculate the sum of all flows
alltraffic = int(receive) + int(transmit) + int(receive2) + int(transmit2)
# Press KB Calculate the flow value
alltraffic = alltraffic/1024
# Get the current time
currenttime = self.getCurrentTime()
# Save the obtained data in the array
self.alldata.append((currenttime, alltraffic))
# Test process control many times
def run(self):
while self.counter >0:
self.testprocess()
self.counter = self.counter - 1
# Every time 5 Collect data once per second
time.sleep(5)
# 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('traffic.csv', 'w')
writer = csv.writer(csvfile)
writer.writerows(self.alldata)
csvfile.close()
if __name__ == "__main__":
controller = Controller(5)
controller.run()
controller.SaveDataToCSV()
边栏推荐
- Explication détaillée du triangle Yang hui
- USB debugging assistant 20181018 (v1.3)
- JVM基础
- Use of Nacos configuration center
- USB debugging assistant
- Download and installation of universal player potplayer, live stream m3u8 import
- 【美团笔试题】
- Custom view - extensible collapsexpendview
- The technical analysis of ERP systems of the two camps in the world has been picked up many times.
- JVM Foundation
猜你喜欢
Recommend a capacity expansion tool to completely solve the problem of insufficient disk space in Disk C and other disks
Local file search tool everything
Echart histogram: stacked histogram displays value
Echart柱状图:x轴显示value,y轴显示类别
The difference between the increment and decrement operators before and after variables i+, +i, I –, – I
Software testing - Summary of common interface problems
Hbuilderx: installation of hbuilderx and its common plug-ins
Experience of redis installation under Linux system (an error is reported at the same time. The struct redis server does not have a member named XXXX)
自我总结ing
Wechat applet: click the event to obtain the current device information (basic)
随机推荐
Uniapp (upload local pictures, preview pictures, convert Base64 format, upload audio files)
Uni app upload file
Status management --provider
华为开发者认证与DevEco Studio编译器下载
@The detailed explanation of configurationproperties and the problem that all properties of the entity bean modified by this annotation are null after injection are solved
Applet export (use) public function, public data
【美团笔试题】
Uni app disable native navigation bar
1+1>2,Share Creators可以帮助您实现
[var const let differences]
Echart histogram: stacked histogram displays value
Echart柱状图:堆叠柱状图value格式化显示
Essays on November 5, 2021
Applet disable native top
超有范的 logo 在线设计制作工具
The difference between the increment and decrement operators before and after variables i+, +i, I –, – I
Huawei developer certification and deveco studio compiler Download
端午安康,使用祝福话语生成词云吧
Minimum spanning tree (prim+kruskal) learning notes (template +oj topic)
Wechat applet: click the event to obtain the current device information (basic)