Search in sources :

Example 1 with AlarmAnalysisResult

use of com.att.aro.core.peripheral.pojo.AlarmAnalysisResult in project VideoOptimzer by attdevsupport.

the class AlarmAnalysisInfoParserImpl method parse.

@Override
public AlarmAnalysisResult parse(String directory, String fileName, String osVersion, double dumpsysEpochTimestamp, double dumpsysElapsedTimestamp, Date traceDateTime) {
    AlarmAnalysisResult result = new AlarmAnalysisResult();
    String filepath = directory + Util.FILE_SEPARATOR + fileName;
    Map<String, List<ScheduledAlarmInfo>> scheduledAlarms = new HashMap<String, List<ScheduledAlarmInfo>>();
    List<AlarmAnalysisInfo> statistics = new ArrayList<AlarmAnalysisInfo>();
    result.setStatistics(statistics);
    result.setScheduledAlarms(scheduledAlarms);
    boolean alarmStats = false;
    Pattern patternAlarms = Pattern.compile("\\s+(\\d+)\\salarms:.+");
    Pattern patternRunning = Pattern.compile("\\s+(\\d+)ms.+,\\s(\\d+)\\swakeups");
    Pattern patternAlarmRepeat = Pattern.compile("\\s+type=(\\d+)\\swhen=\\+?(\\w+)\\srepeatInterval=(\\d+)\\scount=(\\d+)\\s*");
    String applicationName = "";
    int totalScheduledAlarms = 0;
    String strLineBuf;
    String[] lines = null;
    try {
        lines = filereader.readAllLine(filepath);
    } catch (IOException e) {
        LOGGER.error("failed to read Alarm info file: " + filepath);
    }
    if (lines != null) {
        for (int lineCursor = 0; lineCursor < lines.length; lineCursor++) {
            strLineBuf = lines[lineCursor];
            // Parsing Scheduled Alarm
            if (fileName.equals(TraceDataConst.FileName.ALARM_END_FILE) && !alarmStats) {
                String[] scheduledAlarmLine = strLineBuf.trim().split(" ");
                AlarmType alarmType = null;
                if (scheduledAlarmLine[0].equals("RTC_WAKEUP")) {
                    alarmType = AlarmType.RTC_WAKEUP;
                } else if (scheduledAlarmLine[0].equals("RTC")) {
                    alarmType = AlarmType.RTC;
                } else if (scheduledAlarmLine[0].equals("ELAPSED_WAKEUP")) {
                    alarmType = AlarmType.ELAPSED_REALTIME_WAKEUP;
                } else if (scheduledAlarmLine[0].equals("ELAPSED")) {
                    alarmType = AlarmType.ELAPSED_REALTIME;
                }
                if (alarmType != null) {
                    totalScheduledAlarms++;
                    String temp = scheduledAlarmLine[scheduledAlarmLine.length - 1];
                    String appName = temp.substring(0, temp.length() - 1);
                    String nextLine = lines[++lineCursor];
                    Matcher alarmMatcher = patternAlarmRepeat.matcher(nextLine);
                    if (alarmMatcher.matches()) {
                        /* timestamp in milliseconds */
                        double whenNextEpoch = 0;
                        double whenNextTrace = 0;
                        double whenNextElapsed = 0;
                        /**
                         * pre-gingerbread devices use epoch timestamp /
                         * elapsed timestamp instead of a readable format.
                         */
                        if (osVersion != null && osVersion.compareTo("2.3") < 0) {
                            if (alarmType == AlarmType.RTC_WAKEUP || alarmType == AlarmType.RTC) {
                                whenNextEpoch = Double.parseDouble(alarmMatcher.group(2));
                                whenNextElapsed = whenNextEpoch - dumpsysEpochTimestamp + dumpsysElapsedTimestamp;
                            } else {
                                whenNextElapsed = Double.parseDouble(alarmMatcher.group(2));
                                whenNextEpoch = whenNextElapsed - dumpsysElapsedTimestamp + dumpsysEpochTimestamp;
                            }
                        } else {
                            double remainingTimeForNextAlarm = Util.convertTime(alarmMatcher.group(2));
                            whenNextEpoch = remainingTimeForNextAlarm + dumpsysEpochTimestamp;
                            whenNextElapsed = remainingTimeForNextAlarm + dumpsysElapsedTimestamp;
                        }
                        whenNextTrace = whenNextEpoch - traceDateTime.getTime();
                        // round to 3 decimal places.
                        whenNextElapsed = (double) Math.round(whenNextElapsed * 1000) / 1000;
                        double repeatInterval = Double.parseDouble(alarmMatcher.group(3));
                        double count = Double.parseDouble(alarmMatcher.group(4));
                        List<ScheduledAlarmInfo> adding;
                        if (scheduledAlarms.containsKey(appName)) {
                            adding = scheduledAlarms.get(appName);
                        } else {
                            adding = new ArrayList<ScheduledAlarmInfo>();
                        }
                        adding.add(new ScheduledAlarmInfo(appName, whenNextTrace, whenNextEpoch, whenNextElapsed, alarmType, repeatInterval, count));
                        scheduledAlarms.put(appName, adding);
                        if (LOGGER != null) {
                            LOGGER.debug("alarmAnalysisInfoParser \n" + appName + "\nElapsed: " + whenNextElapsed + "\nEpoch: " + whenNextEpoch + "\nFrom trace start: " + whenNextTrace);
                        }
                    } else {
                        LOGGER.debug("Application Name Not Found: " + appName);
                    }
                    ++lineCursor;
                }
            }
            // Locate expired alarms
            if (alarmStats) {
                String running = "";
                if (applicationName != null && !applicationName.trim().equals("")) {
                    running = strLineBuf;
                } else {
                    applicationName = strLineBuf;
                    running = lines[++lineCursor];
                }
                Matcher run = patternRunning.matcher(running);
                double runningTime = 0;
                double wakeups = 0;
                if (run.matches()) {
                    LOGGER.info("RUNNING: " + run.group(1) + " wakeups: " + run.group(2));
                    runningTime = Double.parseDouble(run.group(1));
                    wakeups = Double.parseDouble(run.group(2));
                }
                LOGGER.info("APPLICATION: " + applicationName + " running " + running + "ms");
                // Gathering alarm intents of an application
                List<String> intents = new ArrayList<String>();
                double totalAlarmFiredofThatApplication = 0;
                // Alarm may not have any fired intent
                ++lineCursor;
                String alarms = null;
                if (lineCursor < lines.length) {
                    alarms = lines[lineCursor];
                    if (alarms != null) {
                        Matcher alarmsFired = patternAlarms.matcher(alarms);
                        while (alarms != null && ++lineCursor < lines.length && alarmsFired.matches()) {
                            totalAlarmFiredofThatApplication += Double.parseDouble(alarmsFired.group(1));
                            intents.add(alarms.trim());
                            alarms = lines[lineCursor];
                            if (alarms != null) {
                                alarmsFired = patternAlarms.matcher(alarms);
                            }
                        }
                    }
                }
                // Adding AlarmAnalysisInfo to the return list
                statistics.add(new AlarmAnalysisInfo(applicationName, runningTime, wakeups, totalAlarmFiredofThatApplication, intents));
                // Cache the name of next application which has been read
                if (alarms != null) {
                    applicationName = alarms;
                }
            }
            if (!alarmStats && strLineBuf.indexOf("Alarm Stats:") > 0) {
                LOGGER.info("Alarm Stats Found" + strLineBuf);
                alarmStats = true;
            }
        }
        LOGGER.info("Number of scheduled alarm = " + totalScheduledAlarms + "\n Number of apps has scheduled alarms: " + scheduledAlarms.size());
    }
    return result;
}
Also used : Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) AlarmType(com.att.aro.core.peripheral.pojo.AlarmInfo.AlarmType) ArrayList(java.util.ArrayList) AlarmAnalysisResult(com.att.aro.core.peripheral.pojo.AlarmAnalysisResult) ScheduledAlarmInfo(com.att.aro.core.packetanalysis.pojo.ScheduledAlarmInfo) IOException(java.io.IOException) AlarmAnalysisInfo(com.att.aro.core.peripheral.pojo.AlarmAnalysisInfo) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with AlarmAnalysisResult

