?????????????1??????????????Щ????????????????????????????????????log??????????????????????Ч????
?????????????????????
????1. Android?????????????
????????????Activity???????????????????Log.e(tag??message)??????Ч????
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e("AppStartTime"??"AppOnCreate");
...
}
@Override
protected void onResume() {
super.onResume();
Log.e("AppStartTime"??"AppOnResume");
...
}
???????????tag???????AppStartTime?????????????????????????command??????
????adb logcat -v time -v threadtime *:E | grep ActivityStartTime>StartTimeFile.txt
????2. cpu?????????
??????command??????????????
????adb shell top -n 400 | grep <your package name>Cpu_MemoryFile.txt
????3. GC
??????command??????????????
????adb logcat -v time -v threadtime *:D | grep GC>GCFile.txt
??????????????????GC??????????????????????
????average_GC_Freed
????average_GC_per
????average_GC_time
????4. ????????
??????????????????????????????????????????service????????getAppTrafficList( )?????????????£?
publicvoidgetAppTrafficList(){
PackageManagerpm=getPackageManager();
List<PackageInfo>pinfos=pm
.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES
|PackageManager.GET_PERMISSIONS);
for(PackageInfoinfo:pinfos){
String[]premissions=info.requestedPermissions;
if(premissions!=null&&premissions.length>0){
for(Stringpremission:premissions){
if("android.permission.INTERNET".equals(premission)){
intuId=info.applicationInfo.uid;
longrx=TrafficStats.getUidRxBytes(uId);
longtx=TrafficStats.getUidTxBytes(uId);
if(rx<0||tx<0){
continue;
}else{
Log.e("????????"??info.applicationInfo.loadLabel(pm)+Formatter.formatFileSize(this??rx+tx)
}
}
}
}
}
}