当前位置:网站首页>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()
边栏推荐
- The technical analysis of ERP systems of the two camps in the world has been picked up many times.
- 推荐扩容工具,彻底解决C盘及其它磁盘空间不够的难题
- Binary search
- js-bom
- A glimpse of [wechat applet]
- Using async await in applets
- Echart折线图:当多条折线图的name一样时也显示不同的颜色
- [compilation and assembly link] coff file and structure description
- Uni app upload file
- 本地文件秒搜工具 Everything
猜你喜欢

Complete USB debugging assistant

Learning records countless questions (JS)

1+1>2,Share Creators可以帮助您实现

You still can't remotely debug idea? Come and have a look at my article. It's easy to use

Self summarizing

杨辉三角形详解

Echart矩形树图:简单实现矩形树图

Echart line chart: when multiple lines have the same name, the legend is still displayed

Local file search tool everything

Rk3399 hid gadget configuration
随机推荐
自定义View
Introduction to USB learning (5) -- looking back, the man was in the dim light
2021-11-04 implementation of binary search
Not in the following list of legal domain names, wechat applet solution
Echart rectangular tree diagram: simple implementation of rectangular tree diagram
Echart histogram: X-axis displays value, Y-axis displays category
微信小程序:点击事件获取当前设备信息(基础)
电镀挂具RFID工序管理解决方案
Echart柱状图:堆叠柱状图显示value
A brief analysis of the overall process of view drawing
Wechat applet: use of global state variables
Echart柱状图:x轴显示value,y轴显示类别
不在以下合法域名列表中,微信小程序解决办法
USB debugging assistant (20191028)
Add attributes in storyboard and Xib (fillet, foreground...) Ibinspectable and ibdesignable
[to]12 common IP commands in the iproute installation package
自我总结ing
The boys x pubgmobile linkage is coming! Check out the latest game posters
Detailed explanation of Yanghui triangle
1016 part a+b (15 points)