}\r
}\r
\r
- public void makeAllocData(MemoryData log) {\r
+ private void makeAllocData(MemoryData log) {\r
ArrayList<Object> dbAllocData = new ArrayList<Object>();\r
\r
MemoryData mData = log;\r
memoryAllocDataList.add(dbAllocData);\r
}\r
\r
- public void makeFreeData(MemoryData log) {\r
+ private void makeFreeData(MemoryData log) {\r
ArrayList<Object> dbFreeData = new ArrayList<Object>();\r
\r
MemoryData mData = log;\r
memoryfreeDataList.add(dbFreeData);\r
}\r
\r
+ private void GetAllocationData(List<LogData> memoryLogList) {\r
+ int size = memoryLogList.size();\r
+ for (int i = 0; i < size; i++) {\r
+ MemoryData logData = (MemoryData) memoryLogList.get(i);\r
+ if (allocByteMap.get(logData.getPid()) == null) {\r
+ allocByteMap.put(Integer.valueOf(logData.getPid()), new Long(0));\r
+ libraryAllocByteMap.put(Integer.valueOf(logData.getPid()), new HashMap<Integer, Long>());\r
+ }\r
+\r
+ int memApiType = logData.getMemoryApiType();\r
+ int internalFlag = logData.getInternalCall();\r
+ long errorNo = logData.getErrno();\r
+ \r
+ /*\r
+ * Check library allocation\r
+ */\r
+ BinaryInfo binaryInfo = null;\r
+ Project project = Global.getProject();\r
+ ProcessMemoryMap pmap = project.getProcessInformation(logData.getPid()).getProcessMemoryMap(logData.getTime());\r
+\r
+ if (pmap != null) {\r
+ LibraryObject lib = pmap.getLibraryByAddress(logData.getCallerPcAddr());\r
+ if (lib != null && lib != pmap.getMainbinary()) {\r
+ binaryInfo = project.getDeviceStatusInfo().getBinaryInfo(lib.getBinaryID());\r
+ }\r
+ }\r
+\r
+ if (errorNo == 0 && MEM_USER == internalFlag) {\r
+ if (MEM_API_TYPE_ALLOC == memApiType || MEM_API_TYPE_FREE == memApiType) {\r
+ addNewSeriesUserAllocData(memApiType, logData, binaryInfo);\r
+ }\r
+ }\r
+\r
+ /*\r
+ * Save allocation and free api call \r
+ */\r
+ if(MEM_API_TYPE_ALLOC == memApiType) {\r
+ makeAllocData(logData);\r
+ }\r
+ else if(MEM_API_TYPE_FREE == memApiType) {\r
+ makeFreeData(logData);\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ private void GetSystemMemoryData(List<LogData> systemLogList) {\r
+ ArrayList<List<Object>> systemDataList = new ArrayList<List<Object>>();\r
+ ArrayList<List<Object>> targetProcessDataList = new ArrayList<List<Object>>();\r
+\r
+ int size = systemLogList.size();\r
+ for (int i = 0; i < size; i++) {\r
+ SystemData log = (SystemData) systemLogList.get(i);\r
+ \r
+ /*\r
+ * Make information for other process\r
+ */\r
+ List<Object> pIDList = new ArrayList<Object>();\r
+ List<Object> processLoadList = new ArrayList<Object>();\r
+ String[] processLoadDatas = log.getOtherProcessLoad().split(CommonConstants.COMMA);\r
+ for (int ii = 0; ii < processLoadDatas.length; ii++) {\r
+ String processLoad = processLoadDatas[ii];\r
+ if (processLoad == null || processLoad.isEmpty()) {\r
+ continue;\r
+ }\r
+ pIDList.add(new Integer(processLoad));\r
+ processLoadList.add(processLoadDatas[++ii]);\r
+ }\r
+\r
+ /*\r
+ * Make SystemData Table data\r
+ */\r
+ ArrayList<Object> dbSystemData = new ArrayList<Object>();\r
+ dbSystemData.add(new Long(log.getTime()));\r
+ dbSystemData.add(new Long(log.getSystemMemoryUsed()));\r
+ dbSystemData.add(pIDList);\r
+ dbSystemData.add(processLoadList);\r
+ systemDataList.add(dbSystemData);\r
+\r
+ /*\r
+ * Make target Process Table data\r
+ */\r
+ ProcessProfileData[] targetProcessList = log.getProcessProfileDataList();\r
+ if (targetProcessList != null) {\r
+ for (int j = 0; j < targetProcessList.length; j++) {\r
+ ProcessProfileData process = targetProcessList[j];\r
+\r
+ ArrayList<Object> dbTargetProcessData = new ArrayList<Object>();\r
+ dbTargetProcessData.add(new Long(log.getTime()));\r
+ dbTargetProcessData.add(new Integer(process.getPid()));\r
+ dbTargetProcessData.add(new Float(process.getProcessLoad()));\r
+ dbTargetProcessData.add(new Long(process.getVirtualMemory()));\r
+ dbTargetProcessData.add(new Long(process.getResidentMemory()));\r
+ dbTargetProcessData.add(new Long(process.getSharedMemory()));\r
+ dbTargetProcessData.add(new Long(process.getPssMemory()));\r
+ dbTargetProcessData.add(new Integer(process.getThreadCount()));\r
+ dbTargetProcessData.add(new Long(process.getTotalAllocSize()));\r
+\r
+ /*\r
+ * Set inform for Heap allocation\r
+ */\r
+ List<Object> binaryIDList = new ArrayList<Object>();\r
+ List<Object> allocByteList = new ArrayList<Object>();\r
+ binaryIDList.add(appAllocSeriesID);\r
+ if (allocByteMap.get(process.getPid()) == null) {\r
+ allocByteList.add(new Long(0));\r
+ } else {\r
+ allocByteList.add(allocByteMap.get(process.getPid()));\r
+ }\r
+\r
+ Map<Integer, Long> libraryList = libraryAllocByteMap.get(process.getPid());\r
+ if (libraryList == null) {\r
+ libraryList = new HashMap<Integer, Long>();\r
+ }\r
+\r
+ Iterator<Integer> iter = libraryList.keySet().iterator();\r
+ while (iter.hasNext()) {\r
+ Integer binaryID = iter.next();\r
+ binaryIDList.add(binaryID);\r
+ allocByteList.add(libraryList.get(binaryID));\r
+ }\r
+ dbTargetProcessData.add(binaryIDList);\r
+ dbTargetProcessData.add(allocByteList);\r
+\r
+ /*\r
+ * Set inform for Thread\r
+ */\r
+ List<Object> threadIdList = new ArrayList<Object>();\r
+ List<Object> threadLoadList = new ArrayList<Object>();\r
+ // TODO Remove unnecessary String parsing. first Fix in SystemData.java\r
+ String[] threadLoads = process.getThreadLoad().split(CommonConstants.COMMA);\r
+ for (int iii = 0; iii < threadLoads.length; iii++) {\r
+ String threadLoad = threadLoads[iii];\r
+ if (threadLoad == null || threadLoad.isEmpty()) {\r
+ continue;\r
+ }\r
+ threadIdList.add(new Integer(threadLoad));\r
+ threadLoadList.add(threadLoads[++iii]);\r
+ }\r
+ dbTargetProcessData.add(threadIdList);\r
+ dbTargetProcessData.add(threadLoadList);\r
+\r
+ targetProcessDataList.add(dbTargetProcessData);\r
+ }\r
+ }\r
+ }\r
+ \r
+ systemMemoryDBInserter.pushData(systemDataList);\r
+ processMemoryDBInserter.pushData(targetProcessDataList);\r
+ }\r
+\r
public List<List<Object>> getSystemDataFromDB(long start, long end) {\r
String where = "WHERE SAMPLING_TIME BETWEEN " + start + " AND " + end\r
+ " ORDER BY SAMPLING_TIME";\r
return output;\r
}\r
\r
- public List<Long> getColumnLongFromDB(String tableName, String columnName, String timecolumn, long start, long end) {\r
- List<Long> output = new ArrayList<Long>();\r
- String query;\r
- \r
- if(start == 0 && end == 0) {\r
- query = String.format("SELECT %s FROM %s",\r
- columnName, tableName);\r
- }\r
- else {\r
- query = String.format("SELECT %s FROM %s WHERE %s BETWEEN %s and %s",\r
- columnName, tableName, timecolumn, start, end);\r
- }\r
- \r
- ResultSet rs = SqlConnectionManager.executeQueryRS(query);\r
- if (rs != null) {\r
- try {\r
- while (rs.next()) {\r
- output.add(rs.getLong(1));\r
- }\r
- } catch (SQLException e) {\r
- Logger.exception(e);\r
- } finally {\r
- SqlConnectionManager.releaseResultSet(rs);\r
- }\r
- }\r
- \r
- return output;\r
+ public List<Long> getColumnLongFromDB(String tableName, String columnName, String timecolumn, long start, long end) { \r
+ return getColumnLongFromDB(tableName, columnName, timecolumn, 0, start, end);\r
}\r
\r
- public List<Long> getColumnLongFromDB(String tableName, String columnName, String timecolumn, \r
- int targetID, long start, long end) {\r
+ public List<Long> getColumnLongFromDB(String tableName, String columnName, String timecolumn, int targetID, long start, long end) {\r
List<Long> output = new ArrayList<Long>();\r
String query;\r
\r
if(start == 0 && end == 0) {\r
- query = String.format("SELECT %s FROM %s WHERE PID = %s",\r
- columnName, tableName, targetID);\r
+ query = String.format("SELECT %s FROM %s", columnName, tableName);\r
+ \r
+ if(targetID != 0) {\r
+ query += " WHERE PID = " + targetID;\r
+ }\r
}\r
else {\r
- query = String.format("SELECT %s FROM %s WHERE %s BETWEEN %s and %s AND PID = %s",\r
+ query = String.format("SELECT %s FROM %s WHERE %s BETWEEN %s AND %s",\r
columnName, tableName, timecolumn, start, end, targetID);\r
+ \r
+ if(targetID != 0) {\r
+ query += " AND PID = " + targetID;\r
+ }\r
}\r
\r
ResultSet rs = SqlConnectionManager.executeQueryRS(query);\r
return processedResult;\r
}\r
\r
- public Map<Integer, List<List<Object>>> getTargetProcessDataMapFromDB(long start, long end,\r
- int targetPID) {\r
+ public Map<Integer, List<List<Object>>> getTargetProcessDataMapFromDB(long start, long end, int targetPID) {\r
Map<Integer, List<List<Object>>> processedResult = new HashMap<Integer, List<List<Object>>>();\r
String where = "WHERE SAMPLING_TIME BETWEEN " + start + " AND " + end;\r
if (targetPID > 0) {\r
return processedResult;\r
}\r
\r
- public long getProcessMemoriesFromDB(long time) {\r
+ public List<Long> getProcessMemoriesFromDB(long time) {\r
+ List<Long> processMemories = new ArrayList<Long>();\r
+ \r
+ String query = "SELECT MEMORY_RESIDENT FROM MEMORY_PROCESS_DATA WHERE SAMPLING_TIME = "\r
+ + "(SELECT MAX(SAMPLING_TIME) FROM MEMORY_PROCESS_DATA WHERE SAMPLING_TIME <= "\r
+ + time + ")";\r
+ \r
+ ResultSet rs = SqlConnectionManager.executeQueryRS(query);\r
+ if (rs != null) {\r
+ try {\r
+ while (rs.next()) {\r
+ processMemories.add(rs.getLong(1));\r
+ }\r
+ } catch (SQLException e) {\r
+ Logger.exception(e);\r
+ } finally {\r
+ SqlConnectionManager.releaseResultSet(rs);\r
+ }\r
+ }\r
+ return processMemories;\r
+ }\r
+ \r
+ public long getSystemMemoriesFromDB(long time) {\r
long processMemories = 0;\r
String query = "SELECT MEMORY_RESIDENT FROM MEMORY_PROCESS_DATA WHERE SAMPLING_TIME = "\r
+ "(SELECT MAX(SAMPLING_TIME) FROM MEMORY_PROCESS_DATA WHERE SAMPLING_TIME <= "\r
\r
return allocData;\r
}\r
-\r
- private void GetAllocationData(List<LogData> memoryLogList) {\r
- int size = memoryLogList.size();\r
- for (int i = 0; i < size; i++) {\r
- MemoryData logData = (MemoryData) memoryLogList.get(i);\r
- if (allocByteMap.get(logData.getPid()) == null) {\r
- allocByteMap.put(Integer.valueOf(logData.getPid()), new Long(0));\r
- libraryAllocByteMap.put(Integer.valueOf(logData.getPid()), new HashMap<Integer, Long>());\r
- }\r
-\r
- int memApiType = logData.getMemoryApiType();\r
- int internalFlag = logData.getInternalCall();\r
- long errorNo = logData.getErrno();\r
- \r
- /*\r
- * Check library allocation\r
- */\r
- BinaryInfo binaryInfo = null;\r
- Project project = Global.getProject();\r
- ProcessMemoryMap pmap = project.getProcessInformation(logData.getPid()).getProcessMemoryMap(logData.getTime());\r
-\r
- if (pmap != null) {\r
- LibraryObject lib = pmap.getLibraryByAddress(logData.getCallerPcAddr());\r
- if (lib != null && lib != pmap.getMainbinary()) {\r
- binaryInfo = project.getDeviceStatusInfo().getBinaryInfo(lib.getBinaryID());\r
- }\r
- }\r
-\r
- if (errorNo == 0 && MEM_USER == internalFlag) {\r
- if (MEM_API_TYPE_ALLOC == memApiType || MEM_API_TYPE_FREE == memApiType) {\r
- addNewSeriesUserAllocData(memApiType, logData, binaryInfo);\r
- }\r
- }\r
-\r
- /*\r
- * Save allocation and free api call \r
- */\r
- if(MEM_API_TYPE_ALLOC == memApiType) {\r
- makeAllocData(logData);\r
- }\r
- else if(MEM_API_TYPE_FREE == memApiType) {\r
- makeFreeData(logData);\r
- }\r
- }\r
-\r
- }\r
-\r
- private void GetSystemMemoryData(List<LogData> systemLogList) {\r
- ArrayList<List<Object>> systemDataList = new ArrayList<List<Object>>();\r
- ArrayList<List<Object>> targetProcessDataList = new ArrayList<List<Object>>();\r
-\r
- int size = systemLogList.size();\r
- for (int i = 0; i < size; i++) {\r
- SystemData log = (SystemData) systemLogList.get(i);\r
- \r
- /*\r
- * Make information for other process\r
- */\r
- List<Object> pIDList = new ArrayList<Object>();\r
- List<Object> processLoadList = new ArrayList<Object>();\r
- String[] processLoadDatas = log.getOtherProcessLoad().split(CommonConstants.COMMA);\r
- for (int ii = 0; ii < processLoadDatas.length; ii++) {\r
- String processLoad = processLoadDatas[ii];\r
- if (processLoad == null || processLoad.isEmpty()) {\r
- continue;\r
- }\r
- pIDList.add(new Integer(processLoad));\r
- processLoadList.add(processLoadDatas[++ii]);\r
- }\r
-\r
- /*\r
- * Make SystemData Table data\r
- */\r
- ArrayList<Object> dbSystemData = new ArrayList<Object>();\r
- dbSystemData.add(new Long(log.getTime()));\r
- dbSystemData.add(new Long(log.getSystemMemoryUsed()));\r
- dbSystemData.add(pIDList);\r
- dbSystemData.add(processLoadList);\r
- systemDataList.add(dbSystemData);\r
-\r
- /*\r
- * Make target Process Table data\r
- */\r
- ProcessProfileData[] targetProcessList = log.getProcessProfileDataList();\r
- if (targetProcessList != null) {\r
- for (int j = 0; j < targetProcessList.length; j++) {\r
- ProcessProfileData process = targetProcessList[j];\r
-\r
- ArrayList<Object> dbTargetProcessData = new ArrayList<Object>();\r
- dbTargetProcessData.add(new Long(log.getTime()));\r
- dbTargetProcessData.add(new Integer(process.getPid()));\r
- dbTargetProcessData.add(new Float(process.getProcessLoad()));\r
- dbTargetProcessData.add(new Long(process.getVirtualMemory()));\r
- dbTargetProcessData.add(new Long(process.getResidentMemory()));\r
- dbTargetProcessData.add(new Long(process.getSharedMemory()));\r
- dbTargetProcessData.add(new Long(process.getPssMemory()));\r
- dbTargetProcessData.add(new Integer(process.getThreadCount()));\r
- dbTargetProcessData.add(new Long(process.getTotalAllocSize()));\r
-\r
- /*\r
- * Set inform for Heap allocation\r
- */\r
- List<Object> binaryIDList = new ArrayList<Object>();\r
- List<Object> allocByteList = new ArrayList<Object>();\r
- binaryIDList.add(appAllocSeriesID);\r
- if (allocByteMap.get(process.getPid()) == null) {\r
- allocByteList.add(new Long(0));\r
- } else {\r
- allocByteList.add(allocByteMap.get(process.getPid()));\r
- }\r
-\r
- Map<Integer, Long> libraryList = libraryAllocByteMap.get(process.getPid());\r
- if (libraryList == null) {\r
- libraryList = new HashMap<Integer, Long>();\r
- }\r
-\r
- Iterator<Integer> iter = libraryList.keySet().iterator();\r
- while (iter.hasNext()) {\r
- Integer binaryID = iter.next();\r
- binaryIDList.add(binaryID);\r
- allocByteList.add(libraryList.get(binaryID));\r
- }\r
- dbTargetProcessData.add(binaryIDList);\r
- dbTargetProcessData.add(allocByteList);\r
-\r
- /*\r
- * Set inform for Thread\r
- */\r
- List<Object> threadIdList = new ArrayList<Object>();\r
- List<Object> threadLoadList = new ArrayList<Object>();\r
- // TODO Remove unnecessary String parsing. first Fix in SystemData.java\r
- String[] threadLoads = process.getThreadLoad().split(CommonConstants.COMMA);\r
- for (int iii = 0; iii < threadLoads.length; iii++) {\r
- String threadLoad = threadLoads[iii];\r
- if (threadLoad == null || threadLoad.isEmpty()) {\r
- continue;\r
- }\r
- threadIdList.add(new Integer(threadLoad));\r
- threadLoadList.add(threadLoads[++iii]);\r
- }\r
- dbTargetProcessData.add(threadIdList);\r
- dbTargetProcessData.add(threadLoadList);\r
-\r
- targetProcessDataList.add(dbTargetProcessData);\r
- }\r
- }\r
- }\r
- \r
- systemMemoryDBInserter.pushData(systemDataList);\r
- processMemoryDBInserter.pushData(targetProcessDataList);\r
- }\r
}\r