Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_47647075
emmagee
提交
c008cb7c
E
emmagee
项目概览
weixin_47647075
/
emmagee
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
emmagee
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c008cb7c
编写于
9月 30, 2013
作者:
H
hzhuangqingbin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resolve checkstyle errors
上级
34ccd775
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
60 addition
and
75 deletion
+60
-75
src/com/netease/emmagee/performance/PerformanceMonitor.java
src/com/netease/emmagee/performance/PerformanceMonitor.java
+57
-74
src/com/netease/qa/emmagee/utils/CurrentInfo.java
src/com/netease/qa/emmagee/utils/CurrentInfo.java
+3
-1
未找到文件。
src/com/netease/emmagee/performance/PerformanceMonitor.java
浏览文件 @
c008cb7c
...
...
@@ -37,13 +37,13 @@ import android.os.Handler;
import
android.util.Log
;
/**
* Service running in background
* Service running in background
*
* @author hz_liuxiao
*/
public
class
PerformanceMonitor
{
private
final
static
String
LOG_TAG
=
"Emmagee-"
+
PerformanceMonitor
.
class
.
getSimpleName
();
private
final
static
String
LOG_TAG
=
"Emmagee-"
+
PerformanceMonitor
.
class
.
getSimpleName
();
private
int
delaytime
=
1000
;
private
Handler
handler
=
new
Handler
();
...
...
@@ -60,8 +60,7 @@ public class PerformanceMonitor {
private
SimpleDateFormat
formatterTime
;
private
DecimalFormat
fomart
;
private
boolean
isInitialStatic
=
true
;
private
long
processCpu1
,
processCpu2
,
totalCpu1
,
totalCpu2
,
idleCpu1
,
idleCpu2
;
private
long
processCpu1
,
processCpu2
,
totalCpu1
,
totalCpu2
,
idleCpu1
,
idleCpu2
;
private
long
startTraff
,
endTraff
,
intervalTraff
;
private
String
currentBatt
,
temperature
,
voltage
;
private
boolean
isRunnableStop
=
false
;
...
...
@@ -69,10 +68,10 @@ public class PerformanceMonitor {
private
Context
context
;
private
String
toolName
;
// private OrangeSolo orange;
public
PerformanceMonitor
(
Context
context
,
String
packageName
,
String
toolName
,
String
mDateTime
)
{
public
PerformanceMonitor
(
Context
context
,
String
packageName
,
String
toolName
,
String
mDateTime
)
{
this
.
context
=
context
;
fomart
=
new
DecimalFormat
();
...
...
@@ -89,8 +88,8 @@ public class PerformanceMonitor {
// orange = serializable.getOrange();
getAppInfo
(
packageName
);
// 不在初始化的时候创建报告,而是在真正做记录的时候创建
//
creatReport(toolName, mDateTime);
this
.
toolName
=
toolName
;
//
creatReport(toolName, mDateTime);
this
.
toolName
=
toolName
;
cpuInfo
=
new
CpuInfo
();
memoryInfo
=
new
MemoryInfo
();
networkInfo
=
new
TrafficInfo
();
...
...
@@ -102,8 +101,7 @@ public class PerformanceMonitor {
* @param packageName
*/
private
void
getAppInfo
(
String
packageName
)
{
ActivityManager
am
=
(
ActivityManager
)
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
ActivityManager
am
=
(
ActivityManager
)
context
.
getSystemService
(
Context
.
ACTIVITY_SERVICE
);
List
<
RunningAppProcessInfo
>
run
=
am
.
getRunningAppProcesses
();
// PackageManager pm = context.getPackageManager();
for
(
RunningAppProcessInfo
runningProcess
:
run
)
{
...
...
@@ -122,29 +120,28 @@ public class PerformanceMonitor {
*/
private
void
creatReport
(
String
toolName
,
String
dateTime
)
{
Log
.
d
(
LOG_TAG
,
"start write report"
);
// Calendar cal = Calendar.getInstance();
// SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
// String mDateTime;
// if ((Build.MODEL.equals("sdk")) || (Build.MODEL.equals("google_sdk")))
// mDateTime = formatter.format(cal.getTime().getTime() + 8 * 60 * 60
// * 1000);
// else
// mDateTime = formatter.format(cal.getTime().getTime());
// Calendar cal = Calendar.getInstance();
// SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
// String mDateTime;
// if ((Build.MODEL.equals("sdk")) ||
// (Build.MODEL.equals("google_sdk")))
// mDateTime = formatter.format(cal.getTime().getTime() + 8 * 60 * 60
// * 1000);
// else
// mDateTime = formatter.format(cal.getTime().getTime());
String
dir
=
""
;
if
(
android
.
os
.
Environment
.
getExternalStorageState
().
equals
(
android
.
os
.
Environment
.
MEDIA_MOUNTED
))
{
dir
=
android
.
os
.
Environment
.
getExternalStorageDirectory
()
+
File
.
separator
+
toolName
;
if
(
android
.
os
.
Environment
.
getExternalStorageState
().
equals
(
android
.
os
.
Environment
.
MEDIA_MOUNTED
))
{
dir
=
android
.
os
.
Environment
.
getExternalStorageDirectory
()
+
File
.
separator
+
toolName
;
}
else
{
dir
=
context
.
getFilesDir
().
getPath
()
+
File
.
separator
+
toolName
;
}
// resultFilePath = dir + File.separator + toolName + "-" + mDateTime + ".csv";
// resultFilePath = dir + File.separator + toolName + "-" + Build.VERSION.SDK_INT + "-"
// + Build.MODEL.replace(" ", "-") + "-PerformanceMonitor" + ".csv";
// resultFilePath = dir + File.separator + toolName + "-" + mDateTime +
// ".csv";
// resultFilePath = dir + File.separator + toolName + "-" +
// Build.VERSION.SDK_INT + "-"
// + Build.MODEL.replace(" ", "-") + "-PerformanceMonitor" + ".csv";
resultFilePath
=
dir
+
File
.
separator
+
"PerformanceMonitor.csv"
;
// 这边的性能文件命名改简单一点
try
{
// 创建目录
...
...
@@ -161,10 +158,8 @@ public class PerformanceMonitor {
osw
=
new
OutputStreamWriter
(
out
,
"GBK"
);
bw
=
new
BufferedWriter
(
osw
);
// 生成头文件
bw
.
write
(
"测试用例信息"
+
","
+
"时间"
+
","
+
"应用占用内存PSS(MB)"
+
","
+
"应用占用内存比(%)"
+
","
+
" 机器剩余内存(MB)"
+
","
+
"应用占用CPU率(%)"
+
","
+
"CPU总使用率(%)"
+
","
+
"流量(KB)"
+
","
+
"当前电量"
+
","
+
"电池温度(C)"
+
","
+
"电压(V)"
+
"\r\n"
);
bw
.
write
(
"测试用例信息"
+
","
+
"时间"
+
","
+
"应用占用内存PSS(MB)"
+
","
+
"应用占用内存比(%)"
+
","
+
" 机器剩余内存(MB)"
+
","
+
"应用占用CPU率(%)"
+
","
+
"CPU总使用率(%)"
+
","
+
"流量(KB)"
+
","
+
"当前电量"
+
","
+
"电池温度(C)"
+
","
+
"电压(V)"
+
"\r\n"
);
bw
.
flush
();
}
else
{
out
=
new
FileOutputStream
(
resultFile
,
true
);
// 在文件内容后继续加内容
...
...
@@ -188,22 +183,20 @@ public class PerformanceMonitor {
startTraff
=
networkInfo
.
getTrafficInfo
(
uid
);
isInitialStatic
=
false
;
}
// Network
endTraff
=
networkInfo
.
getTrafficInfo
(
uid
);
if
(
startTraff
==
-
1
)
intervalTraff
=
-
1
;
else
intervalTraff
=
(
endTraff
-
startTraff
+
1023
)
/
1024
;
// CPU
processCpu1
=
cpuInfo
.
readCpuStat
(
pid
)[
0
];
idleCpu1
=
cpuInfo
.
readCpuStat
(
pid
)[
1
];
totalCpu1
=
cpuInfo
.
readCpuStat
(
pid
)[
2
];
String
processCpuRatio
=
fomart
.
format
(
100
*
((
double
)
(
processCpu1
-
processCpu2
)
/
((
double
)
(
totalCpu1
-
totalCpu2
))));
String
totalCpuRatio
=
fomart
.
format
(
100
*
((
double
)
((
totalCpu1
-
idleCpu1
)
-
(
totalCpu2
-
idleCpu2
))
/
(
double
)
(
totalCpu1
-
totalCpu2
)));
String
processCpuRatio
=
fomart
.
format
(
100
*
((
double
)
(
processCpu1
-
processCpu2
)
/
((
double
)
(
totalCpu1
-
totalCpu2
))));
String
totalCpuRatio
=
fomart
.
format
(
100
*
((
double
)
((
totalCpu1
-
idleCpu1
)
-
(
totalCpu2
-
idleCpu2
))
/
(
double
)
(
totalCpu1
-
totalCpu2
)));
// Memory
long
pidMemory
=
memoryInfo
.
getPidMemorySize
(
pid
,
context
);
...
...
@@ -213,22 +206,17 @@ public class PerformanceMonitor {
long
totalMemorySize
=
memoryInfo
.
getTotalMemory
();
String
percent
=
"统计出错"
;
if
(
totalMemorySize
!=
0
)
{
percent
=
fomart
.
format
(((
double
)
pidMemory
/
(
double
)
totalMemorySize
)
*
100
);
percent
=
fomart
.
format
(((
double
)
pidMemory
/
(
double
)
totalMemorySize
)
*
100
);
}
try
{
if
(
intervalTraff
==
-
1
)
{
bw
.
write
(
this
.
getTestCaseInfo
()
+
"-"
+
this
.
getActionInfo
()
+
","
+
mDateTime
+
","
+
pss
+
","
+
percent
+
","
+
freeMem
+
","
+
processCpuRatio
+
","
+
totalCpuRatio
+
","
+
"本程序或本设备不支持流量统计"
+
","
+
currentBatt
+
","
+
temperature
+
","
+
voltage
bw
.
write
(
this
.
getTestCaseInfo
()
+
"-"
+
this
.
getActionInfo
()
+
","
+
mDateTime
+
","
+
pss
+
","
+
percent
+
","
+
freeMem
+
","
+
processCpuRatio
+
","
+
totalCpuRatio
+
","
+
"本程序或本设备不支持流量统计"
+
","
+
currentBatt
+
","
+
temperature
+
","
+
voltage
+
"\r\n"
);
}
else
{
bw
.
write
(
this
.
getTestCaseInfo
()
+
"-"
+
this
.
getActionInfo
()
+
","
+
mDateTime
+
","
+
pss
+
","
+
percent
+
","
+
freeMem
+
","
+
processCpuRatio
+
","
+
totalCpuRatio
+
","
+
intervalTraff
+
","
+
currentBatt
+
","
+
temperature
+
","
+
voltage
bw
.
write
(
this
.
getTestCaseInfo
()
+
"-"
+
this
.
getActionInfo
()
+
","
+
mDateTime
+
","
+
pss
+
","
+
percent
+
","
+
freeMem
+
","
+
processCpuRatio
+
","
+
totalCpuRatio
+
","
+
intervalTraff
+
","
+
currentBatt
+
","
+
temperature
+
","
+
voltage
+
"\r\n"
);
}
bw
.
flush
();
...
...
@@ -236,7 +224,7 @@ public class PerformanceMonitor {
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
processCpu2
=
processCpu1
;
idleCpu2
=
idleCpu1
;
totalCpu2
=
totalCpu1
;
...
...
@@ -252,10 +240,11 @@ public class PerformanceMonitor {
};
};
/**
/**
* 电量广播类
*
* @author hz_liuxiao@corp.netease.com
*
*
*/
public
class
BatteryInfoBroadcastReceiver
extends
BroadcastReceiver
{
...
...
@@ -268,14 +257,11 @@ public class PerformanceMonitor {
int
scale
=
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_SCALE
,
-
1
);
currentBatt
=
String
.
valueOf
(
level
*
100
/
scale
)
+
"%"
;
voltage
=
String
.
valueOf
(
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_VOLTAGE
,
-
1
)
*
1.0
/
1000
);
voltage
=
String
.
valueOf
(
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_VOLTAGE
,
-
1
)
*
1.0
/
1000
);
temperature
=
String
.
valueOf
(
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_TEMPERATURE
,
-
1
)
*
1.0
/
10
);
temperature
=
String
.
valueOf
(
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_TEMPERATURE
,
-
1
)
*
1.0
/
10
);
int
status
=
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_STATUS
,
-
1
);
int
status
=
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_STATUS
,
-
1
);
}
}
...
...
@@ -303,7 +289,7 @@ public class PerformanceMonitor {
isRunnableStop
=
true
;
closeOpenedStream
();
}
/**
* 从栈中获取类名和测试方法名
*
...
...
@@ -316,27 +302,26 @@ public class PerformanceMonitor {
int
i
=
0
;
while
(
i
<
stack
.
length
)
{
// 在setUp和testXXX中会有orange的操作方法
if
(
stack
[
i
].
getMethodName
().
toString
().
startsWith
(
"test"
)
||
stack
[
i
].
getMethodName
().
toString
().
startsWith
(
"setUp"
))
{
if
(
stack
[
i
].
getMethodName
().
toString
().
startsWith
(
"test"
)
||
stack
[
i
].
getMethodName
().
toString
().
startsWith
(
"setUp"
))
{
break
;
}
i
++;
i
++;
}
if
(
i
>=
stack
.
length
)
{
testCaseInfo
=
"No TestCase Info"
;
testCaseInfo
=
"No TestCase Info"
;
}
else
{
// “.”在正则中代码任意字符,不能用来分割,如需使用则通过“//.”转义
String
[]
packageName
=
stack
[
i
].
getClassName
().
toString
().
split
(
"\\."
);
className
=
packageName
[
packageName
.
length
-
1
];
//
className = stack[i].getClassName().toString();
//
className = stack[i].getClassName().toString();
testName
=
stack
[
i
].
getMethodName
().
toString
();
testCaseInfo
=
className
+
"."
+
testName
;
}
//
Log.i(LOG_TAG, "*** getTestCaseInfo =" + testCaseInfo + " *** ");
//
Log.i(LOG_TAG, "*** getTestCaseInfo =" + testCaseInfo + " *** ");
return
testCaseInfo
;
}
/**
* 从栈中获取相应操作方法名,有clickXXX,enterXXX,scrollXXX,typeXXX
*
...
...
@@ -349,19 +334,17 @@ public class PerformanceMonitor {
int
i
=
0
;
while
(
i
<
stack
.
length
)
{
// 类对应的是OrangeSolo,
if
(
stack
[
i
].
getMethodName
().
toString
().
startsWith
(
"click"
)
||
stack
[
i
].
getMethodName
().
toString
().
startsWith
(
"enter"
)
||
stack
[
i
].
getMethodName
().
toString
().
startsWith
(
"scroll"
)
||
stack
[
i
].
getMethodName
().
toString
().
startsWith
(
"type"
))
{
if
(
stack
[
i
].
getMethodName
().
toString
().
startsWith
(
"click"
)
||
stack
[
i
].
getMethodName
().
toString
().
startsWith
(
"enter"
)
||
stack
[
i
].
getMethodName
().
toString
().
startsWith
(
"scroll"
)
||
stack
[
i
].
getMethodName
().
toString
().
startsWith
(
"type"
))
{
break
;
}
i
++;
i
++;
}
if
(
i
>=
stack
.
length
)
{
actionInfo
=
"No Action Info"
;
actionInfo
=
"No Action Info"
;
}
else
{
//className暂时不用展现
//
className暂时不用展现
testName
=
stack
[
i
].
getMethodName
().
toString
();
actionInfo
=
testName
;
}
...
...
src/com/netease/qa/emmagee/utils/CurrentInfo.java
浏览文件 @
c008cb7c
...
...
@@ -105,7 +105,9 @@ public class CurrentInfo {
try
{
// @@@ debug
// StringReader fr = new
// StringReader("vref: 1248\r\nbatt_id: 3\r\nbatt_vol: 4068\r\nbatt_current: 0\r\nbatt_discharge_current: 123\r\nbatt_temperature: 329\r\nbatt_temp_protection:normal\r\nPd_M:0\r\nI_MBAT:-313\r\npercent_last(RP): 94\r\npercent_update: 71\r\nlevel: 71\r\nfirst_level: 100\r\nfull_level:100\r\ncapacity:1580\r\ncharging_source: USB\r\ncharging_enabled: Slow\r\n");
// StringReader("vref: 1248\r\nbatt_id: 3\r\nbatt_vol: 4068\r\nbatt_current: 0\r\nbatt_discharge_current: 123\r\nbatt_temperature:
// 329\r\nbatt_temp_protection:normal\r\nPd_M:0\r\nI_MBAT:-313\r\npercent_last(RP):
// 94\r\npercent_update: 71\r\nlevel: 71\r\nfirst_level: 100\r\nfull_level:100\r\ncapacity:1580\r\ncharging_source: USB\r\ncharging_enabled: Slow\r\n");
FileReader
fr
=
new
FileReader
(
f
);
BufferedReader
br
=
new
BufferedReader
(
fr
);
String
line
=
br
.
readLine
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录