From ae400ef024ceb69fd498f0f85e7a443c1095be00 Mon Sep 17 00:00:00 2001 From: dongkyu6 lee Date: Thu, 31 Mar 2016 18:43:27 +0900 Subject: [PATCH] [SRADA-177] Fixed that Statistics Table has wrong value - But it needs improvement. - Please suggest good algorithm. Change-Id: I7774acf5007c4bb90a9bf644d9f2fa940c06fed3 --- .../ui/memory/table/MemoryStatisticsTable.java | 168 ++++++++++++--------- 1 file changed, 95 insertions(+), 73 deletions(-) diff --git a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/memory/table/MemoryStatisticsTable.java b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/memory/table/MemoryStatisticsTable.java index e158175..0dddc4c 100755 --- a/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/memory/table/MemoryStatisticsTable.java +++ b/org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/memory/table/MemoryStatisticsTable.java @@ -37,6 +37,7 @@ import org.tizen.dynamicanalyzer.model.TableInput; import org.tizen.dynamicanalyzer.model.TreeInput; import org.tizen.dynamicanalyzer.nl.MemoryPageLabels; import org.tizen.dynamicanalyzer.ui.memory.data.AllocateDBTable; +import org.tizen.dynamicanalyzer.ui.memory.data.FreeDBTable; import org.tizen.dynamicanalyzer.ui.memory.data.MemoryDataManager; import org.tizen.dynamicanalyzer.ui.toolbar.Toolbar; import org.tizen.dynamicanalyzer.ui.widgets.table.DATableComposite; @@ -45,15 +46,15 @@ import org.tizen.dynamicanalyzer.ui.widgets.table.TableColumnSizePackListener; import org.tizen.dynamicanalyzer.util.Logger; public class MemoryStatisticsTable extends DATableComposite { - + private int[] columnSizes = { 200 , 100, 80, 80, 100, 80 }; private boolean[] columnVisibility = { true, true, true, true, true, true }; private int[] columnAlignment = { SWT.RIGHT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT, SWT.RIGHT }; - + private Long StartTime; - private Long EndTime; - + private Long EndTime; + private String[] columnNames = { MemoryPageLabels.MEMORY_STATISTICS_VIEW_PATH, MemoryPageLabels.MEMORY_STATISTICS_VIEW_PERSISTENT_BYTE, @@ -62,27 +63,32 @@ public class MemoryStatisticsTable extends DATableComposite { MemoryPageLabels.MEMORY_STATISTICS_VIEW_TOTAL_BYTE, MemoryPageLabels.MEMORY_STATISTICS_VIEW_TOTAL }; - + int[] sortTypes = { AnalyzerConstants.SORT_TYPE_STRING, AnalyzerConstants.SORT_TYPE_STRING, AnalyzerConstants.SORT_TYPE_NUM, AnalyzerConstants.SORT_TYPE_NUM, AnalyzerConstants.SORT_TYPE_STRING, AnalyzerConstants.SORT_TYPE_NUM }; - + + private final int OUTPUT_PERSISTENT_BYTE = 0; + private final int OUTPUT_PERSISTENT_COUNT = 1; + private final int OUTPUT_FREE_COUNT = 2; + private final int OUTPUT_TOTAL_BYTE = 3; + public MemoryStatisticsTable(Composite parent, int style, int tableStyle) { super(parent, style, tableStyle); - + StartTime = (long)0; EndTime = (long)0; - + setSortTypes(sortTypes); setColumnAlignment(columnAlignment); setColumns(columnNames); setColumnSize(columnSizes); setColumnVisibility(columnVisibility); - + parent.addControlListener(new TableColumnSizePackListener(this, columnSizes)); } - + public void setSelectionRange(Long start, Long end){ StartTime = start; EndTime = end; @@ -92,16 +98,40 @@ public class MemoryStatisticsTable extends DATableComposite { protected List makeTableInput() { List output = new ArrayList(); List> allocDataList = null; - List> freeDataList = null; - List pidlist = new ArrayList(); - + List> freeDataList = null; + if(Global.getProject() == null) { return output; } - + + String pidliststring = getTargetPIDString(); + + allocDataList = MemoryDataManager.getInstance().getAllocationDataFromDB(StartTime, EndTime, pidliststring); + freeDataList = MemoryDataManager.getInstance().getFreeDataFromDB(StartTime, EndTime, pidliststring); + + if (allocDataList == null || freeDataList == null || allocDataList.size() == 0) + return output; + + Map> staticdatas = calculateAllocateData(allocDataList, freeDataList); + + int index = 0; + for(Map.Entry> elem : staticdatas.entrySet()) { + TableInput staticInput = makeTreeInputForDatas(elem.getKey(), elem.getValue(), index++); + + if (staticInput != null){ + output.add(staticInput); + } + } + + return output; + } + + private String getTargetPIDString(){ + List pidlist = new ArrayList(); + int[] pids = Global.getProject().getProcessIDs(); int targetPID = Toolbar.INSTANCE.getSelectedPid(); - + if(targetPID > 0) { pidlist.add(targetPID); } @@ -110,56 +140,40 @@ public class MemoryStatisticsTable extends DATableComposite { pidlist.add(pids[i]); } } - + String pidliststring = "("; - + for(int i = 0 ; i < pidlist.size() ; i++) { pidliststring += Integer.toString(pidlist.get(i)); - + if(i != pidlist.size() - 1) { pidliststring += ", "; } } - + pidliststring += ")"; - - allocDataList = MemoryDataManager.getInstance().getAllocationDataFromDB(StartTime, EndTime, pidliststring); - freeDataList = MemoryDataManager.getInstance().getFreeDataFromDB(StartTime, EndTime, pidliststring); - if (allocDataList == null || freeDataList == null || allocDataList.size() == 0) - return output; - - Map> staticdatas = calculateAllocateData(allocDataList, freeDataList); - - int index = 0; - for(Map.Entry> elem : staticdatas.entrySet()) { - TableInput staticInput = makeTreeInputForDatas(elem.getKey(), elem.getValue(), index++); - - if (staticInput != null){ - output.add(staticInput); - } - } - - return output; + return pidliststring; } - + + @SuppressWarnings("unchecked") private Map> calculateAllocateData(List> allocData, List> freeData) { // Map for result Map> output = new HashMap> (); - // Map for saving allocation address - Map> addresmap = new HashMap> (); - + // List for saving allocation address + List addresslist = new ArrayList (); + for (int i = 0; i < allocData.size(); i++) { // Get one allocation api data List iAllocData = allocData.get(i); String libname = (String) iAllocData.get(AllocateDBTable.COLUMN.CALLER_LIBRARY_NAME.index); Long address = (Long) iAllocData.get(AllocateDBTable.COLUMN.ALLOCATED_ADDRESS.index); Long size = (Long) iAllocData.get(AllocateDBTable.COLUMN.ALLOCATED_MEMORY_SIZE.index); - + // Save each library to Map if(!output.containsKey(libname)) { List allocdata = new ArrayList(); - + // Persistent Byte allocdata.add(size); // Persistent Count @@ -168,40 +182,49 @@ public class MemoryStatisticsTable extends DATableComposite { allocdata.add((Integer) 0); // Total Byte allocdata.add(size); - + output.put(libname, allocdata); } else { - Long sumsize = (Long)output.get(libname).get(0) + size; - output.get(libname).set(0, sumsize); - output.get(libname).set(1, (Integer) output.get(libname).get(1) + 1); - output.get(libname).set(3, sumsize); + Long sumsize = (Long)output.get(libname).get(OUTPUT_PERSISTENT_BYTE) + size; + output.get(libname).set(OUTPUT_PERSISTENT_BYTE, sumsize); + output.get(libname).set(OUTPUT_PERSISTENT_COUNT, + (Integer) output.get(libname).get(OUTPUT_PERSISTENT_COUNT) + 1); + output.get(libname).set(OUTPUT_TOTAL_BYTE, sumsize); } - + List onedata = new ArrayList (); + onedata.add(address); onedata.add(libname); onedata.add(size); - - addresmap.put(address, onedata); + + addresslist.add(onedata); } - + for (int i = 0; i < freeData.size(); i++) { List iFreeData = freeData.get(i); - long address = (Long) iFreeData.get(4); - - if(addresmap.containsKey(address)) { - String libname = (String) addresmap.get(address).get(0); - Long allocsize = (Long) addresmap.get(address).get(1); - output.get(libname).set(0, (Long) output.get(libname).get(0) - allocsize); - output.get(libname).set(2, (Integer) output.get(libname).get(2) + 1); - - addresmap.remove(address); + long address = (Long) iFreeData.get(FreeDBTable.COLUMN.ALLOCATED_ADDRESS.index); + + for(int j = 0; j < addresslist.size() ; j++) { + if((Long)((List)addresslist.get(j)).get(0) == address) { + List templist = (List)addresslist.get(j); + + String libname = (String) templist.get(1); + Long allocsize = (Long) templist.get(2); + Long persistentsize = (Long) output.get(libname).get(OUTPUT_PERSISTENT_BYTE); + int count = (Integer) output.get(libname).get(OUTPUT_FREE_COUNT); + output.get(libname).set(OUTPUT_PERSISTENT_BYTE, persistentsize - allocsize); + output.get(libname).set(OUTPUT_FREE_COUNT, count + 1); + + addresslist.remove(j); + break; + } } } - + return output; } - + private TableInput makeTreeInputForDatas(String path, List staticdata, int index) { DATableDataFormat tableData = new DATableDataFormat(index); @@ -212,27 +235,26 @@ public class MemoryStatisticsTable extends DATableComposite { Logger.error("very strange case !!"); return null; } - + // Path String libname = path; - + if(path == Global.getCurrentApplication().getMainApp().getExecPath()) { libname = MemoryPageLabels.MEMORY_MAIN_EXCUTABLE; } - + text.add(libname); data.add(libname); - // Persistent byte Long PByte = (Long) staticdata.get(0); data.add(PByte); - + String pbytestr = String.format("%,d B", PByte); if (PByte > 1024) { PByte /= 1024; pbytestr = String.format("%,d KB", PByte); } - + text.add(pbytestr); // Persistent count @@ -248,7 +270,7 @@ public class MemoryStatisticsTable extends DATableComposite { // Total Byte Long TotalByte = (Long) staticdata.get(3); data.add(TotalByte); - + String tbytestr = String.format("%,d B", TotalByte); if (TotalByte > 1024) { TotalByte /= 1024; @@ -260,7 +282,7 @@ public class MemoryStatisticsTable extends DATableComposite { Integer TotalCount = PCount + FCount; text.add(TotalCount.toString()); data.add(TotalCount); - + TreeInput output = new TreeInput(); output.setText(text); tableData.getData().addAll(data); @@ -268,9 +290,9 @@ public class MemoryStatisticsTable extends DATableComposite { return output; } - + public void removeSelection() { table.removeAll(); updateTable(); } -} +} \ No newline at end of file -- 2.7.4