@Test public void readData() throws IOException { reader = (CpuActivityParserImpl)context.getBean(ICpuActivityParser.class); CpuActivity cpuActivity = reader.parseCpuLine("1.413913604E9 56 /sbin/adbd=29 com.android.systemui=9 /system/bin/surfaceflinger=4 system_server=3 top=1", 1.413913604E9); double usage = cpuActivity.getTotalCpuUsage(); assertEquals(56, usage, 0); }
@Override public CpuActivity parseCpuLine(String cpuLine, double pcapTime) { CpuActivity cpuActivity = null; String pattern = "[\\s=]"; String splitLine[] = cpuLine.split(pattern); int numOfElements = splitLine.length; if(numOfElements < (CpuActivity.TOTAL_CPU_INFO_IDX + 1)){ return null; } cpuActivity = new CpuActivity(); double time = Double.parseDouble(splitLine[CpuActivity.TIMESTAMP_IDX]); double timeStamp = Util.normalizeTime(time, pcapTime); double cpuUsageTotal = Double.parseDouble(splitLine[CpuActivity.TOTAL_CPU_INFO_IDX]); double cpuUsageTotalFiltered = cpuUsageTotal; cpuActivity.setTimestamp(timeStamp); cpuActivity.setTotalCpuUsage(cpuUsageTotal); cpuActivity.setCpuUsageTotalFiltered(cpuUsageTotalFiltered); if( (numOfElements >= (CpuActivity.PROCESS_INFO_IDX + 1)) && (((numOfElements - CpuActivity.PROCESS_INFO_IDX) % 2) == 0)) { List<String> processNameList = new ArrayList<String>(); List<Double> cpuProcessUsageList = new ArrayList<Double>(); String procName; String cpuUsage; for (int i = CpuActivity.PROCESS_INFO_IDX; i < splitLine.length; i++) { procName = splitLine[i]; cpuUsage = splitLine[++i]; processNameList.add(procName); cpuProcessUsageList.add(Double.parseDouble(cpuUsage)); } cpuActivity.setProcessNames(processNameList); cpuActivity.setCpuUsages(cpuProcessUsageList); double other = 0.0; for (Double individualCpuUsage : cpuActivity.getCpuUsages()) { other += individualCpuUsage.doubleValue(); } other = cpuUsageTotal - other; cpuActivity.setCpuUsageOther(other); } return cpuActivity; }
CpuActivityParserImpl implements ICpuActivityParser { @Override public CpuActivity parseCpuLine(String cpuLine, double pcapTime) { CpuActivity cpuActivity = null; String pattern = "[\\s=]"; String splitLine[] = cpuLine.split(pattern); int numOfElements = splitLine.length; if(numOfElements < (CpuActivity.TOTAL_CPU_INFO_IDX + 1)){ return null; } cpuActivity = new CpuActivity(); double time = Double.parseDouble(splitLine[CpuActivity.TIMESTAMP_IDX]); double timeStamp = Util.normalizeTime(time, pcapTime); double cpuUsageTotal = Double.parseDouble(splitLine[CpuActivity.TOTAL_CPU_INFO_IDX]); double cpuUsageTotalFiltered = cpuUsageTotal; cpuActivity.setTimestamp(timeStamp); cpuActivity.setTotalCpuUsage(cpuUsageTotal); cpuActivity.setCpuUsageTotalFiltered(cpuUsageTotalFiltered); if( (numOfElements >= (CpuActivity.PROCESS_INFO_IDX + 1)) && (((numOfElements - CpuActivity.PROCESS_INFO_IDX) % 2) == 0)) { List<String> processNameList = new ArrayList<String>(); List<Double> cpuProcessUsageList = new ArrayList<Double>(); String procName; String cpuUsage; for (int i = CpuActivity.PROCESS_INFO_IDX; i < splitLine.length; i++) { procName = splitLine[i]; cpuUsage = splitLine[++i]; processNameList.add(procName); cpuProcessUsageList.add(Double.parseDouble(cpuUsage)); } cpuActivity.setProcessNames(processNameList); cpuActivity.setCpuUsages(cpuProcessUsageList); double other = 0.0; for (Double individualCpuUsage : cpuActivity.getCpuUsages()) { other += individualCpuUsage.doubleValue(); } other = cpuUsageTotal - other; cpuActivity.setCpuUsageOther(other); } return cpuActivity; } }
CpuActivityParserImpl implements ICpuActivityParser { @Override public CpuActivity parseCpuLine(String cpuLine, double pcapTime) { CpuActivity cpuActivity = null; String pattern = "[\\s=]"; String splitLine[] = cpuLine.split(pattern); int numOfElements = splitLine.length; if(numOfElements < (CpuActivity.TOTAL_CPU_INFO_IDX + 1)){ return null; } cpuActivity = new CpuActivity(); double time = Double.parseDouble(splitLine[CpuActivity.TIMESTAMP_IDX]); double timeStamp = Util.normalizeTime(time, pcapTime); double cpuUsageTotal = Double.parseDouble(splitLine[CpuActivity.TOTAL_CPU_INFO_IDX]); double cpuUsageTotalFiltered = cpuUsageTotal; cpuActivity.setTimestamp(timeStamp); cpuActivity.setTotalCpuUsage(cpuUsageTotal); cpuActivity.setCpuUsageTotalFiltered(cpuUsageTotalFiltered); if( (numOfElements >= (CpuActivity.PROCESS_INFO_IDX + 1)) && (((numOfElements - CpuActivity.PROCESS_INFO_IDX) % 2) == 0)) { List<String> processNameList = new ArrayList<String>(); List<Double> cpuProcessUsageList = new ArrayList<Double>(); String procName; String cpuUsage; for (int i = CpuActivity.PROCESS_INFO_IDX; i < splitLine.length; i++) { procName = splitLine[i]; cpuUsage = splitLine[++i]; processNameList.add(procName); cpuProcessUsageList.add(Double.parseDouble(cpuUsage)); } cpuActivity.setProcessNames(processNameList); cpuActivity.setCpuUsages(cpuProcessUsageList); double other = 0.0; for (Double individualCpuUsage : cpuActivity.getCpuUsages()) { other += individualCpuUsage.doubleValue(); } other = cpuUsageTotal - other; cpuActivity.setCpuUsageOther(other); } return cpuActivity; }  }
CpuActivityParserImpl implements ICpuActivityParser { @Override public CpuActivity parseCpuLine(String cpuLine, double pcapTime) { CpuActivity cpuActivity = null; String pattern = "[\\s=]"; String splitLine[] = cpuLine.split(pattern); int numOfElements = splitLine.length; if(numOfElements < (CpuActivity.TOTAL_CPU_INFO_IDX + 1)){ return null; } cpuActivity = new CpuActivity(); double time = Double.parseDouble(splitLine[CpuActivity.TIMESTAMP_IDX]); double timeStamp = Util.normalizeTime(time, pcapTime); double cpuUsageTotal = Double.parseDouble(splitLine[CpuActivity.TOTAL_CPU_INFO_IDX]); double cpuUsageTotalFiltered = cpuUsageTotal; cpuActivity.setTimestamp(timeStamp); cpuActivity.setTotalCpuUsage(cpuUsageTotal); cpuActivity.setCpuUsageTotalFiltered(cpuUsageTotalFiltered); if( (numOfElements >= (CpuActivity.PROCESS_INFO_IDX + 1)) && (((numOfElements - CpuActivity.PROCESS_INFO_IDX) % 2) == 0)) { List<String> processNameList = new ArrayList<String>(); List<Double> cpuProcessUsageList = new ArrayList<Double>(); String procName; String cpuUsage; for (int i = CpuActivity.PROCESS_INFO_IDX; i < splitLine.length; i++) { procName = splitLine[i]; cpuUsage = splitLine[++i]; processNameList.add(procName); cpuProcessUsageList.add(Double.parseDouble(cpuUsage)); } cpuActivity.setProcessNames(processNameList); cpuActivity.setCpuUsages(cpuProcessUsageList); double other = 0.0; for (Double individualCpuUsage : cpuActivity.getCpuUsages()) { other += individualCpuUsage.doubleValue(); } other = cpuUsageTotal - other; cpuActivity.setCpuUsageOther(other); } return cpuActivity; }  @Override CpuActivity parseCpuLine(String cpuLine, double pcapTime); }
CpuActivityParserImpl implements ICpuActivityParser { @Override public CpuActivity parseCpuLine(String cpuLine, double pcapTime) { CpuActivity cpuActivity = null; String pattern = "[\\s=]"; String splitLine[] = cpuLine.split(pattern); int numOfElements = splitLine.length; if(numOfElements < (CpuActivity.TOTAL_CPU_INFO_IDX + 1)){ return null; } cpuActivity = new CpuActivity(); double time = Double.parseDouble(splitLine[CpuActivity.TIMESTAMP_IDX]); double timeStamp = Util.normalizeTime(time, pcapTime); double cpuUsageTotal = Double.parseDouble(splitLine[CpuActivity.TOTAL_CPU_INFO_IDX]); double cpuUsageTotalFiltered = cpuUsageTotal; cpuActivity.setTimestamp(timeStamp); cpuActivity.setTotalCpuUsage(cpuUsageTotal); cpuActivity.setCpuUsageTotalFiltered(cpuUsageTotalFiltered); if( (numOfElements >= (CpuActivity.PROCESS_INFO_IDX + 1)) && (((numOfElements - CpuActivity.PROCESS_INFO_IDX) % 2) == 0)) { List<String> processNameList = new ArrayList<String>(); List<Double> cpuProcessUsageList = new ArrayList<Double>(); String procName; String cpuUsage; for (int i = CpuActivity.PROCESS_INFO_IDX; i < splitLine.length; i++) { procName = splitLine[i]; cpuUsage = splitLine[++i]; processNameList.add(procName); cpuProcessUsageList.add(Double.parseDouble(cpuUsage)); } cpuActivity.setProcessNames(processNameList); cpuActivity.setCpuUsages(cpuProcessUsageList); double other = 0.0; for (Double individualCpuUsage : cpuActivity.getCpuUsages()) { other += individualCpuUsage.doubleValue(); } other = cpuUsageTotal - other; cpuActivity.setCpuUsageOther(other); } return cpuActivity; }  @Override CpuActivity parseCpuLine(String cpuLine, double pcapTime);  }