use of com.att.aro.core.packetanalysis.pojo.ScheduledAlarmInfo 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.packetanalysis.pojo.ScheduledAlarmInfo in project VideoOptimzer by attdevsupport.
the class AlarmPlot method getHasFiredAlarms.
private List<ScheduledAlarmInfo> getHasFiredAlarms(Map<String, List<ScheduledAlarmInfo>> pendingAlarms) {
List<ScheduledAlarmInfo> result = new ArrayList<ScheduledAlarmInfo>();
for (Map.Entry<String, List<ScheduledAlarmInfo>> entry : pendingAlarms.entrySet()) {
List<ScheduledAlarmInfo> alarms = entry.getValue();
@SuppressWarnings("rawtypes") ListIterator itrAlarms = alarms.listIterator();
while (itrAlarms.hasNext()) {
ScheduledAlarmInfo alarm = (ScheduledAlarmInfo) itrAlarms.next();
if (alarm.getHasFired() > 0) {
result.add(alarm);
}
}
}
return result;
}
use of com.att.aro.core.packetanalysis.pojo.ScheduledAlarmInfo 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;
}
use of com.att.aro.core.packetanalysis.pojo.ScheduledAlarmInfo 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());
}
use of com.att.aro.core.packetanalysis.pojo.ScheduledAlarmInfo in project VideoOptimzer by attdevsupport.
the class TraceDataReaderImplTest method readTraceDir_checkExternalVideoAndTime.
@Test
public void readTraceDir_checkExternalVideoAndTime() throws IOException {
String[] time = { "1410212153.578 1410213352.550", "272927100", "1410213352.550" };
String[] appId = {};
traceDataReaderImpl.setFileReader(filereader);
when(filereader.directoryExist(any(String.class))).thenReturn(true);
when(filereader.readAllLine(any(String.class))).thenReturn(time);
when(filereader.readAllLine(any(String.class))).thenReturn(appId);
when(filereader.readAllLine(Util.getCurrentRunningDir() + Util.FILE_SEPARATOR + "exVideo_time")).thenReturn(time);
when(filereader.fileExist(any(String.class))).thenReturn(true);
when(filereader.fileExist(Util.getCurrentRunningDir() + Util.FILE_SEPARATOR + "traffic1.cap")).thenReturn(false);
when(filereader.fileExist(Util.getCurrentRunningDir() + Util.FILE_SEPARATOR + "time")).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);
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();
when(devicedetailreader.readData(any(String.class))).thenReturn(device);
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(0, result.getAppIds().size());
}
Aggregations