Search in sources :

Example 1 with WakelockInfo

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;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) WakelockState(com.att.aro.core.peripheral.pojo.WakelockInfo.WakelockState) IOException(java.io.IOException) WakelockInfo(com.att.aro.core.peripheral.pojo.WakelockInfo)

Example 2 with WakelockInfo

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);
}
Also used : IOException(java.io.IOException) Date(java.util.Date) WakelockInfo(com.att.aro.core.peripheral.pojo.WakelockInfo) Test(org.junit.Test) BaseTest(com.att.aro.core.BaseTest)

Example 3 with WakelockInfo

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;
}
Also used : TraceResultType(com.att.aro.core.packetanalysis.pojo.TraceResultType) XYIntervalSeriesCollection(org.jfree.data.xy.XYIntervalSeriesCollection) XYIntervalSeries(org.jfree.data.xy.XYIntervalSeries) TraceDirectoryResult(com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult) XYDataset(org.jfree.data.xy.XYDataset) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) XYToolTipGenerator(org.jfree.chart.labels.XYToolTipGenerator) WakelockInfo(com.att.aro.core.peripheral.pojo.WakelockInfo)

Example 4 with WakelockInfo

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);
}
Also used : Date(java.util.Date) WakelockInfo(com.att.aro.core.peripheral.pojo.WakelockInfo) Test(org.junit.Test) BaseTest(com.att.aro.core.BaseTest)

Aggregations

WakelockInfo (com.att.aro.core.peripheral.pojo.WakelockInfo)4 BaseTest (com.att.aro.core.BaseTest)2 IOException (java.io.IOException)2 Date (java.util.Date)2 Test (org.junit.Test)2 TraceDirectoryResult (com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult)1 TraceResultType (com.att.aro.core.packetanalysis.pojo.TraceResultType)1 WakelockState (com.att.aro.core.peripheral.pojo.WakelockInfo.WakelockState)1 ArrayList (java.util.ArrayList)1 XYToolTipGenerator (org.jfree.chart.labels.XYToolTipGenerator)1 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)1 XYDataset (org.jfree.data.xy.XYDataset)1 XYIntervalSeries (org.jfree.data.xy.XYIntervalSeries)1 XYIntervalSeriesCollection (org.jfree.data.xy.XYIntervalSeriesCollection)1