Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_47647075
emmagee
提交
1d89a09d
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 搜索 >>
提交
1d89a09d
编写于
12月 20, 2013
作者:
H
hzhuangqingbin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed: reivew comments
上级
ee187d7e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
64 addition
and
39 deletion
+64
-39
src/com/netease/qa/emmagee/activity/MainPageActivity.java
src/com/netease/qa/emmagee/activity/MainPageActivity.java
+3
-3
src/com/netease/qa/emmagee/service/EmmageeService.java
src/com/netease/qa/emmagee/service/EmmageeService.java
+61
-36
未找到文件。
src/com/netease/qa/emmagee/activity/MainPageActivity.java
浏览文件 @
1d89a09d
...
...
@@ -96,11 +96,11 @@ public class MainPageActivity extends Activity {
Intent
intent
=
getPackageManager
()
.
getLaunchIntentForPackage
(
packageName
);
Log
.
d
(
LOG_TAG
,
packageName
);
//
清除logcat日志
//
clear logcat
try
{
Runtime
.
getRuntime
().
exec
(
"logcat -c"
);
}
catch
(
IOException
e
1
)
{
e1
.
printStackTrace
(
);
}
catch
(
IOException
e
)
{
Log
.
d
(
LOG_TAG
,
e
.
getMessage
()
);
}
try
{
startActivity
(
intent
);
...
...
src/com/netease/qa/emmagee/service/EmmageeService.java
浏览文件 @
1d89a09d
...
...
@@ -22,6 +22,8 @@ import java.io.File;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.FileReader
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.InputStreamReader
;
import
java.io.OutputStreamWriter
;
...
...
@@ -119,8 +121,9 @@ public class EmmageeService extends Service {
private
CurrentInfo
currentInfo
;
private
BatteryInfoBroadcastReceiver
batteryBroadcast
=
null
;
//获取启动时间所需变量
private
static
final
int
MAX_START_TIME_COUNT
=
5
;
//暂定最大轮询5次
// get start time
private
static
final
int
MAX_START_TIME_COUNT
=
5
;
private
static
final
String
START_TIME
=
"#startTime"
;
private
int
getStartTimeCount
=
0
;
private
boolean
isGetStartTime
=
true
;
private
String
startTime
=
""
;
...
...
@@ -258,13 +261,14 @@ public class EmmageeService extends Service {
File
resultFile
=
new
File
(
resultFilePath
);
resultFile
.
createNewFile
();
out
=
new
FileOutputStream
(
resultFile
);
osw
=
new
OutputStreamWriter
(
out
,
"
GBK
"
);
osw
=
new
OutputStreamWriter
(
out
,
"
UTF-8
"
);
bw
=
new
BufferedWriter
(
osw
);
long
totalMemorySize
=
memoryInfo
.
getTotalMemory
();
String
totalMemory
=
fomart
.
format
((
double
)
totalMemorySize
/
1024
);
bw
.
write
(
"指定应用的CPU内存监控情况\r\n"
+
"应用包名:,"
+
packageName
+
"\r\n"
+
"应用名称: ,"
+
processName
+
"\r\n"
+
"应用PID: ,"
+
pid
+
"\r\n"
+
"机器内存大小(MB):,"
+
totalMemory
+
"MB\r\n"
+
"机器CPU型号:,"
+
cpuInfo
.
getCpuName
()
+
"\r\n"
+
"机器android系统版本:,"
+
memoryInfo
.
getSDKVersion
()
+
"\r\n"
+
"手机型号:,"
+
memoryInfo
.
getPhoneType
()
+
"\r\n"
+
"UID:,"
+
uid
+
"\r\n"
);
+
memoryInfo
.
getSDKVersion
()
+
"\r\n"
+
"手机型号:,"
+
memoryInfo
.
getPhoneType
()
+
"\r\n"
+
"UID:,"
+
uid
+
"\r\n"
+
"启动时间:,"
+
START_TIME
+
"\r\n"
);
bw
.
write
(
"时间"
+
","
+
"应用占用内存PSS(MB)"
+
","
+
"应用占用内存比(%)"
+
","
+
" 机器剩余内存(MB)"
+
","
+
"应用占用CPU率(%)"
+
","
+
"CPU总使用率(%)"
+
","
+
"流量(KB)"
+
","
+
"电量(%)"
+
","
+
"电流(mA)"
+
","
+
"温度(C)"
+
","
+
"电压(V)"
+
"\r\n"
);
}
catch
(
IOException
e
)
{
...
...
@@ -362,8 +366,7 @@ public class EmmageeService extends Service {
if
(
isFloating
)
{
windowManager
.
updateViewLayout
(
viFloatingWindow
,
wmParams
);
}
//每次刷新数据(有最大次数限制)就尝试获取logcat的启动时间,如果获取到了,就退出
//TODO:是否每个应用都能正常正确的获取
// get app start time from logcat on every task running
getStartTimeFromLogcat
();
}
else
{
Intent
intent
=
new
Intent
();
...
...
@@ -376,33 +379,35 @@ public class EmmageeService extends Service {
};
/**
*
get start time from logcat
*
Try to get start time from logcat.
*/
private
void
getStartTimeFromLogcat
()
{
if
(
isGetStartTime
&&
getStartTimeCount
<
MAX_START_TIME_COUNT
)
{
try
{
String
logcatCommand
=
"logcat -v time -d ActivityManager:I *:S"
;
Process
process
=
Runtime
.
getRuntime
().
exec
(
logcatCommand
);
BufferedReader
bufferedReader
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
()));
StringBuilder
strBuilder
=
new
StringBuilder
();
String
line
=
""
;
while
((
line
=
bufferedReader
.
readLine
())
!=
null
)
{
strBuilder
.
append
(
line
);
strBuilder
.
append
(
"\r\n"
);
if
(
line
.
matches
(
".*Displayed.*\\+(.*)ms.*"
))
{
//TODO:可以通过正则表达式获取,同时获取启动的是哪个Activity
startTime
=
line
.
substring
(
line
.
lastIndexOf
(
"+"
)
+
1
,
line
.
lastIndexOf
(
"ms"
)
+
2
);
Toast
.
makeText
(
EmmageeService
.
this
,
"启动时间:"
+
startTime
,
Toast
.
LENGTH_LONG
).
show
();
isGetStartTime
=
false
;
}
if
(!
isGetStartTime
||
getStartTimeCount
>=
MAX_START_TIME_COUNT
)
{
return
;
}
try
{
// filter logcat by Tag:ActivityManager and Level:Info
String
logcatCommand
=
"logcat -v time -d ActivityManager:I *:S"
;
Process
process
=
Runtime
.
getRuntime
().
exec
(
logcatCommand
);
BufferedReader
bufferedReader
=
new
BufferedReader
(
new
InputStreamReader
(
process
.
getInputStream
()));
// StringBuilder strBuilder = new StringBuilder();
String
line
=
""
;
while
((
line
=
bufferedReader
.
readLine
())
!=
null
)
{
// strBuilder.append(line);
// strBuilder.append("\r\n");
if
(
line
.
matches
(
".*Displayed.*\\+(.*)ms.*"
))
{
// TODO:regular pattern:Activity,startTime
startTime
=
line
.
substring
(
line
.
lastIndexOf
(
"+"
)
+
1
,
line
.
lastIndexOf
(
"ms"
)
+
2
);
Toast
.
makeText
(
EmmageeService
.
this
,
"启动时间:"
+
startTime
,
Toast
.
LENGTH_LONG
).
show
();
isGetStartTime
=
false
;
}
getStartTimeCount
++;
Log
.
w
(
LOG_TAG
,
"启动日志:"
+
strBuilder
.
toString
());
Log
.
w
(
LOG_TAG
,
"getStartCount:"
+
getStartTimeCount
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
getStartTimeCount
++;
// Log.w(LOG_TAG, "Start Time Log:" + strBuilder.toString());
// Log.w(LOG_TAG, "getStartCount:" + getStartTimeCount);
}
catch
(
IOException
e
)
{
Log
.
d
(
LOG_TAG
,
e
.
getMessage
());
}
}
...
...
@@ -489,14 +494,9 @@ public class EmmageeService extends Service {
if
(
windowManager
!=
null
)
windowManager
.
removeView
(
viFloatingWindow
);
handler
.
removeCallbacks
(
task
);
//在文件最后把启动时间加上
try
{
//TODO:现在把启动时间写在了文件最后
bw
.
write
(
"\r\n启动时间:"
+
startTime
+
"\r\n"
);
}
catch
(
IOException
e1
)
{
e1
.
printStackTrace
();
}
closeOpenedStream
();
// replace the start time in file
replaceFileString
(
resultFilePath
,
START_TIME
,
startTime
);
isStop
=
true
;
unregisterReceiver
(
batteryBroadcast
);
boolean
isSendSuccessfully
=
false
;
...
...
@@ -515,6 +515,31 @@ public class EmmageeService extends Service {
stopForeground
(
true
);
}
/**
* Replaces all matches for replaceType within this replaceString in file on the filePath
* @param filePath
* @param replaceType
* @param replaceString
*/
private
void
replaceFileString
(
String
filePath
,
String
replaceType
,
String
replaceString
)
{
try
{
File
file
=
new
File
(
filePath
);
BufferedReader
reader
=
new
BufferedReader
(
new
FileReader
(
file
));
String
line
=
""
,
oldtext
=
""
;
while
((
line
=
reader
.
readLine
())
!=
null
)
{
oldtext
+=
line
+
"\r\n"
;
}
reader
.
close
();
// replace a word in a file
String
newtext
=
oldtext
.
replaceAll
(
replaceType
,
replaceString
);
BufferedWriter
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
new
FileOutputStream
(
filePath
),
"UTF-8"
));
writer
.
write
(
newtext
);
writer
.
close
();
}
catch
(
IOException
e
)
{
Log
.
d
(
LOG_TAG
,
e
.
getMessage
());
}
}
@Override
public
IBinder
onBind
(
Intent
intent
)
{
return
null
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录