use of com.att.aro.core.peripheral.pojo.AlarmAnalysisResult in project VideoOptimzer by attdevsupport.

the class TraceDataReaderImpl method readAlarmAnalysisInfo.

/**
 * Create List<AlarmStatisticsInfos> of alarms triggered during the trace.
 */
private void readAlarmAnalysisInfo(TraceDirectoryResult res) throws IOException {
    String filepath = res.getTraceDirectory() + Util.FILE_SEPARATOR + TraceDataConst.FileName.ALARM_END_FILE;
    // Collect triggered alarms summary at end of capture
    if (!filereader.fileExist(filepath)) {
        return;
    }
    filepath = res.getTraceDirectory() + Util.FILE_SEPARATOR + TraceDataConst.FileName.ALARM_START_FILE;
    if (!filereader.fileExist(filepath)) {
        return;
    }
    AlarmAnalysisResult result = alarmanalysisinfoparser.parse(res.getTraceDirectory(), TraceDataConst.FileName.ALARM_END_FILE, res.getOsVersion(), res.getDumpsysEpochTimestamp(), res.getDumpsysElapsedTimestamp(), res.getTraceDateTime());
    // String[]
    if (result != null) {
        List<AlarmAnalysisInfo> alarmStatisticsInfosEnd = result.getStatistics();
        res.getScheduledAlarms().putAll(result.getScheduledAlarms());
        // Collect triggered alarms summary at start of capture
        AlarmAnalysisResult result2 = alarmanalysisinfoparser.parse(res.getTraceDirectory(), TraceDataConst.FileName.ALARM_START_FILE, res.getOsVersion(), res.getDumpsysEpochTimestamp(), res.getDumpsysElapsedTimestamp(), res.getTraceDateTime());
        List<AlarmAnalysisInfo> alarmStatisticsInfosStart = result2.getStatistics();
        res.getScheduledAlarms().putAll(result2.getScheduledAlarms());
        // Differentiate the triggered alarms between start/end of catpure.
        if (alarmStatisticsInfosEnd != null && alarmStatisticsInfosStart != null) {
            List<AlarmAnalysisInfo> alarmStatisticsInfos = alarmanalysisinfoparser.compareAlarmAnalysis(alarmStatisticsInfosEnd, alarmStatisticsInfosStart);
            res.setAlarmStatisticsInfos(alarmStatisticsInfos);
        }
    }
}
Also used : AlarmAnalysisInfo(com.att.aro.core.peripheral.pojo.AlarmAnalysisInfo) AlarmAnalysisResult(com.att.aro.core.peripheral.pojo.AlarmAnalysisResult)

