use of com.att.aro.core.peripheral.pojo.AlarmInfo.AlarmType 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;
}
use of com.att.aro.core.peripheral.pojo.AlarmInfo.AlarmType in project VideoOptimzer by attdevsupport.
the class AlarmInfoReaderImpl method readData.
@Override
public List<AlarmInfo> readData(String directory, double dumpsysEpochTimestamp, double dumpsysElapsedTimestamp, Date traceDateTime) {
List<AlarmInfo> alarmInfos = new ArrayList<AlarmInfo>();
String filepath = directory + Util.FILE_SEPARATOR + TraceDataConst.FileName.KERNEL_LOG_FILE;
double timestamp;
double timestampElapsed;
double timestampEpoch;
double timeDeltaEpochElapsed = dumpsysEpochTimestamp - dumpsysElapsedTimestamp;
AlarmType alarmType;
String[] lines = null;
if (!filereader.fileExist(filepath)) {
return alarmInfos;
}
try {
lines = filereader.readAllLine(filepath);
} catch (IOException e1) {
LOGGER.error("failed to read kernal log file for Alarm Info data: " + filepath);
return alarmInfos;
}
for (String strLineBuf : lines) {
if (strLineBuf.indexOf("alarm_timer_triggered") > 0) {
String[] strFields = strLineBuf.split(" ");
if (strFields.length > 1) {
try {
timestamp = 0;
switch(Integer.parseInt(strFields[strFields.length - 3])) {
case 0:
alarmType = AlarmType.RTC_WAKEUP;
break;
case 1:
alarmType = AlarmType.RTC;
break;
case 2:
alarmType = AlarmType.ELAPSED_REALTIME_WAKEUP;
timestamp = timeDeltaEpochElapsed;
break;
case 3:
alarmType = AlarmType.ELAPSED_REALTIME;
timestamp = timeDeltaEpochElapsed;
break;
default:
// should not arrive here
LOGGER.warn("cannot resolve alarm type: " + timestamp + " type " + Double.parseDouble(strFields[strFields.length - 3]));
alarmType = AlarmType.UNKNOWN;
break;
}
// convert ns to milliseconds
timestamp += Double.parseDouble(strFields[strFields.length - 1]) / 1000000;
timestampEpoch = timestamp;
timestamp = timestamp - traceDateTime.getTime();
timestampElapsed = timestampEpoch - dumpsysEpochTimestamp + dumpsysElapsedTimestamp;
alarmInfos.add(new AlarmInfo(timestamp, timestampEpoch, timestampElapsed, alarmType));
// logger.info("Time: " + timestamp
// + "Alarm type: " + alarmType
// + "\nEpoch: " + timestampEpoch
// + "\nElapsed: " + timestampElapsed);
} catch (Exception e) {
LOGGER.warn("Unexpected error parsing alarm event: " + strLineBuf, e);
}
}
}
}
return alarmInfos;
}
use of com.att.aro.core.peripheral.pojo.AlarmInfo.AlarmType in project VideoOptimzer by attdevsupport.
the class AlarmPlot method populate.
@Override
public void populate(XYPlot plot, AROTraceData analysis) {
if (analysis == null) {
LOGGER.info("analysis data is null");
} else {
alarmDataCollection.removeAllSeries();
pointerAnnotation.clear();
TraceResultType resultType = analysis.getAnalyzerResult().getTraceresult().getTraceResultType();
if (resultType.equals(TraceResultType.TRACE_FILE)) {
LOGGER.info("didn't get analysis trace data!");
} else {
// Remove old annotation from previous plots
Iterator<XYPointerAnnotation> pointers = pointerAnnotation.iterator();
while (pointers.hasNext()) {
plot.removeAnnotation(pointers.next());
}
for (AlarmType eventType : AlarmType.values()) {
XYIntervalSeries series = new XYIntervalSeries(eventType);
seriesMap.put(eventType, series);
alarmDataCollection.addSeries(series);
}
TraceDirectoryResult traceresult = (TraceDirectoryResult) analysis.getAnalyzerResult().getTraceresult();
List<AlarmInfo> alarmInfos = traceresult.getAlarmInfos();
List<ScheduledAlarmInfo> pendingAlarms = getHasFiredAlarms(traceresult.getScheduledAlarms());
Iterator<ScheduledAlarmInfo> iterPendingAlarms = pendingAlarms.iterator();
double firedTime = 0;
while (iterPendingAlarms.hasNext()) {
ScheduledAlarmInfo scheduledEvent = iterPendingAlarms.next();
AlarmType pendingAlarmType = scheduledEvent.getAlarmType();
if (pendingAlarmType != null) {
firedTime = (scheduledEvent.getTimeStamp() - scheduledEvent.getRepeatInterval()) / 1000;
seriesMap.get(pendingAlarmType).add(firedTime, firedTime, firedTime, 1, 0.8, 1);
eventMapPending.put(firedTime, scheduledEvent);
// logger.fine("populateAlarmScheduledPlot type:\n" +
// pendingAlarmType
// + "\ntime " + scheduledEvent.getTimeStamp()
// + "\nrepeating " + firedTime);
}
}
Iterator<AlarmInfo> iter = alarmInfos.iterator();
while (iter.hasNext()) {
AlarmInfo currEvent = iter.next();
if (currEvent != null) {
AlarmType alarmType = currEvent.getAlarmType();
if (alarmType != null) {
firedTime = currEvent.getTimeStamp() / 1000;
/*
* Catching any alarms align to quanta as being
* inexactRepeating alarms
*/
if ((currEvent.getTimestampElapsed() / 1000) % 900 < 1) {
seriesMap.get(alarmType).add(firedTime, firedTime, firedTime, 1, 0, 0.7);
// Adding an arrow to mark these
// inexactRepeating alarms
XYPointerAnnotation xypointerannotation = new XYPointerAnnotation(alarmType.name(), firedTime, 0.6, 3.92699082D);
xypointerannotation.setBaseRadius(20D);
xypointerannotation.setTipRadius(1D);
pointerAnnotation.add(xypointerannotation);
plot.addAnnotation(xypointerannotation);
// logger.info("SetInexactRepeating alarm type: "
// + alarmType
// + " time " + firedTime
// + " epoch " + currEvent.getTimestampEpoch()
// + " elapsed:\n" +
// currEvent.getTimestampElapsed()/1000);
} else {
seriesMap.get(alarmType).add(firedTime, firedTime, firedTime, 1, 0, 0.5);
}
eventMap.put(firedTime, currEvent);
}
}
}
XYItemRenderer renderer = plot.getRenderer();
renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.RTC_WAKEUP), Color.red);
renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.RTC), Color.pink);
renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.ELAPSED_REALTIME_WAKEUP), Color.blue);
renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.ELAPSED_REALTIME), Color.cyan);
renderer.setSeriesPaint(alarmDataCollection.indexOf(AlarmType.UNKNOWN), Color.black);
// Assign ToolTip to renderer
renderer.setBaseToolTipGenerator(new XYToolTipGenerator() {
@Override
public String generateToolTip(XYDataset dataset, int series, int item) {
AlarmInfo info = eventMap.get(dataset.getX(series, item));
Date epochTime = new Date();
if (info != null) {
epochTime.setTime((long) info.getTimestampEpoch());
StringBuffer displayInfo = new StringBuffer(ResourceBundleHelper.getMessageString("alarm.tooltip.prefix"));
displayInfo.append(MessageFormat.format(ResourceBundleHelper.getMessageString("alarm.tooltip.content"), info.getAlarmType(), info.getTimeStamp() / 1000, epochTime.toString()));
if ((info.getTimestampElapsed() / 1000) % 900 < 1) {
displayInfo.append(ResourceBundleHelper.getMessageString("alarm.tooltip.setInexactRepeating"));
}
displayInfo.append(ResourceBundleHelper.getMessageString("alarm.tooltip.suffix"));
return displayInfo.toString();
}
ScheduledAlarmInfo infoPending = eventMapPending.get(dataset.getX(series, item));
if (infoPending != null) {
epochTime.setTime((long) (infoPending.getTimestampEpoch() - infoPending.getRepeatInterval()));
StringBuffer displayInfo = new StringBuffer(ResourceBundleHelper.getMessageString("alarm.tooltip.prefix"));
displayInfo.append(MessageFormat.format(ResourceBundleHelper.getMessageString("alarm.tooltip.contentWithName"), infoPending.getAlarmType(), (infoPending.getTimeStamp() - infoPending.getRepeatInterval()) / 1000, epochTime.toString(), infoPending.getApplication(), infoPending.getRepeatInterval() / 1000));
displayInfo.append(ResourceBundleHelper.getMessageString("alarm.tooltip.suffix"));
return displayInfo.toString();
}
return null;
}
});
}
}
plot.setDataset(alarmDataCollection);
// return plot;
}
Aggregations