use of com.att.aro.core.packetanalysis.pojo.EnergyModel in project VideoOptimzer by attdevsupport.
the class HtmlReportImpl method getTimeRangeAnalysisAndStatisticRows.
private String getTimeRangeAnalysisAndStatisticRows(PacketAnalyzerResult results) {
StringBuilder builder = new StringBuilder();
if (results != null) {
TimeRangeAnalysis timeRangeAnalysis = results.getTimeRangeAnalysis();
// Calculate time range
if (timeRangeAnalysis == null) {
AnalysisFilter filter = results.getFilter();
double beginTime = 0.0d;
double endTime = 0.0d;
boolean readyForAnalysis = false;
if (filter != null && filter.getTimeRange() != null) {
beginTime = filter.getTimeRange().getBeginTime();
endTime = filter.getTimeRange().getEndTime();
readyForAnalysis = true;
} else if (results.getTraceresult() != null) {
endTime = results.getTraceresult().getTraceDuration();
readyForAnalysis = true;
}
if (readyForAnalysis) {
timeRangeAnalysis = new TimeRangeAnalysis(beginTime, endTime, results);
}
}
if (timeRangeAnalysis != null) {
double traceDuration = timeRangeAnalysis.getEndTime() - timeRangeAnalysis.getStartTime();
long traceDurationLong = (long) traceDuration;
builder.append("<tr><th>Duration (second)</th><td>" + String.format("%.3f", traceDuration) + "</td></tr>");
builder.append("<tr><th>Duration (hh:mm:ss.sss)</th><td>" + String.format("%02d:%02d:%02d", traceDurationLong / 3600, (traceDurationLong % 3600) / 60, traceDurationLong % 60) + String.format("%.3f", traceDuration - Math.floor(traceDuration)).substring(1));
String timeRangeTitle = results.getTraceresult().getTimeRange().getTitle();
builder.append("<tr><th>Time Range Identifier</th><td>" + (timeRangeTitle != null ? timeRangeTitle : "") + "</td></tr>");
builder.append("<tr><th>Start Time (second)</th><td>" + doubleToFixedDecimal(timeRangeAnalysis.getStartTime(), 3) + "</td></tr>");
builder.append("<tr><th>End Time (second)</th><td>" + doubleToFixedDecimal(timeRangeAnalysis.getEndTime(), 3) + "</td></tr>");
}
Statistic statistic = results.getStatistic();
if (statistic != null) {
builder.append(tableLIne() + "<th>Total Data (Byte)</th><td>" + statistic.getTotalByte() + tableChange() + System.getProperty(lineSeperator()));
builder.append(tableLIne() + "<th>Total PayLoad Data (Byte)</th><td>" + statistic.getTotalPayloadBytes() + tableChange() + System.getProperty(lineSeperator()));
builder.append(tableLIne() + "<th>Total HTTPS Data (Byte)</th><td>" + statistic.getTotalHTTPSByte() + " (" + String.format("%.2f", statistic.getTotalHTTPSByte() * 100.0 / statistic.getTotalByte()) + "%)" + tableChange() + System.getProperty(lineSeperator()));
builder.append(tableLIne() + "<th>Total Unanalyzed HTTPS Data (Byte)</th><td>" + statistic.getTotalHTTPSBytesNotAnalyzed() + " (" + String.format("%.2f", statistic.getTotalHTTPSBytesNotAnalyzed() * 100.0 / statistic.getTotalByte()) + "%)</td>" + System.getProperty(lineSeperator()));
}
if (timeRangeAnalysis != null) {
builder.append("<tr><th>Average Throughput (kbps)</th><td>" + doubleToFixedDecimal(timeRangeAnalysis.getAverageThroughput(), 2) + "</td></tr>" + System.getProperty(lineSeperator()));
builder.append("<tr><th>Total Upload Data (Byte)</th><td>" + timeRangeAnalysis.getUplinkBytes() + "</td></tr>" + System.getProperty(lineSeperator()));
builder.append("<tr><th>Average Upload Throughput (kbps)</th><td>" + doubleToFixedDecimal(timeRangeAnalysis.getAverageUplinkThroughput(), 2) + "</td></tr>" + System.getProperty(lineSeperator()));
builder.append("<tr><th>Total Download Data (Byte)</th><td>" + timeRangeAnalysis.getDownlinkBytes() + "</td></tr>" + System.getProperty(lineSeperator()));
builder.append("<tr><th>Average Download Throughput (kbps)</th><td>" + doubleToFixedDecimal(timeRangeAnalysis.getAverageDownlinkThroughput(), 2) + "</td></tr>" + System.getProperty(lineSeperator()));
}
EnergyModel energyModel = results.getEnergyModel();
if (energyModel != null) {
builder.append("<tr><th>Total Energy Consumed (J)</th><td>" + doubleToFixedDecimal(energyModel.getTotalEnergyConsumed(), 2) + "</td></tr>" + System.getProperty(lineSeperator()));
}
}
return builder.toString();
}
use of com.att.aro.core.packetanalysis.pojo.EnergyModel in project VideoOptimzer by attdevsupport.
the class EnergyModelFactoryImplTest method create_Test.
@Test
public void create_Test() {
Date date = new Date();
Profile profile = Mockito.mock(Profile.class);
Mockito.when(profile.getPowerGpsActive()).thenReturn(1.0);
GpsInfo gpsInfo01 = Mockito.mock(GpsInfo.class);
Mockito.when(gpsInfo01.getBeginTimeStamp()).thenReturn(date.getTime() + 0.0);
Mockito.when(gpsInfo01.getEndTimeStamp()).thenReturn(date.getTime() + 1000.0);
Mockito.when(gpsInfo01.getGpsState()).thenReturn(GpsState.GPS_ACTIVE);
GpsInfo gpsInfo02 = Mockito.mock(GpsInfo.class);
Mockito.when(profile.getPowerGpsStandby()).thenReturn(0.5);
Mockito.when(gpsInfo02.getBeginTimeStamp()).thenReturn(date.getTime() + 0.0);
Mockito.when(gpsInfo02.getEndTimeStamp()).thenReturn(date.getTime() + 1000.0);
Mockito.when(gpsInfo02.getGpsState()).thenReturn(GpsState.GPS_STANDBY);
List<GpsInfo> gpsList = new ArrayList<GpsInfo>();
gpsList.add(gpsInfo01);
gpsList.add(gpsInfo02);
CameraInfo cameraInfo01 = Mockito.mock(CameraInfo.class);
Mockito.when(cameraInfo01.getBeginTimeStamp()).thenReturn(date.getTime() + 0.0);
Mockito.when(cameraInfo01.getEndTimeStamp()).thenReturn(date.getTime() + 1000.0);
Mockito.when(cameraInfo01.getCameraState()).thenReturn(CameraState.CAMERA_ON);
Mockito.when(profile.getPowerCameraOn()).thenReturn(0.3);
List<CameraInfo> cameraList = new ArrayList<CameraInfo>();
cameraList.add(cameraInfo01);
BluetoothInfo bluetoothInfo01 = Mockito.mock(BluetoothInfo.class);
Mockito.when(bluetoothInfo01.getBeginTimeStamp()).thenReturn(date.getTime() + 0.0);
Mockito.when(bluetoothInfo01.getEndTimeStamp()).thenReturn(date.getTime() + 1000.0);
Mockito.when(bluetoothInfo01.getBluetoothState()).thenReturn(BluetoothState.BLUETOOTH_CONNECTED);
BluetoothInfo bluetoothInfo02 = Mockito.mock(BluetoothInfo.class);
Mockito.when(bluetoothInfo02.getBeginTimeStamp()).thenReturn(date.getTime() + 0.0);
Mockito.when(bluetoothInfo02.getEndTimeStamp()).thenReturn(date.getTime() + 1000.0);
Mockito.when(bluetoothInfo02.getBluetoothState()).thenReturn(BluetoothState.BLUETOOTH_DISCONNECTED);
List<BluetoothInfo> bluetoothList = new ArrayList<BluetoothInfo>();
bluetoothList.add(bluetoothInfo01);
bluetoothList.add(bluetoothInfo02);
Mockito.when(profile.getPowerBluetoothActive()).thenReturn(1.0);
Mockito.when(profile.getPowerBluetoothStandby()).thenReturn(0.5);
ScreenStateInfo screenStateInfo01 = Mockito.mock(ScreenStateInfo.class);
Mockito.when(screenStateInfo01.getBeginTimeStamp()).thenReturn(date.getTime() + 0.0);
Mockito.when(screenStateInfo01.getEndTimeStamp()).thenReturn(date.getTime() + 1000.0);
Mockito.when(screenStateInfo01.getScreenState()).thenReturn(ScreenState.SCREEN_ON);
List<ScreenStateInfo> screenStateList = new ArrayList<ScreenStateInfo>();
screenStateList.add(screenStateInfo01);
Mockito.when(profile.getPowerScreenOn()).thenReturn(0.3);
EnergyModel model = eMdlFctr.create(profile, 0.0, gpsList, cameraList, bluetoothList, screenStateList);
assertEquals(1000.0, model.getGpsActiveEnergy(), 0.0);
assertEquals(500.0, model.getGpsStandbyEnergy(), 0.0);
assertEquals(1500.0, model.getTotalGpsEnergy(), 0.0);
assertEquals(300.0, model.getTotalCameraEnergy(), 0.0);
assertEquals(1000.0, model.getBluetoothActiveEnergy(), 0.0);
assertEquals(500.0, model.getBluetoothStandbyEnergy(), 0.0);
assertEquals(1500.0, model.getTotalBluetoothEnergy(), 0.0);
assertEquals(300.0, model.getTotalScreenEnergy(), 0.0);
}
use of com.att.aro.core.packetanalysis.pojo.EnergyModel in project VideoOptimzer by attdevsupport.
the class EnergyModelFactoryImpl method create.
@Override
public EnergyModel create(Profile profile, double totalRrcEnergy, List<GpsInfo> gpsinfos, List<CameraInfo> camerainfos, List<BluetoothInfo> bluetoothinfos, List<ScreenStateInfo> screenstateinfos) {
double gpsActiveEnergy = 0, gpsStandbyEnergy = 0, totalGpsEnergy = 0, totalCameraEnergy = 0;
double bluetoothActiveEnergy = 0, bluetoothStandbyEnergy = 0, totalBluetoothEnergy = 0;
double totalScreenEnergy = 0;
EnergyModel model = new EnergyModel();
model.setTotalRrcEnergy(totalRrcEnergy);
// GPS Energy
Iterator<GpsInfo> gpsIter = gpsinfos.iterator();
if (gpsIter.hasNext()) {
while (gpsIter.hasNext()) {
GpsInfo gps = gpsIter.next();
GpsState gpsState = gps.getGpsState();
switch(gpsState) {
case GPS_ACTIVE:
gpsActiveEnergy += profile.getPowerGpsActive() * (gps.getEndTimeStamp() - gps.getBeginTimeStamp());
break;
case GPS_STANDBY:
gpsStandbyEnergy += profile.getPowerGpsStandby() * (gps.getEndTimeStamp() - gps.getBeginTimeStamp());
break;
default:
break;
}
}
}
totalGpsEnergy = gpsActiveEnergy + gpsStandbyEnergy;
// Camera Energy
Iterator<CameraInfo> cameraIter = camerainfos.iterator();
if (cameraIter.hasNext()) {
while (cameraIter.hasNext()) {
CameraInfo camera = cameraIter.next();
CameraInfo.CameraState cameraState = camera.getCameraState();
if (cameraState == CameraInfo.CameraState.CAMERA_ON) {
totalCameraEnergy += profile.getPowerCameraOn() * (camera.getEndTimeStamp() - camera.getBeginTimeStamp());
}
}
}
// Bluetooth Energy
Iterator<BluetoothInfo> bluetoothIter = bluetoothinfos.iterator();
if (bluetoothIter.hasNext()) {
while (bluetoothIter.hasNext()) {
BluetoothInfo btInfo = bluetoothIter.next();
if (btInfo == null || btInfo.getBluetoothState() == null) {
continue;
}
switch(btInfo.getBluetoothState()) {
case BLUETOOTH_CONNECTED:
bluetoothActiveEnergy += profile.getPowerBluetoothActive() * (btInfo.getEndTimeStamp() - btInfo.getBeginTimeStamp());
break;
case BLUETOOTH_DISCONNECTED:
bluetoothStandbyEnergy += profile.getPowerBluetoothStandby() * (btInfo.getEndTimeStamp() - btInfo.getBeginTimeStamp());
break;
default:
break;
}
}
}
totalBluetoothEnergy = bluetoothActiveEnergy + bluetoothStandbyEnergy;
// Screen Energy
Iterator<ScreenStateInfo> screenIter = screenstateinfos.iterator();
if (screenIter.hasNext()) {
while (screenIter.hasNext()) {
ScreenStateInfo screenInfo = screenIter.next();
if (screenInfo.getScreenState() == ScreenStateInfo.ScreenState.SCREEN_ON) {
totalScreenEnergy += profile.getPowerScreenOn() * (screenInfo.getEndTimeStamp() - screenInfo.getBeginTimeStamp());
}
}
}
model.setBluetoothActiveEnergy(bluetoothActiveEnergy);
model.setBluetoothStandbyEnergy(bluetoothStandbyEnergy);
model.setGpsActiveEnergy(gpsActiveEnergy);
model.setGpsStandbyEnergy(gpsStandbyEnergy);
model.setTotalBluetoothEnergy(totalBluetoothEnergy);
model.setTotalCameraEnergy(totalCameraEnergy);
model.setTotalGpsEnergy(totalGpsEnergy);
model.setTotalRrcEnergy(totalRrcEnergy);
model.setTotalScreenEnergy(totalScreenEnergy);
return model;
}
use of com.att.aro.core.packetanalysis.pojo.EnergyModel in project VideoOptimzer by attdevsupport.
the class PacketAnalyzerImpl method finalResult.
protected PacketAnalyzerResult finalResult(AbstractTraceResult result, Profile profile, AnalysisFilter filter) {
PacketAnalyzerResult data = new PacketAnalyzerResult();
if (filter == null) {
double endTime = result.getAllpackets().size() > 0 ? Math.max(result.getAllpackets().get(result.getAllpackets().size() - 1).getTimeStamp(), result.getTraceDuration()) : 0.0;
result.setTimeRange(new TimeRange("Full", TimeRange.TimeRangeType.FULL, 0.0, endTime));
} else {
result.setTimeRange(filter.getTimeRange());
}
// List of packets included in analysis (application filtered)
List<PacketInfo> filteredPackets;
Profile aProfile = profile;
if (aProfile == null) {
// if the user doesn't load any profile.....
aProfile = profilefactory.createLTEdefault();
aProfile.setName("AT&T LTE");
}
// for the situation, filter out all no-ip packets and caused the allpackets is empty, need to refactor
if (result != null && result.getAllpackets() != null && result.getAllpackets().size() == 0) {
data.setTraceresult(result);
return data;
}
/* Purpose of this code block is to finish building out the filter, if needed, for TimeRange analysis
*
* This code block is excuted when:
* 1: time-range.json exists in trace folder
* a: and the json contains an entry with RangeType.AUTO
* 2: A TimeRange object was created and launched in TimeRangeEditorDialog
*
* AroController will have created an AnalysisFilter and so filter will not be null
*
*/
try {
if ((filter != null && filter.getTimeRange() != null && filter.getTimeRange().getPath() != null) || result.getAllAppNames().size() == 1) {
String app = TraceDataReaderImpl.UNKNOWN_APPNAME;
if (filter != null && filter.getAppSelections() != null && filter.getAppSelections().containsKey(app) && filter.getAppSelections().get(app).getIPAddressSelections().isEmpty()) {
LOGGER.debug("AUTO Time Range analysis: add all found appIps to " + app + ", then store in the filter");
ApplicationSelection appSelection = new ApplicationSelection(app, result.getAppIps().get(app));
filter.getAppSelections().put(app, appSelection);
}
}
} catch (Exception e) {
LOGGER.error("Error handling TimeRange JSON data", e);
}
TimeRange timeRange = null;
boolean isCSI = false;
filteredPackets = new ArrayList<PacketInfo>();
if (filter == null) {
if (result != null) {
filteredPackets = result.getAllpackets();
}
} else {
// do the filter
if (filter.isCSI() && filter.getManifestFilePath() != null) {
isCSI = true;
}
timeRange = filter.getTimeRange();
if (result != null) {
filteredPackets = filterPackets(filter, result.getAllpackets());
}
}
// Fix for Sev 2 Time Range Analysis Issue - DE187848
if (result != null) {
result.setAllpackets(filteredPackets);
SessionManagerImpl sessionMangerImpl = (SessionManagerImpl) sessionmanager;
sessionMangerImpl.setPcapTimeOffset(result.getPcapTimeOffset());
// for iOS trace
sessionmanager.setiOSSecureTracePath(result.getTraceDirectory());
// Check if secure trace path exists
if (result instanceof TraceDirectoryResult) {
File file = new File(((SessionManagerImpl) sessionmanager).getTracePath());
if (file.exists()) {
((TraceDirectoryResult) result).setSecureTrace(true);
}
}
}
Statistic stat = this.getStatistic(filteredPackets);
List<Session> sessionList = sessionmanager.processPacketsAndAssembleSessions(filteredPackets);
generateGetRequestMapAndPopulateLatencyStat(sessionList, stat);
if (result != null && stat.getAppName() != null && stat.getAppName().size() == 1 && stat.getAppName().contains(TraceDataReaderImpl.UNKNOWN_APPNAME)) {
stat.setAppName(new HashSet<String>(result.getAppInfos()));
}
// get Unanalyzed HTTPS bytes
boolean isSecureTrace = result instanceof TraceDirectoryResult ? ((TraceDirectoryResult) result).isSecureTrace() : false;
if (isSecureTrace) {
stat.setTotalHTTPSBytesNotAnalyzed(getHttpsBytesNotAnalyzed(sessionList));
} else {
stat.setTotalHTTPSBytesNotAnalyzed(stat.getTotalHTTPSByte());
}
// stat is used to get some info for RrcStateMachine etc
if (result != null) {
LOGGER.debug("Starting pre processing in PAI");
AbstractRrcStateMachine statemachine = statemachinefactory.create(filteredPackets, aProfile, stat.getPacketDuration(), result.getTraceDuration(), stat.getTotalByte(), timeRange);
EnergyModel energymodel = energymodelfactory.create(aProfile, statemachine.getTotalRRCEnergy(), result.getGpsInfos(), result.getCameraInfos(), result.getBluetoothInfos(), result.getScreenStateInfos());
BurstCollectionAnalysisData burstcollectiondata = burstcollectionanalyzer.analyze(filteredPackets, aProfile, stat.getPacketSizeToCountMap(), statemachine.getStaterangelist(), result.getUserEvents(), result.getCpuActivityList().getCpuActivities(), sessionList);
data.clearBPResults();
try {
List<BestPracticeType> videoBPList = BestPracticeType.getByCategory(BestPracticeType.Category.VIDEO);
data.setStreamingVideoData(videoTrafficCollector.clearData());
if (CollectionUtils.containsAny(SettingsUtil.retrieveBestPractices(), videoBPList)) {
if (isCSI || csiDataHelper.doesCSIFileExist(result.getTraceDirectory())) {
data.setStreamingVideoData(videoTrafficInferencer.inferVideoData(result, sessionList, (filter != null && filter.getManifestFilePath() != null) ? filter.getManifestFilePath() : result.getTraceDirectory()));
} else {
data.setStreamingVideoData(videoTrafficCollector.collect(result, sessionList, requestMap));
}
}
} catch (Exception ex) {
LOGGER.error("Error in Video usage analysis :", ex);
// Guarantee that StreamingVideoData is empty
data.setStreamingVideoData(videoTrafficCollector.clearData());
data.getStreamingVideoData().setFinished(true);
}
try {
List<BestPracticeType> imageBPList = new ArrayList<>();
imageBPList.add(BestPracticeType.IMAGE_MDATA);
imageBPList.add(BestPracticeType.IMAGE_CMPRS);
imageBPList.add(BestPracticeType.IMAGE_FORMAT);
imageBPList.add(BestPracticeType.IMAGE_COMPARE);
if (CollectionUtils.containsAny(SettingsUtil.retrieveBestPractices(), imageBPList)) {
imageExtractor.execute(result, sessionList, requestMap);
}
} catch (Exception ex) {
LOGGER.error("Error in Image extraction:" + ex.getMessage(), ex);
}
htmlExtractor.execute(result, sessionList, requestMap);
// Calculate time range analysis
double beginTime = 0.0d;
double endTime = 0.0d;
if (filter != null && filter.getTimeRange() != null) {
beginTime = filter.getTimeRange().getBeginTime();
endTime = filter.getTimeRange().getEndTime();
} else {
endTime = result.getTraceDuration();
}
data.setBurstCollectionAnalysisData(burstcollectiondata);
data.setEnergyModel(energymodel);
data.setSessionlist(sessionList);
data.setStatemachine(statemachine);
data.setStatistic(stat);
data.setTraceresult(result);
data.setProfile(aProfile);
data.setFilter(filter);
data.setDeviceKeywords(result.getDeviceKeywordInfos());
data.setTimeRangeAnalysis(new TimeRangeAnalysis(beginTime, endTime, data));
}
return data;
}
use of com.att.aro.core.packetanalysis.pojo.EnergyModel in project VideoOptimzer by attdevsupport.
the class HtmlReportImplTest method reportGenerator_retunrIsTrue.
@Test
@Ignore
public void reportGenerator_retunrIsTrue() {
AccessingPeripheralResult access = new AccessingPeripheralResult();
access.setResultType(BPResultType.PASS);
CacheControlResult cache = new CacheControlResult();
cache.setResultType(BPResultType.FAIL);
List<AbstractBestPracticeResult> bpResults = new ArrayList<AbstractBestPracticeResult>();
bpResults.add(access);
bpResults.add(cache);
File tempFile = null;
try {
tempFile = folder.newFile("abc.html");
} catch (IOException e) {
e.printStackTrace();
}
if (tempFile != null) {
tempFile.deleteOnExit();
}
when(filereader.createFile(any(String.class))).thenReturn(tempFile);
AROTraceData results = new AROTraceData();
PacketAnalyzerResult analyzerResult = new PacketAnalyzerResult();
TraceDirectoryResult tracedirresult = new TraceDirectoryResult();
EnergyModel energyModel = new EnergyModel();
Statistic statistic = new Statistic();
statistic.setTotalByte(123);
statistic.setTotalHTTPSByte(123);
tracedirresult.setTraceDirectory("temp.txt");
analyzerResult.setTraceresult(tracedirresult);
analyzerResult.setEnergyModel(energyModel);
analyzerResult.setStatistic(statistic);
results.setAnalyzerResult(analyzerResult);
results.setBestPracticeResults(bpResults);
assertTrue(htmlReportImpl.reportGenerator("abc.html", results));
}
Aggregations