提交 e5cca493 编写于 作者: R rex

bug fix 141

上级 3c65e322
......@@ -15,10 +15,10 @@ import android.text.TextUtils;
import android.text.format.DateUtils;
import android.view.Choreographer;
import com.didichuxing.doraemonkit.R;
import com.didichuxing.doraemonkit.DoraemonKit;
import com.didichuxing.doraemonkit.config.PerformanceInfoConfig;
import com.didichuxing.doraemonkit.kit.custom.PerformanceInfo;
import com.didichuxing.doraemonkit.kit.custom.UploadMonitorInfoBean;
import com.didichuxing.doraemonkit.kit.custom.UploadMonitorItem;
import com.didichuxing.doraemonkit.kit.network.NetworkManager;
import com.didichuxing.doraemonkit.util.FileManager;
import com.didichuxing.doraemonkit.util.JsonUtil;
......@@ -54,6 +54,10 @@ public class PerformanceDataManager {
private int mLastSkippedFrames;
private float mLastCpuRate;
private float mLastMemoryInfo;
private long mUpBytes;
private long mDownBytes;
private long mLastUpBytes;
private long mLastDownBytes;
private Handler mHandler;
private HandlerThread mHandlerThread;
private float mMaxMemory;
......@@ -67,6 +71,7 @@ public class PerformanceDataManager {
private static final int MSG_CPU = 1;
private static final int MSG_MEMORY = 2;
private static final int MSG_SAVE_LOCAL = 3;
private static final int MSG_NET_FLOW = 4;
private UploadMonitorInfoBean mUploadMonitorBean;
private boolean mUploading;
private Handler mMainHandler = new Handler(Looper.getMainLooper());
......@@ -179,6 +184,10 @@ public class PerformanceDataManager {
} else if (msg.what == MSG_MEMORY) {
executeMemoryData();
mHandler.sendEmptyMessageDelayed(MSG_MEMORY, NORMAL_FRAME_RATE * 1000);
} else if (msg.what == MSG_NET_FLOW){
mLastUpBytes = NetworkManager.get().getTotalRequestSize() - mUpBytes;
mLastDownBytes = NetworkManager.get().getTotalResponseSize() - mDownBytes;
mHandler.sendEmptyMessageDelayed(MSG_NET_FLOW, NORMAL_FRAME_RATE * 1000);
} else if (msg.what == MSG_SAVE_LOCAL){
saveToLocal();
mHandler.sendEmptyMessageDelayed(MSG_SAVE_LOCAL, NORMAL_FRAME_RATE * 1000);
......@@ -213,6 +222,14 @@ public class PerformanceDataManager {
mHandler.sendEmptyMessageDelayed(MSG_CPU, NORMAL_FRAME_RATE * 1000);
}
public void startMonitorNetFlowInfo() {
mHandler.sendEmptyMessageDelayed(MSG_NET_FLOW, NORMAL_FRAME_RATE * 1000);
}
public void stopMonitorNetFlowInfo() {
mHandler.removeMessages(MSG_NET_FLOW);
}
public void startUploadMonitorData() {
mUploading = true;
if (mUploadMonitorBean != null) {
......@@ -229,6 +246,7 @@ public class PerformanceDataManager {
}
if (PerformanceInfoConfig.isTrafficOpen(mContext)) {
NetworkManager.get().startMonitor();
startMonitorNetFlowInfo();
}
mHandler.sendEmptyMessageDelayed(MSG_SAVE_LOCAL, NORMAL_FRAME_RATE * 1000);
}
......@@ -240,6 +258,7 @@ public class PerformanceDataManager {
stopMonitorFrameInfo();
stopMonitorCPUInfo();
stopMonitorMemoryInfo();
stopMonitorNetFlowInfo();
NetworkManager.get().stopMonitor();
}
......@@ -270,11 +289,25 @@ public class PerformanceDataManager {
mUploadMonitorBean.performanceArray = new ArrayList<>();
}
}
PerformanceInfo info = new PerformanceInfo();
NetworkManager networkManager = NetworkManager.get();
long upSize = networkManager.getTotalRequestSize();
long downSize = networkManager.getTotalResponseSize();
UploadMonitorItem info = new UploadMonitorItem();
info.cpu = mLastCpuRate;
info.fps = mLastFrameRate;
info.memory = mLastMemoryInfo;
info.upFlow = mLastUpBytes;
info.downFlow = mLastDownBytes;
mUpBytes = upSize;
mDownBytes = downSize;
info.timestamp = System.currentTimeMillis();
String pageName = "unkown";
if (DoraemonKit.getCurrentResumedActivity() != null) {
pageName = DoraemonKit.getCurrentResumedActivity().getLocalClassName();
}
info.page = pageName;
mUploadMonitorBean.performanceArray.add(info);
}
......@@ -478,4 +511,12 @@ public class PerformanceDataManager {
writeFpsDataIntoFile();
}
}
public long getLastUpBytes() {
return mLastUpBytes;
}
public long getLastDownBytes() {
return mLastDownBytes;
}
}
......@@ -11,20 +11,22 @@ import android.view.View;
import com.didichuxing.doraemonkit.R;
import com.didichuxing.doraemonkit.kit.common.PerformanceDataManager;
import com.didichuxing.doraemonkit.ui.base.BaseFragment;
import com.didichuxing.doraemonkit.ui.fileexplorer.FileInfo;
import com.didichuxing.doraemonkit.ui.widget.recyclerview.DividerItemDecoration;
import com.didichuxing.doraemonkit.ui.widget.titlebar.HomeTitleBar;
import com.didichuxing.doraemonkit.ui.widget.titlebar.TitleBar;
import com.didichuxing.doraemonkit.util.JsonUtil;
import com.google.gson.reflect.TypeToken;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Type;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
public class PageDataFragment extends BaseFragment {
private RecyclerView mRvList;
......@@ -99,53 +101,75 @@ public class PageDataFragment extends BaseFragment {
return dataItems;
}
Map<String,List<UploadMonitorItem>> listMap = new TreeMap<>();
for (UploadMonitorInfoBean infoBean : infoBeans) {
if(null == infoBean || null == infoBean.performanceArray || 0 >= infoBean.performanceArray.size()){
continue;
}
PageDataItem item = new PageDataItem();
List<PerformanceInfo> performanceInfos = infoBean.performanceArray;
item.pageName = infoBean.appName;
item.upNetWork =new PageDataItemChild<>(R.string.dk_frameinfo_upstream);
item.downNetWork = new PageDataItemChild<>(R.string.dk_frameinfo_downstream);
item.memory = new PageDataItemChild<>(R.string.dk_frameinfo_ram);
item.cpu = new PageDataItemChild<>(R.string.dk_frameinfo_cpu);
item.fps = new PageDataItemChild<>(R.string.dk_frameinfo_fps);
for (PerformanceInfo info : performanceInfos) {
setValue(item.memory,info.memory);
setValue(item.cpu,info.cpu);
setValue(item.fps,info.fps);
List<UploadMonitorItem> performanceInfos = infoBean.performanceArray;
for (UploadMonitorItem item : performanceInfos) {
List<UploadMonitorItem> itemList = listMap.get(item.page);
if(null == itemList){
itemList = new ArrayList<>();
listMap.put(item.page, itemList);
}
item.memory.avg /= performanceInfos.size();
item.cpu.avg /= performanceInfos.size();
item.fps.avg /= performanceInfos.size();
itemList.add(item);
}
}
dataItems.add(item);
for (String pageName : listMap.keySet()) {
dataItems.addAll(getPageItemData(pageName, listMap.get(pageName)));
}
return dataItems;
}
private void setValue(PageDataItemChild<Float> child, float newValue) {
child.min = Math.min(null == child.min ? 0:child.min, newValue);
child.max = Math.max(null == child.max ? 0:child.max, newValue);
child.avg = (null == child.avg ? 0:child.avg)+newValue;
private List<PageDataItem> getPageItemData(String appName, List<UploadMonitorItem> performanceInfos) {
List<PageDataItem> dataItems = new ArrayList<>();
PageDataItem item = new PageDataItem();
item.pageName = appName;
item.upNetWork =new PageDataItemChild(R.string.dk_frameinfo_upstream);
item.downNetWork = new PageDataItemChild(R.string.dk_frameinfo_downstream);
item.memory = new PageDataItemChild(R.string.dk_frameinfo_ram);
item.cpu = new PageDataItemChild(R.string.dk_frameinfo_cpu);
item.fps = new PageDataItemChild(R.string.dk_frameinfo_fps);
for (UploadMonitorItem monitorItem : performanceInfos) {
setValue(item.upNetWork,monitorItem.upFlow);
setValue(item.downNetWork,monitorItem.downFlow);
setValue(item.memory,monitorItem.memory);
setValue(item.cpu,monitorItem.cpu);
setValue(item.fps,monitorItem.fps);
}
int size = performanceInfos.size();
if(0 < size){
item.upNetWork.avg /= size;
item.downNetWork.avg /= size;
item.memory.avg /= size;
item.cpu.avg /= size;
item.fps.avg /= size;
}else{
item.upNetWork.avg = 0;
item.downNetWork.avg = 0;
item.memory.avg = 0;
item.cpu.avg = 0;
item.fps.avg = 0;
}
private void setValue(PageDataItemChild<Integer> child, int newValue) {
child.min = Math.min(null == child.min ? 0:child.min, newValue);
child.max = Math.max(null == child.max ? 0:child.max, newValue);
child.avg = (null == child.avg ? 0:child.avg)+newValue;
dataItems.add(item);
return dataItems;
}
private void setValue(PageDataItemChild<Double> child, double newValue) {
child.min = Math.min(null == child.min ? 0:child.min, newValue);
child.max = Math.max(null == child.max ? 0:child.max, newValue);
child.avg = (null == child.avg ? 0:child.avg)+newValue;
private void setValue(PageDataItemChild child, double newValue) {
child.min = 0 == child.min || 0 == newValue ? child.min+newValue : Math.min(child.min, newValue);
child.max = 0 == child.max || 0 == newValue ? child.max+newValue : Math.max(child.max, newValue);
child.avg += newValue;
}
private String getFileString(File file) {
......
......@@ -6,27 +6,27 @@ import android.view.View;
public class PageDataItem {
public String pageName;
public PageDataItemChild<Double> upNetWork;
public PageDataItemChild<Double> downNetWork;
public PageDataItemChild<Float> memory;
public PageDataItemChild<Float> cpu;
public PageDataItemChild<Integer> fps;
public PageDataItemChild upNetWork;
public PageDataItemChild downNetWork;
public PageDataItemChild memory;
public PageDataItemChild cpu;
public PageDataItemChild fps;
public PageDataItem() {
}
}
class PageDataItemChild<T extends Number> {
class PageDataItemChild {
@StringRes
public int nameResId;
public T min;
public T max;
public T avg;
public double min;
public double max;
public double avg;
public PageDataItemChild(int nameResId) {
this.nameResId = nameResId;
}
public int getVisibility(PageDataItemChild<? extends Number> child){
public int getVisibility(PageDataItemChild child){
return 0 < getValue(child.min)+ getValue(child.max) + getValue(child.avg)
? View.VISIBLE: View.GONE;
}
......@@ -43,23 +43,27 @@ class PageDataItemChild<T extends Number> {
this.nameResId = nameResId;
}
public void setMin(T min) {
public double getMin() {
return min;
}
public void setMin(double min) {
this.min = min;
}
public T getMax() {
public double getMax() {
return max;
}
public void setMax(T max) {
public void setMax(double max) {
this.max = max;
}
public T getAvg() {
public double getAvg() {
return avg;
}
public void setAvg(T avg) {
public void setAvg(double avg) {
this.avg = avg;
}
}
......@@ -10,6 +10,8 @@ import com.didichuxing.doraemonkit.R;
import com.didichuxing.doraemonkit.ui.widget.recyclerview.AbsRecyclerAdapter;
import com.didichuxing.doraemonkit.ui.widget.recyclerview.AbsViewBinder;
import java.text.DecimalFormat;
public class PageDataItemAdapter extends AbsRecyclerAdapter<AbsViewBinder<PageDataItem>, PageDataItem> {
private Context mContext;
public PageDataItemAdapter(Context context) {
......@@ -63,7 +65,7 @@ public class PageDataItemAdapter extends AbsRecyclerAdapter<AbsViewBinder<PageDa
}
}
private void setValue(View iteView, PageDataItemChild<? extends Number> data) {
private void setValue(View iteView, PageDataItemChild data) {
int visibility = data.getVisibility(data);
iteView.setVisibility(visibility);
if(View.GONE == visibility){
......@@ -72,23 +74,28 @@ public class PageDataItemAdapter extends AbsRecyclerAdapter<AbsViewBinder<PageDa
String rule = getFormatRule(data.nameResId);
((TextView)iteView.findViewById(R.id.data_name_txt)).setText(data.nameResId);
((TextView)iteView.findViewById(R.id.high_data_txt)).setText(String.format(rule, data.max));
((TextView)iteView.findViewById(R.id.low_data_txt)).setText(String.format(rule, data.min));
((TextView)iteView.findViewById(R.id.avg_data_txt)).setText(String.format("%s - "+rule, mContext.getString(R.string.dk_frameinfo_avg_value), data.avg));
((TextView)iteView.findViewById(R.id.high_data_txt)).setText(String.format(rule, getFormatText(data.nameResId, data.max)));
((TextView)iteView.findViewById(R.id.low_data_txt)).setText(String.format(rule, getFormatText(data.nameResId, data.min)));
((TextView)iteView.findViewById(R.id.avg_data_txt)).setText(String.format("%s - "+rule, mContext.getString(R.string.dk_frameinfo_avg_value),getFormatText(data.nameResId, data.avg)));
}
private String getFormatText(int nameResId, double value){
if (nameResId == R.string.dk_frameinfo_downstream || nameResId == R.string.dk_frameinfo_upstream) {
return RealTimePerformDataFloatPage.getFlowTxt((long) value);
}
DecimalFormat df=new DecimalFormat(".#");
return df.format(value);
}
private String getFormatRule(int nameResId){
String formatRule = "";
if (nameResId == R.string.dk_frameinfo_ram) {
formatRule = "%.1fM";
formatRule = "%sM";
} else if (nameResId == R.string.dk_frameinfo_cpu) {
formatRule = "%.1f%%";
formatRule = "%s%%";
} else if (nameResId == R.string.dk_frameinfo_fps) {
formatRule = "%s";
} else if (nameResId == R.string.dk_frameinfo_downstream) {
formatRule = "%.1fB";
} else if (nameResId == R.string.dk_frameinfo_upstream) {
formatRule = "%.1fB";
} else if (nameResId == R.string.dk_frameinfo_downstream || nameResId == R.string.dk_frameinfo_upstream) {
formatRule = "%s";
}
return formatRule;
......
......@@ -15,15 +15,11 @@ import android.widget.TextView;
import com.didichuxing.doraemonkit.R;
import com.didichuxing.doraemonkit.config.PerformanceInfoConfig;
import com.didichuxing.doraemonkit.kit.common.PerformanceDataManager;
import com.didichuxing.doraemonkit.kit.network.NetworkManager;
import com.didichuxing.doraemonkit.kit.network.bean.NetworkRecord;
import com.didichuxing.doraemonkit.kit.timecounter.TimeCounterManager;
import com.didichuxing.doraemonkit.ui.base.BaseFloatPage;
import com.didichuxing.doraemonkit.ui.base.TouchProxy;
import com.didichuxing.doraemonkit.util.UIUtils;
import java.util.List;
/**
*
*/
......@@ -119,17 +115,27 @@ public class RealTimePerformDataFloatPage extends BaseFloatPage implements Touch
mDownNetworkTxt.setVisibility(View.VISIBLE);
mUpNetworkTxt.setVisibility(View.VISIBLE);
List<NetworkRecord> records = NetworkManager.get().getRecords();
long requestLength = null != records && 0 < records.size() ? records.get(records.size() - 1).requestLength : 0;
long responseLength = null != records && 0 < records.size() ? records.get(records.size() - 1).responseLength : 0;
mDownNetworkTxt.setText(String.format("%s: %sB", getString(R.string.dk_frameinfo_downstream), requestLength));
mUpNetworkTxt.setText(String.format("%s: %sB", getString(R.string.dk_frameinfo_upstream), responseLength));
mDownNetworkTxt.setText(String.format("%s%s", getString(R.string.dk_frameinfo_downstream), getFlowTxt(manager.getLastDownBytes())));
mUpNetworkTxt.setText(String.format("%s%s", getString(R.string.dk_frameinfo_upstream), getFlowTxt(manager.getLastUpBytes())));
}else{
mDownNetworkTxt.setVisibility(View.INVISIBLE);
mUpNetworkTxt.setVisibility(View.INVISIBLE);
}
}
public static String getFlowTxt(long flowBytes) {
String upFlowTxt = flowBytes+"B";
if(1073741824 < flowBytes) {
upFlowTxt = flowBytes/1073741824 +"GB";
}else if(1048576 < flowBytes) {
upFlowTxt = flowBytes/1048576 +"MB";
}else if(1024 < flowBytes) {
upFlowTxt = flowBytes/1024 +"KB";
}
return upFlowTxt;
}
@Override
public void onMove(int x, int y, int dx, int dy) {
getLayoutParams().x += dx;
......
......@@ -5,6 +5,6 @@ import java.util.List;
public class UploadMonitorInfoBean {
public long timestamp;
public String appName;
public List<PerformanceInfo> performanceArray;
public List<UploadMonitorItem> performanceArray;
}
package com.didichuxing.doraemonkit.kit.custom;
public class UploadMonitorItem {
public String page = "unkown";
public long timestamp;
public int fps;
public float memory;
public float cpu;
public long upFlow;
public long downFlow;
}
package com.didichuxing.doraemonkit.kit.network.bean;
public class NetflowInfo {
public long flow;
public long timestamp;
public String page;
public boolean isUp;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册