Example 3 with AlarmAnalysisResult

use of com.att.aro.core.peripheral.pojo.AlarmAnalysisResult in project VideoOptimzer by attdevsupport.

the class AlarmAnalysisInfoParserImplTest method readData.

@SuppressWarnings("deprecation")
@Test
public void readData() throws IOException {
    parser = (AlarmAnalysisInfoParserImpl) context.getBean(IAlarmAnalysisInfoParser.class);
    IFileManager filereader = Mockito.mock(IFileManager.class);
    String[] arr = getData();
    Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(arr);
    parser.setFileReader(filereader);
    Date date = new Date(2014, 01, 06, 12, 0, 26);
    AlarmAnalysisResult result = null;
    boolean hasdata = false;
    Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true);
    result = parser.parse("/", "alarm_info_end", "2.3", 3015093, 3064068, date);
    hasdata = result.getStatistics().size() > 0;
    assertTrue(hasdata);
    String[] startarr = getDataStart();
    Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(startarr);
    date = new Date(2014, 01, 06, 12, 0, 29);
    AlarmAnalysisResult result2 = parser.parse("/", "alarm_info_start", "2.3", 3047197, 3064068, date);
    List<AlarmAnalysisInfo> alarmStatisticsInfosEnd = result.getStatistics();
    List<AlarmAnalysisInfo> alarmStatisticsInfosStart = result2.getStatistics();
    List<AlarmAnalysisInfo> alarmlist = parser.compareAlarmAnalysis(alarmStatisticsInfosEnd, alarmStatisticsInfosStart);
    hasdata = alarmlist.size() > 0;
    assertTrue(hasdata);
}
Also used : AlarmAnalysisInfo(com.att.aro.core.peripheral.pojo.AlarmAnalysisInfo) AlarmAnalysisResult(com.att.aro.core.peripheral.pojo.AlarmAnalysisResult) Date(java.util.Date) IFileManager(com.att.aro.core.fileio.IFileManager) Test(org.junit.Test) BaseTest(com.att.aro.core.BaseTest)

Example 4 with AlarmAnalysisResult

