【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 ...
随机推荐
- class tuple
class tuple(object): """ tuple() -> empty tuple tuple(iterable) -> tuple initia ...
- JS的一些小验证
1,文本框只能输入数字代码(小数点也不能输入) <input onkeyup="this.value=this.value.replace(/\D/g,'')" onafte ...
- hdoj 5327 Olmpiad
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5327 #include<stdio.h> #include<cstring> ...
- window8家庭版上的RationalRose
来点儿小插曲儿,本是继续Java系列文章的续集的,但是最近要用到UML,在网上看了看,查了查推荐的到是不少,最终还是选择了rose,哈哈,一半是冲着名字去的,一半看看了与其它的UML的比较,最终中意r ...
- 局部化原理(Laplace渐进估计方法)
设$f(x)$于$[0,1]$上严格单调递减,且$f(0)=1,f(1)=0$,证明: $$\int_{0}^{1}f^{n}(x)dx \sim \int_{0}^{\delta}f^{n}(x), ...
- CMSIS Example - osMutex osMutexWait osMutexRelease
osMutexDef( Mutex ); osMutexId mutex; void Thread0( void * arg); void Thread1( void * arg); osThread ...
- 双网卡绑定-bond0
网卡绑定就是多张网卡逻辑上作为一张网卡用.可分为,负载均衡绑定和冗余绑定两种. 1.编辑虚拟网络接口配置文件 [root@test~]# more /etc/sysconfig/network-scr ...
- Could not load the assembly 'App_Web_cwclgcuu'. Make sure that it is compiled before accessing the page.
将网站迁移到windows server 2012 R2(64 bit), IIS 6.2(build 9200)上,爆出这个错误. 解决:右键相应的application pool,选择“Set A ...
- Codeforces Educational Codeforces Round 3 A. USB Flash Drives 水题
A. USB Flash Drives 题目连接: http://www.codeforces.com/contest/609/problem/A Description Sean is trying ...
- bzoj 2435: [Noi2011]道路修建 树上 dp
2435: [Noi2011]道路修建 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...