提交 4c2dc6d7 编写于 作者: A andrewleo

Added: #35 add top activity name to csv report and #34 change encoding to...

Added: #35 add top activity name to csv report and #34 change encoding to 'GBK' when system language is chinese
上级 f24c6416
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.netease.qa.emmagee"
android:versionCode="30"
android:versionName="2.1" >
android:versionCode="31"
android:versionName="2.2" >
<uses-sdk android:minSdkVersion="8" />
......@@ -43,4 +43,5 @@
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
</manifest>
\ No newline at end of file
......@@ -73,4 +73,7 @@
同时支持自定义的监控频率以及性能数据的实时显示.</string>
<string name="about_team">开发团队:网易(杭州)质量保障部</string>
<string name="about_project_address">项目地址:https://github.com/NetEase/Emmagee</string>
<string name="top_activity">栈顶Activity名称</string>
<string name="csv_encoding">GBK</string>
</resources>
......@@ -73,5 +73,8 @@
Additionally, it also provides several cool features such as customizing interval of collecting
data, rendering real-time process status in a floating window, and much more.</string>
<string name="about_team">Team:QA, Netease(Hangzhou)</string>
<string name="about_project_address">Project Address:https://github.com/NetEase/Emmagee</string>
<string name="about_project_address">Project Site:https://github.com/NetEase/Emmagee</string>
<string name="top_activity">Top Activity Name</string>
<string name="csv_encoding">UTF-8</string>
</resources>
......@@ -59,6 +59,7 @@ import android.widget.Toast;
import com.netease.qa.emmagee.R;
import com.netease.qa.emmagee.activity.MainPageActivity;
import com.netease.qa.emmagee.utils.Constants;
import com.netease.qa.emmagee.utils.CpuInfo;
import com.netease.qa.emmagee.utils.CurrentInfo;
import com.netease.qa.emmagee.utils.EncryptData;
......@@ -256,7 +257,7 @@ public class EmmageeService extends Service {
File resultFile = new File(resultFilePath);
resultFile.createNewFile();
out = new FileOutputStream(resultFile);
osw = new OutputStreamWriter(out, "UTF-8");
osw = new OutputStreamWriter(out, getString(R.string.csv_encoding));
bw = new BufferedWriter(osw);
long totalMemorySize = memoryInfo.getTotalMemory();
String totalMemory = fomart.format((double) totalMemorySize / 1024);
......@@ -264,22 +265,24 @@ public class EmmageeService extends Service {
// titles of multiple cpu cores
ArrayList<String> cpuList = cpuInfo.getCpuList();
for (int i = 0; i < cpuList.size(); i++) {
multiCpuTitle += "," + cpuList.get(i) + getString(R.string.total_usage);
multiCpuTitle += Constants.COMMA + cpuList.get(i) + getString(R.string.total_usage);
}
bw.write(getString(R.string.process_package) + ": ," + packageName + "\r\n" + getString(R.string.process_name) + ": ," + processName
+ "\r\n" + getString(R.string.process_pid) + ": ," + pid + "\r\n" + getString(R.string.mem_size) + ": ," + totalMemory + "MB\r\n"
+ getString(R.string.cpu_type) + ": ," + cpuInfo.getCpuName() + "\r\n" + getString(R.string.android_system_version) + ": ,"
+ memoryInfo.getSDKVersion() + "\r\n" + getString(R.string.mobile_type) + ": ," + memoryInfo.getPhoneType() + "\r\n" + "UID"
+ ": ," + uid + "\r\n");
bw.write(getString(R.string.process_package) + ": ," + packageName + Constants.LINE_END + getString(R.string.process_name) + ": ,"
+ processName + Constants.LINE_END + getString(R.string.process_pid) + ": ," + pid + Constants.LINE_END
+ getString(R.string.mem_size) + ": ," + totalMemory + "MB" + Constants.LINE_END + getString(R.string.cpu_type) + ": ,"
+ cpuInfo.getCpuName() + Constants.LINE_END + getString(R.string.android_system_version) + ": ," + memoryInfo.getSDKVersion()
+ Constants.LINE_END + getString(R.string.mobile_type) + ": ," + memoryInfo.getPhoneType() + Constants.LINE_END + "UID" + ": ,"
+ uid + Constants.LINE_END);
if (isGrantedReadLogsPermission()) {
bw.write(START_TIME);
}
bw.write(getString(R.string.timestamp) + "," + getString(R.string.used_mem_PSS) + "," + getString(R.string.used_mem_ratio) + ","
+ getString(R.string.mobile_free_mem) + "," + getString(R.string.app_used_cpu_ratio) + ","
+ getString(R.string.total_used_cpu_ratio) + multiCpuTitle + "," + getString(R.string.traffic) + ","
+ getString(R.string.battery) + "," + getString(R.string.current) + "," + getString(R.string.temperature) + ","
+ getString(R.string.voltage) + "\r\n");
bw.write(getString(R.string.timestamp) + Constants.COMMA + getString(R.string.top_activity) + Constants.COMMA
+ getString(R.string.used_mem_PSS) + Constants.COMMA + getString(R.string.used_mem_ratio) + Constants.COMMA
+ getString(R.string.mobile_free_mem) + Constants.COMMA + getString(R.string.app_used_cpu_ratio) + Constants.COMMA
+ getString(R.string.total_used_cpu_ratio) + multiCpuTitle + Constants.COMMA + getString(R.string.traffic) + Constants.COMMA
+ getString(R.string.battery) + Constants.COMMA + getString(R.string.current) + Constants.COMMA + getString(R.string.temperature)
+ Constants.COMMA + getString(R.string.voltage) + Constants.LINE_END);
} catch (IOException e) {
Log.e(LOG_TAG, e.getMessage());
}
......
package com.netease.qa.emmagee.utils;
/**
* Constant Class
*
* @author andrewleo
*
*/
public final class Constants {
public static final String NA = "N/A";
public static final String COMMA = ",";
public static final String LINE_END = "\r\n";
public static final String COLON = ":";
}
......@@ -71,8 +71,6 @@ public class CpuInfo {
private static final String CPU_X86 = "x86";
private static final String CPU_INFO_PATH = "/proc/cpuinfo";
private static final String CPU_STAT = "/proc/stat";
private static final String NA = "N/A";
private static final String COMMA = ",";
public CpuInfo(Context context, int pid, String uid) {
this.pid = pid;
......@@ -247,10 +245,10 @@ public class CpuInfo {
Calendar cal = Calendar.getInstance();
if ((Build.MODEL.equals("sdk")) || (Build.MODEL.equals("google_sdk"))) {
mDateTime2 = formatterFile.format(cal.getTime().getTime() + 8 * 60 * 60 * 1000);
totalBatt = NA;
currentBatt = NA;
temperature = NA;
voltage = NA;
totalBatt = Constants.NA;
currentBatt = Constants.NA;
temperature = Constants.NA;
voltage = Constants.NA;
} else
mDateTime2 = formatterFile.format(cal.getTime().getTime());
if (isInitialStatics) {
......@@ -276,7 +274,7 @@ public class CpuInfo {
.get(i) - totalCpu2.get(i))));
}
totalCpuRatio.add(cpuRatio);
totalCpuBuffer.append(cpuRatio + COMMA);
totalCpuBuffer.append(cpuRatio + Constants.COMMA);
}
} else {
processCpuRatio = "0";
......@@ -303,13 +301,14 @@ public class CpuInfo {
String trafValue;
// whether certain device supports traffic statics or not
if (traffic == -1) {
trafValue = NA;
trafValue = Constants.NA;
} else {
trafValue = String.valueOf(traffic);
}
EmmageeService.bw.write(mDateTime2 + COMMA + pMemory + COMMA + percent + COMMA + fMemory + COMMA + processCpuRatio + COMMA
+ totalCpuBuffer.toString() + trafValue + COMMA + totalBatt + COMMA + currentBatt + COMMA + temperature + COMMA + voltage
+ "\r\n");
EmmageeService.bw.write(mDateTime2 + Constants.COMMA + ProcessInfo.getTopActivity(context) + Constants.COMMA + pMemory
+ Constants.COMMA + percent + Constants.COMMA + fMemory + Constants.COMMA + processCpuRatio + Constants.COMMA
+ totalCpuBuffer.toString() + trafValue + Constants.COMMA + totalBatt + Constants.COMMA + currentBatt + Constants.COMMA
+ temperature + Constants.COMMA + voltage + Constants.LINE_END);
totalCpu2 = (ArrayList<Long>) totalCpu.clone();
processCpu2 = processCpu;
idleCpu2 = (ArrayList<Long>) idleCpu.clone();
......
......@@ -22,9 +22,11 @@ import java.util.List;
import android.app.ActivityManager;
import android.app.ActivityManager.RunningAppProcessInfo;
import android.app.ActivityManager.RunningTaskInfo;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Debug;
import android.util.Log;
/**
......@@ -87,4 +89,20 @@ public class ProcessInfo {
List<ApplicationInfo> appList = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
return appList;
}
/**
* get top activity name
*
* @param context
* context of activity
* @return top activity name
*/
public static String getTopActivity(Context context) {
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);
if (runningTaskInfos != null)
return (runningTaskInfos.get(0).topActivity).toString();
else
return null;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册