use of com.att.aro.core.peripheral.pojo.AlarmAnalysisResult in project VideoOptimzer by attdevsupport.

the class AlarmAnalysisInfoParserImplTest method readData_Test2.

@Test
public void readData_Test2() throws IOException {
    parser = (AlarmAnalysisInfoParserImpl) context.getBean(IAlarmAnalysisInfoParser.class);
    IFileManager filereader = Mockito.mock(IFileManager.class);
    String[] startarr2 = getDataStart2();
    Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(startarr2);
    parser.setFileReader(filereader);
    @SuppressWarnings("deprecation") Date date = new Date(2014, 01, 06, 12, 0, 30);
    AlarmAnalysisResult result4 = null;
    boolean hasdata = false;
    Mockito.when(filereader.fileExist(Mockito.anyString())).thenReturn(true);
    result4 = parser.parse("/", "alarm_info_end", "3.0", 3015093, 3064068, date);
    String[] startarr3 = getDataStart3();
    Mockito.when(filereader.readAllLine(Mockito.anyString())).thenReturn(startarr3);
    AlarmAnalysisResult result3 = parser.parse("/", "alarm_info_start", "3.0", 3047197, 3064068, date);
    List<AlarmAnalysisInfo> alarmStatisticsInfosStart1 = result4.getStatistics();
    List<AlarmAnalysisInfo> alarmStatisticsInfosEnd1 = result3.getStatistics();
    List<AlarmAnalysisInfo> alarmlist1 = parser.compareAlarmAnalysis(alarmStatisticsInfosEnd1, alarmStatisticsInfosStart1);
    hasdata = alarmlist1.size() > 0;
    assertTrue(hasdata);
}
Also used : AlarmAnalysisInfo(com.att.aro.core.peripheral.pojo.AlarmAnalysisInfo) AlarmAnalysisResult(com.att.aro.core.peripheral.pojo.AlarmAnalysisResult) Date(java.util.Date) IFileManager(com.att.aro.core.fileio.IFileManager) Test(org.junit.Test) BaseTest(com.att.aro.core.BaseTest)

Example 5 with AlarmAnalysisResult

use of com.att.aro.core.peripheral.pojo.AlarmAnalysisResult in project VideoOptimzer by attdevsupport.

the class TraceDataReaderImplTest method readTraceDir_.

