主要记录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的流量消耗的更多相关文章

  1. Windows下部署Appium教程(Android App自动化测试框架搭建)

    摘要: 1,appium是开源的移动端自动化测试框架: 2,appium可以测试原生的.混合的.以及移动端的web项目: 3,appium可以测试ios.android.firefox os: 4,a ...

  2. windows下用cordova构建android app

    最近用到cordova打包apk,总结了下,写下来给大家分享. 一.前期准备工作: 1.安装node   6.2.0 *64 下载地址:链接:http://pan.baidu.com/s/1eS7Ts ...

  3. Cordova - Windows 下创建第一个 Android App

    官方文档: Create your first Cordova app Android Platform Guide 安装 JDK 和 Android SDK 注意: 需要将 JK 和 Android ...

  4. adb查看Android app包名

    1. 确保电脑已经安装了adb.exe文件 2. 使用USB连接你的手机到电脑上,输入下图所示的命令后按下回车键:adb devices 3. 使用手机打开某个应用程序 4.回到命令号窗口,输入代码如 ...

  5. 个人开发者做一款Android App需要知道的事情

    个人开发者做一款Android App需要知道的事情 在大学时, 自己是学计算机专业的,而且还和老师一起做过一年半的项目. 有时候是不是有这样的想法,做一个自己的网站.但一直未付诸行动.2012年时, ...

  6. 如何做一款自己的Android App

    转自:http://www.cnblogs.com/hubcarl/p/4030884.html 正在做App,后续补充: 概述:以我开发的一款编程学习的App[编程在线]为例讲讲如何做一款自己的An ...

  7. 我的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 ...

  8. Python调用windows下DLL详解

    Python调用windows下DLL详解 - ctypes库的使用 2014年09月05日 16:05:44 阅读数:6942 在python中某些时候需要C做效率上的补充,在实际应用中,需要做部分 ...

  9. Python通过调用windows命令行处理sam文件

    Python通过调用windows命令行处理sam文件 以samtools软件为例 一.下载或者索取得到windows版本的samtools软件,解压后如下: 进入文件内部,有如下几个文件: 二.将s ...

随机推荐

  1. OracleCommand.CommandText 无效

    OracleCommand insertADataCmd = conn.CreateCommand(); insertBDataCmd.CommandText = SQL OracleParamete ...

  2. 51Nod 1405 树的距离之和 (树dp)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1405 中文题面不解释了,两次dfs,第一次自下向上,第二次自上 ...

  3. LEARUN 开发框架 /aspnetboilerplate ----上海力软信息技术有限公司

    LEARUN 开发框架 ----上海力软信息技术有限公司 http://www.learun.cn/ aspnetboilerplate    http://www.aspnetboilerplate ...

  4. git filename to long问题解决

    在.git/config 下面编辑 [core] longpaths = true

  5. Simple Worker Thread Class

    http://www.codeproject.com/Articles/36184/Simple-Worker-Thread-Class Introduction Many times we need ...

  6. js页面文字选中后分享到新浪微博实现

    demo您可以狠狠地点击这里:js文字选中分享到新浪微博demo 方法与代码 选中即分享的功能看上去比较高级,其实实现是相当简单的.其中的会让人头大,一般人也不感兴趣的原理这里就直接跳过.这个js文字 ...

  7. 常用CSS3效果:用text-shadow做CSS3 文字描边

    思路: 利用CSS3的text-shadow属性,对文字的四个边均用阴影. 最终效果: 单纯的为了实现效果.未作任何美化. 实现代码: HTML: <div>文字描边效果</div& ...

  8. 用NDK编译lua库

    Android.mk是这样的 LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := lua LOCAL_SRC_FILE ...

  9. Codeforces Round #311 (Div. 2) C. Arthur and Table Multiset

    C. Arthur and Table Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/p ...

  10. Ubuntu 改动bash

    ubuntu下/bin/sh的指向   ubuntu 下 /bin/sh 默认是dash,用ll /bin/sh就能够看出来sh是指向dash的链接.有时候会导致使用bash脚本的时候出问题.   假 ...