use of com.att.aro.core.peripheral.pojo.WakelockInfo in project VideoOptimzer by attdevsupport.
the class WakelockInfoReaderImpl method readData.
@Override
public List<WakelockInfo> readData(String directory, String osVersion, double dumpsysEpochTimestamp, Date traceDateTime) {
List<WakelockInfo> wakelockInfos = new ArrayList<WakelockInfo>();
String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.BATTERYINFO_FILE;
String[] lines = null;
if (!filereader.fileExist(filepath)) {
return wakelockInfos;
}
if (osVersion != null && osVersion.compareTo("2.3") < 0) {
LOGGER.info("OS 2.2(Froyo) or earlier does not has the wakelock timeline");
}
try {
lines = filereader.readAllLine(filepath);
} catch (IOException e1) {
LOGGER.error("failed to read Wakelock Info file: " + filepath);
}
if (lines != null && lines.length > 0) {
WakelockState wakelockState;
for (String strLineBuf : lines) {
// Look for +/-wake_lock
int index = strLineBuf.indexOf(TraceDataConst.WAKELOCK_ACQUIRED);
if (index < 0) {
index = strLineBuf.indexOf(TraceDataConst.WAKELOCK_RELEASED);
}
// If either +/-wake_lock found
if (index > 0) {
String actualWakelockstate = strLineBuf.substring(index, index + 10);
String[] strFields = strLineBuf.trim().split(" ");
try {
// Get timestamp of wakelock event
double bTimeStamp = dumpsysEpochTimestamp - Util.convertTime(strFields[0]);
if (bTimeStamp > traceDateTime.getTime()) {
bTimeStamp = (bTimeStamp - traceDateTime.getTime()) / 1000;
if (TraceDataConst.WAKELOCK_RELEASED.equals(actualWakelockstate)) {
wakelockState = WakelockState.WAKELOCK_RELEASED;
} else {
wakelockState = WakelockState.WAKELOCK_ACQUIRED;
}
wakelockInfos.add(new WakelockInfo(bTimeStamp, wakelockState));
LOGGER.info("Trace Start: " + traceDateTime.getTime() + "\nWakelock Time: " + bTimeStamp + " Wakelock state: " + actualWakelockstate + " strFields " + Arrays.toString(strFields));
}
} catch (Exception e) {
LOGGER.warn("Unexpected error parsing wakelock event: " + Arrays.toString(strFields) + " found wakelock in " + index, e);
}
}
}
}
return wakelockInfos;
}
use of com.att.aro.core.peripheral.pojo.WakelockInfo in project VideoOptimzer by attdevsupport.
the class WakelockInfoReaderImplTest method readData_Exception_readAllLine.
@Test
public void readData_Exception_readAllLine() throws IOException {
Date traceDateTime = new Date((long) 1412161675045.0);
double dumpsysEpochTimestamp = (new Date((long) 1.412361724E12)).getTime();
Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true);
Mockito.when(filereader.readAllLine(Mockito.anyString())).thenThrow(new IOException("Exception_readAllLine"));
List<WakelockInfo> wakelockInfos = traceDataReader.readData("", "2.2", dumpsysEpochTimestamp, traceDateTime);
assertTrue(wakelockInfos.size() == 0);
}
use of com.att.aro.core.peripheral.pojo.WakelockInfo in project VideoOptimzer by attdevsupport.
the class WakeLockPlot method populate.
@Override
public void populate(XYPlot plot, AROTraceData analysis) {
XYIntervalSeriesCollection wakelockData = new XYIntervalSeriesCollection();
if (analysis == null) {
LOGGER.info("analysis data is null");
} else {
TraceResultType resultType = analysis.getAnalyzerResult().getTraceresult().getTraceResultType();
if (resultType.equals(TraceResultType.TRACE_FILE)) {
LOGGER.info("didn't get analysis trace data!");
} else {
TraceDirectoryResult traceresult = (TraceDirectoryResult) analysis.getAnalyzerResult().getTraceresult();
XYIntervalSeries series = new XYIntervalSeries(WakelockState.WAKELOCK_ACQUIRED);
wakelockData.addSeries(series);
// Populate the data set
Iterator<WakelockInfo> iter = traceresult.getWakelockInfos().iterator();
if (iter.hasNext()) {
WakelockInfo lastEvent = iter.next();
LOGGER.debug("Wakelock Plotting");
// Check whether WAKELOCK was acquired before logging begins.
if (lastEvent.getWakelockState() == WakelockState.WAKELOCK_RELEASED) {
series.add(0, 0, lastEvent.getBeginTimeStamp(), 0.5, 0, 1);
dataMap.put(lastEvent.getBeginTimeStamp(), lastEvent);
}
while (iter.hasNext()) {
WakelockInfo currEvent = iter.next();
if (lastEvent.getWakelockState() == WakelockState.WAKELOCK_ACQUIRED) {
LOGGER.debug("Wakelock acquired curr " + currEvent.getBeginTimeStamp());
LOGGER.debug("Wakelock acquired last " + lastEvent.getBeginTimeStamp());
series.add(lastEvent.getBeginTimeStamp(), lastEvent.getBeginTimeStamp(), currEvent.getBeginTimeStamp(), 0.5, 0, 1);
dataMap.put(lastEvent.getBeginTimeStamp(), lastEvent);
}
lastEvent = currEvent;
}
if (lastEvent.getWakelockState() == WakelockState.WAKELOCK_ACQUIRED) {
series.add(lastEvent.getBeginTimeStamp(), lastEvent.getBeginTimeStamp(), traceresult.getTraceDuration(), 0.5, 0, 1);
dataMap.put(lastEvent.getBeginTimeStamp(), lastEvent);
}
}
// Assign ToolTip to renderer
XYItemRenderer renderer = plot.getRenderer();
renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
@Override
public String generateToolTip(XYDataset dataset, int series, int item) {
WakelockInfo wi = dataMap.get(dataset.getXValue(series, item));
if (wi != null) {
StringBuffer displayInfo = new StringBuffer(ResourceBundleHelper.getMessageString("wakelock.tooltip.prefix"));
displayInfo.append(MessageFormat.format(ResourceBundleHelper.getMessageString("wakelock.tooltip.content"), ResourceBundleHelper.getEnumString(wi.getWakelockState()), wi.getBeginTimeStamp()));
displayInfo.append(ResourceBundleHelper.getMessageString("wakelock.tooltip.suffix"));
return displayInfo.toString();
}
return null;
}
});
}
}
plot.setDataset(wakelockData);
// return plot;
}
use of com.att.aro.core.peripheral.pojo.WakelockInfo in project VideoOptimzer by attdevsupport.
the class WakelockInfoReaderImplTest method readData.
@Test
public void readData() throws IOException {
Date traceDateTime = new Date((long) 1412161675045.0);
double dumpsysEpochTimestamp = (new Date((long) 1.412361724E12)).getTime();
List<WakelockInfo> wakelockInfos = null;
String filepath = "" + Util.FILE_SEPARATOR + TraceDataConst.FileName.BATTERYINFO_FILE;
Mockito.when(filereader.fileExist(filepath)).thenReturn(true);
Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(getMockedFileData());
traceDataReader.setFileReader(filereader);
wakelockInfos = traceDataReader.readData("", "2.2", dumpsysEpochTimestamp, traceDateTime);
wakelockInfos = traceDataReader.readData("", "4.2", dumpsysEpochTimestamp, traceDateTime);
assertEquals(7, wakelockInfos.size(), 0);
}
Aggregations