@Test
public void readTraceDir_() throws IOException {
    String[] time = { "1410212153 1410213352", "272927100", "1410213352.550" };
    String[] appId = { "5", "5", "13", "-127" };
    traceDataReaderImpl.setFileReader(filereader);
    when(filereader.directoryExist(any(String.class))).thenReturn(true);
    when(filereader.fileExist(any(String.class))).thenReturn(true);
    when(filereader.readAllLine(any(String.class))).thenReturn(time);
    when(filereader.readAllLine(Util.getCurrentRunningDir() + Util.FILE_SEPARATOR + "appid")).thenReturn(appId);
    when(filereader.fileExist(Util.getCurrentRunningDir() + Util.FILE_SEPARATOR + "traffic1.cap")).thenReturn(false);
    Map<String, List<ScheduledAlarmInfo>> scheduledAlarms = new HashMap<String, List<ScheduledAlarmInfo>>();
    List<AlarmAnalysisInfo> statistics = new ArrayList<AlarmAnalysisInfo>();
    AlarmAnalysisResult alarmResult = mock(AlarmAnalysisResult.class);
    when(alarmResult.getScheduledAlarms()).thenReturn(scheduledAlarms);
    when(alarmResult.getStatistics()).thenReturn(statistics);
    when(alarmanalysisinfoparser.parse(any(String.class), any(String.class), any(String.class), any(double.class), any(double.class), any(Date.class))).thenReturn(alarmResult);
    // Crypto
    traceDataReaderImpl.setCrypto(crypto);
    when(crypto.readSSLKeys(any(String.class))).thenReturn(1);
    Mockito.doAnswer(new Answer<Object>() {

        public Object answer(InvocationOnMock invocation) {
            byte b = 3;
            short s = 1;
            InetAddress address1 = null;
            InetAddress address2 = null;
            try {
                address2 = InetAddress.getByName("78.46.84.177");
                address1 = InetAddress.getByName("78.46.84.171");
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
            Date date1 = new Date();
            IPPacket ippack01 = mock(IPPacket.class);
            when(ippack01.getIPVersion()).thenReturn(b);
            when(ippack01.getFragmentOffset()).thenReturn(s);
            when(ippack01.getSourceIPAddress()).thenReturn(address1);
            when(ippack01.getDestinationIPAddress()).thenReturn(address2);
            when(ippack01.getTimeStamp()).thenReturn((double) date1.getTime());
            // pretend jpcap lib
            traceDataReaderImpl.packetArrived("com.google.android.youtube", ippack01);
            return null;
        }
    }).when(packetreader).readPacket(any(String.class), any(IPacketListener.class));
    AppInfo app = new AppInfo();
    Map<String, String> appMap = new HashMap<String, String>();
    appMap.put("flipboard.app", "2.3.8");
    appMap.put("com.att.android.arodatacollector", "3.1.1.6");
    appMap.put("com.google.android.youtube", "4.0.23");
    app.setAppVersionMap(appMap);
    List<String> appInfos = new ArrayList<String>();
    appInfos.add("flipboard.app");
    appInfos.add("com.att.android.arodatacollector");
    appInfos.add("com.google.android.youtube");
    app.setAppInfos(appInfos);
    when(appinforeader.readData(any(String.class))).thenReturn(app);
    DeviceDetail device = new DeviceDetail();
    device.setTotalLines(8);
    device.setScreenSize("720*1280");
    when(devicedetailreader.readData(any(String.class))).thenReturn(device);
    CollectOptions cOptions = new CollectOptions();
    when(collectOptionsReader.readData(any(String.class))).thenReturn(cOptions);
    NetworkTypeObject obj = new NetworkTypeObject();
    when(networktypereader.readData(any(String.class), any(double.class), any(double.class))).thenReturn(obj);
    TraceDirectoryResult result = traceDataReaderImpl.readTraceDirectory(Util.getCurrentRunningDir());
    assertSame(3, result.getAppIds().size());
}
Also used : NetworkTypeObject(com.att.aro.core.peripheral.pojo.NetworkTypeObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) AlarmAnalysisResult(com.att.aro.core.peripheral.pojo.AlarmAnalysisResult) AlarmAnalysisInfo(com.att.aro.core.peripheral.pojo.AlarmAnalysisInfo) TraceDirectoryResult(com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult) ArrayList(java.util.ArrayList) List(java.util.List) UnknownHostException(java.net.UnknownHostException) IPacketListener(com.att.aro.core.packetreader.IPacketListener) DeviceDetail(com.att.aro.core.peripheral.pojo.DeviceDetail) ScheduledAlarmInfo(com.att.aro.core.packetanalysis.pojo.ScheduledAlarmInfo) Date(java.util.Date) AppInfo(com.att.aro.core.peripheral.pojo.AppInfo) CollectOptions(com.att.aro.core.peripheral.pojo.CollectOptions) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NetworkTypeObject(com.att.aro.core.peripheral.pojo.NetworkTypeObject) InetAddress(java.net.InetAddress) IPPacket(com.att.aro.core.packetreader.pojo.IPPacket) BaseTest(com.att.aro.core.BaseTest) Test(org.junit.Test)

Aggregations

AlarmAnalysisInfo (com.att.aro.core.peripheral.pojo.AlarmAnalysisInfo)6 AlarmAnalysisResult (com.att.aro.core.peripheral.pojo.AlarmAnalysisResult)6 BaseTest (com.att.aro.core.BaseTest)4 Date (java.util.Date)4 Test (org.junit.Test)4 ScheduledAlarmInfo (com.att.aro.core.packetanalysis.pojo.ScheduledAlarmInfo)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 IFileManager (com.att.aro.core.fileio.IFileManager)2 TraceDirectoryResult (com.att.aro.core.packetanalysis.pojo.TraceDirectoryResult)2 IPacketListener (com.att.aro.core.packetreader.IPacketListener)2 IPPacket (com.att.aro.core.packetreader.pojo.IPPacket)2 AppInfo (com.att.aro.core.peripheral.pojo.AppInfo)2 DeviceDetail (com.att.aro.core.peripheral.pojo.DeviceDetail)2 NetworkTypeObject (com.att.aro.core.peripheral.pojo.NetworkTypeObject)2 InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 AlarmType (com.att.aro.core.peripheral.pojo.AlarmInfo.AlarmType)1