Search in sources :

Example 1 with AlarmAnalysisInfo

use of com.att.aro.core.peripheral.pojo.AlarmAnalysisInfo 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 AlarmAnalysisInfo

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

the class AlarmAnalysisInfoParserImpl method compareAlarmAnalysis.

/**
 * Comparing Alarm Stats before/after capture
 *
 * @param end
 *            List<AlarmAnalysisInfo> of alarms triggered summary at end of
 *            capture.
 * @param start
 *            List<AlarmAnalysisInfo> of alarms triggered summary at start
 *            of capture.
 *
 *            Return the difference
 */
@Override
public List<AlarmAnalysisInfo> compareAlarmAnalysis(List<AlarmAnalysisInfo> end, List<AlarmAnalysisInfo> start) {
    Iterator<AlarmAnalysisInfo> itrAlarmAnalysisInfoS;
    ListIterator<AlarmAnalysisInfo> itrAlarmAnalysisInfoE;
    Pattern patternAlarms = Pattern.compile("(\\d+)\\salarms:\\s(.+)");
    itrAlarmAnalysisInfoE = end.listIterator();
    /**
     * Go through alarms history in END_FILE and loop through START_FILE to
     * find the matching application
     */
    while (itrAlarmAnalysisInfoE.hasNext()) {
        AlarmAnalysisInfo alarmInfoE = (AlarmAnalysisInfo) itrAlarmAnalysisInfoE.next();
        /**
         * Start iterator from beginning for every new applications as the
         * lists are not in any order
         */
        double totalFired = 0;
        itrAlarmAnalysisInfoS = start.iterator();
        AlarmAnalysisInfo alarmInfoS = (AlarmAnalysisInfo) itrAlarmAnalysisInfoS.next();
        // Application look up in START_FILE
        while (!alarmInfoS.getApplication().equals(alarmInfoE.getApplication()) && itrAlarmAnalysisInfoS.hasNext()) {
            alarmInfoS = (AlarmAnalysisInfo) itrAlarmAnalysisInfoS.next();
        }
        // If no matching application, skip to next
        if (!alarmInfoS.getApplication().equals(alarmInfoE.getApplication())) {
            LOGGER.info("no matching application - " + alarmInfoE.getApplication());
            continue;
        }
        /**
         * Found matching application Note down the difference in Alarm
         * Stats
         */
        double wakeup = alarmInfoE.getWakeup() - alarmInfoS.getWakeup();
        double running = alarmInfoE.getRunning() - alarmInfoS.getRunning();
        LOGGER.debug("running: " + running);
        /**
         * Discard those applications didn't fire any alarms using running
         * time as reference.
         */
        if (running > 0) {
            List<String> intentS = alarmInfoS.getIntent();
            List<String> intentE = alarmInfoE.getIntent();
            Iterator<String> itStringStart;
            ListIterator<String> itStringEnd = intentE.listIterator();
            String stringStart;
            String stringEnd;
            /**
             * Iterate through all alarms under the found application. to
             * compare the applications' intents
             */
            while (itStringEnd.hasNext()) {
                itStringStart = intentS.iterator();
                if (itStringStart.hasNext()) {
                    stringStart = itStringStart.next();
                    stringEnd = itStringEnd.next();
                    Matcher startingMatcher = patternAlarms.matcher(stringStart);
                    Matcher endingMatcher = patternAlarms.matcher(stringEnd);
                    // Search for matching alarms intent from matching application
                    while (startingMatcher.matches() && endingMatcher.matches() && !startingMatcher.group(2).equals(endingMatcher.group(2))) {
                        if (itStringStart.hasNext()) {
                            stringStart = (String) itStringStart.next();
                            startingMatcher = patternAlarms.matcher(stringStart);
                        } else {
                            break;
                        }
                    }
                    // Found matching fired intent, update the statistics here
                    if (startingMatcher.group(2).equals(endingMatcher.group(2))) {
                        double alarms = Double.parseDouble(endingMatcher.group(1)) - Double.parseDouble(startingMatcher.group(1));
                        if (alarms > 0) {
                            totalFired += alarms;
                            itStringEnd.set(alarms + " alarms: " + endingMatcher.group(2));
                        } else {
                            itStringEnd.remove();
                            LOGGER.debug("compareAlarmAnalysis: alarm intent discarded - " + endingMatcher.group(2));
                        }
                    } else {
                        totalFired += Double.parseDouble(endingMatcher.group(1));
                        LOGGER.debug("No matching alarm intent found \n Total fired = " + endingMatcher.group(1) + " " + stringEnd);
                    }
                } else {
                    break;
                }
            }
            // Replacing updated AlarmAnalysisInfo
            AlarmAnalysisInfo replacing = new AlarmAnalysisInfo(alarmInfoE.getApplication(), running, wakeup, totalFired, alarmInfoE.getIntent());
            itrAlarmAnalysisInfoE.set(replacing);
        } else {
            itrAlarmAnalysisInfoE.remove();
            LOGGER.debug("compareAlarmAnalysis: history discarded - " + alarmInfoE.getApplication());
        }
    }
    return end;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) AlarmAnalysisInfo(com.att.aro.core.peripheral.pojo.AlarmAnalysisInfo)

Example 3 with AlarmAnalysisInfo

use of com.att.aro.core.peripheral.pojo.AlarmAnalysisInfo 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 4 with AlarmAnalysisInfo

use of com.att.aro.core.peripheral.pojo.AlarmAnalysisInfo 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 5 with AlarmAnalysisInfo

use of com.att.aro.core.peripheral.pojo.AlarmAnalysisInfo 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)

Aggregations

AlarmAnalysisInfo (com.att.aro.core.peripheral.pojo.AlarmAnalysisInfo)7 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 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2