【python调用windows CLI】调用adb统计Android app的流量消耗
主要记录python如何调用windows CLI
手机连接PC,adb devices可以看到手机sn
通过adb 获取指定app的processID UID
读取Android /proc/net/xt_qtaguid/stats 获取指定列,格式化输出,用于后续统计app消耗的流量
#coding=utf-8
import subprocess
import time
fo = open(r"D:\foo.txt", "w")
#获取进程ID
getProcessIdcmd = 'adb shell ps | grep appname'
p = subprocess.Popen(getProcessIdcmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
content = p.stdout.readlines()
if len(content) == 1:
processId = content[0].split()[1]
else:
print "not get processID"
#获取进程对应的UID
getUidcmd = 'adb shell cat /proc/' + processId + '/status | grep Uid' p = subprocess.Popen(getUidcmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
content = p.stdout.readlines()
uidList = content[0].strip().split('\t')
print uidList
uid = uidList[1] #获取UID对应的Traffic
getTrafficcmd = 'adb shell cat /proc/net/xt_qtaguid/stats | grep ' + uid for i in range(10000):
currentTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
traffic_initial = [0]*16
traffic_prefix = []
p = subprocess.Popen(getTrafficcmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in p.stdout.readlines():
ll = line.strip()
ll2=ll.replace(' ',',')
ll2_list=ll2.split(',')
traffic_list = ll2_list[5:]
traffic_prefix = ll2_list[0:4]
traffic_list_int = [int(e) for e in traffic_list] traffic_initial = [x+y for x, y in zip(traffic_initial, traffic_list_int)]
#print traffic_list
print currentTime + "," + ll2
retval = p.wait()
print traffic_initial
traffic_list_str = [str(e) for e in traffic_initial]
print traffic_prefix + traffic_list_str
traffic = ','.join(traffic_prefix + traffic_list_str)
print currentTime +','+ traffic
fo.write(currentTime +','+ traffic + '\n')
time.sleep(60)
print '--------------'
fo.close()
【python调用windows CLI】调用adb统计Android app的流量消耗的更多相关文章
- Windows下部署Appium教程(Android App自动化测试框架搭建)
摘要: 1,appium是开源的移动端自动化测试框架: 2,appium可以测试原生的.混合的.以及移动端的web项目: 3,appium可以测试ios.android.firefox os: 4,a ...
- windows下用cordova构建android app
最近用到cordova打包apk,总结了下,写下来给大家分享. 一.前期准备工作: 1.安装node 6.2.0 *64 下载地址:链接:http://pan.baidu.com/s/1eS7Ts ...
- Cordova - Windows 下创建第一个 Android App
官方文档: Create your first Cordova app Android Platform Guide 安装 JDK 和 Android SDK 注意: 需要将 JK 和 Android ...
- adb查看Android app包名
1. 确保电脑已经安装了adb.exe文件 2. 使用USB连接你的手机到电脑上,输入下图所示的命令后按下回车键:adb devices 3. 使用手机打开某个应用程序 4.回到命令号窗口,输入代码如 ...
- 个人开发者做一款Android App需要知道的事情
个人开发者做一款Android App需要知道的事情 在大学时, 自己是学计算机专业的,而且还和老师一起做过一年半的项目. 有时候是不是有这样的想法,做一个自己的网站.但一直未付诸行动.2012年时, ...
- 如何做一款自己的Android App
转自:http://www.cnblogs.com/hubcarl/p/4030884.html 正在做App,后续补充: 概述:以我开发的一款编程学习的App[编程在线]为例讲讲如何做一款自己的An ...
- 我的Android进阶之旅------>Android APP终极瘦身指南
首先声明,下面文字转载于: APK瘦身实践 http://www.jayfeng.com/2015/12/29/APK%E7%98%A6%E8%BA%AB%E5%AE%9E%E8%B7%B5/ APP ...
- Python调用windows下DLL详解
Python调用windows下DLL详解 - ctypes库的使用 2014年09月05日 16:05:44 阅读数:6942 在python中某些时候需要C做效率上的补充,在实际应用中,需要做部分 ...
- Python通过调用windows命令行处理sam文件
Python通过调用windows命令行处理sam文件 以samtools软件为例 一.下载或者索取得到windows版本的samtools软件,解压后如下: 进入文件内部,有如下几个文件: 二.将s ...
随机推荐
- STL容器set()--->自定义数据类型
set容器中不能插入重复的元素,需要其插入的元素有比较大小(<).相等(==) 的逻辑判断,这是因为set中的元素是有序排列, 默认从小到大排列 std::set<type,std::le ...
- flume ng配置拓扑图
- 常见错误:Apple Mach-O Linker Error
常见错误描述: Apple Mach-O Linker Error这类错误的错误信息最后一行通常如下: Command /Developer/Platforms/iPhoneOS.platform/D ...
- Spring三种实例化Bean的方法
1.实例化bean的三种方法:(1) 构造器<!-- 体验1 --><bean id="personService" class="com.persia ...
- win8 企业版 安装 .net2.0 .net 3.5
Windows 8 默认集成 .Net Framework 4.5,因此运行一些基于3.5或以前版本的程序时会弹出这个提示. 2012-3-2 15:24 上传 下载附件 (23.91 KB) 这 ...
- 把自定义类实例存储到LSO
使用flash.net.registerClassAlias( )方法保留类型信息并把类实例添加到共享对象的data属性上. LSOs 使用特殊的二进制格式,Action Message Format ...
- window.location.href的使用方法
http://hljqfl.blog.163.com/blog/static/40931580201122210573364/ 在写ASP.Net程序的时候,我们常常遇到跳转页面的问题,我们常常使用R ...
- C# String.Format
C 货币 string.Format("{0:C3}", 2) $2.000 D 十进制 string.Format("{0:D3}", 2) 002 E 科学 ...
- JavaScript代码优化(下载时间和执行速度优化)
JavaScript代码的速度被分成两部分:下载时间和执行速度. 下载时间 Web浏览器下载的是js源码,因此所有长变量名和注释都回包含在内.这个因素会增加下载时间.1160是一个TCP-IP包中的字 ...
- netcdf入门(转)
一.概述 NetCDF全称为network Common Data Format,中文译法为“网络通用数据格式”,对程序员来说,它和zip.jpeg.bmp文件格式类似,都是一种文件格式的标准.ne ...