package simulator.stats.implementation; import java.awt.Color; import java.awt.Paint; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; import org.apache.commons.lang.ArrayUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartRenderingInfo; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.AxisLocation; import org.jfree.chart.axis.DateAxis; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.encoders.ImageFormat; import org.jfree.chart.labels.CategoryItemLabelGenerator; import org.jfree.chart.labels.ItemLabelAnchor; import org.jfree.chart.labels.ItemLabelPosition; import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.plot.CombinedDomainXYPlot; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.renderer.category.GanttRenderer; import org.jfree.chart.renderer.xy.XYStepAreaRenderer; import org.jfree.chart.title.TextTitle; import org.jfree.chart.title.Title; import org.jfree.data.gantt.TaskSeries; import org.jfree.data.gantt.TaskSeriesCollection; import org.jfree.data.time.FixedMillisecond; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.jfree.ui.TextAnchor; import org.joda.time.DateTime; import org.joda.time.DateTimeUtilsExt; import schedframe.ExecutablesList; import schedframe.ResourceController; import schedframe.exceptions.ResourceException; import schedframe.resources.ResourceType; import schedframe.resources.UserResourceType; import schedframe.resources.computing.ComputingResource; import schedframe.resources.computing.extensions.Extension; import schedframe.resources.computing.extensions.ExtensionList; import schedframe.resources.computing.extensions.ExtensionType; import schedframe.resources.computing.profiles.energy.EnergyExtension; import schedframe.resources.computing.profiles.energy.airthroughput.AirFlowValue; import schedframe.resources.computing.profiles.energy.power.PowerUsage; import schedframe.resources.computing.profiles.energy.thermal.TemperatureValue; import schedframe.resources.units.PEUnit; import schedframe.resources.units.ProcessingElements; import schedframe.resources.units.ResourceUnit; import schedframe.resources.units.ResourceUnitName; import schedframe.resources.units.StandardResourceUnitName; import schedframe.scheduling.ResourceHistoryItem; import schedframe.scheduling.Scheduler; import schedframe.scheduling.manager.tasks.JobRegistry; import schedframe.scheduling.manager.tasks.JobRegistryImpl; import schedframe.scheduling.tasks.Job; import schedframe.scheduling.tasks.JobInterface; import simulator.ConfigurationOptions; import simulator.DCWormsConstants; import simulator.DataCenterWorkloadSimulator; import simulator.GenericUser; import simulator.stats.GSSAccumulator; import simulator.stats.SimulationStatistics; import simulator.stats.implementation.out.AbstractStringSerializer; import simulator.stats.implementation.out.StringSerializer; import csiro.mit.utils.jfreechart.timetablechart.TimetableChartFactory; import csiro.mit.utils.jfreechart.timetablechart.data.Timetable; import csiro.mit.utils.jfreechart.timetablechart.data.TimetableEventGroup; import csiro.mit.utils.jfreechart.timetablechart.data.TimetableEventSource; import csiro.mit.utils.jfreechart.timetablechart.renderer.TimetableRenderer; import dcworms.schedframe.scheduling.ExecTask; import dcworms.schedframe.scheduling.Executable; import eduni.simjava.Sim_stat; public class DCWormsStatistics implements SimulationStatistics { private Log log = LogFactory.getLog(DCWormsStatistics.class); protected static float ALPHA = 0.5f; protected static int GANTT_WIDTH = 1200; protected static final int MILLI_SEC = 1000; protected static final String RAW_TASKS_STATISTICS_OUTPUT_FILE_NAME = "Tasks.txt"; protected static final String JOBS_STATISTICS_OUTPUT_FILE_NAME = "Jobs.txt"; protected static final String SIMULATION_STATISTICS_OUTPUT_FILE_NAME = "Simulation.txt"; protected static final String RESOURCEUTILIZATION_STATISTICS_OUTPUT_FILE_NAME = "ResourceUtilization.txt"; protected static final String ENERGYUSAGE_STATISTICS_OUTPUT_FILE_NAME = "EnergyUsage.txt"; protected static final String AIRFLOW_STATISTICS_OUTPUT_FILE_NAME = "AirThroughput.txt"; protected static final String TEMPERATURE_STATISTICS_OUTPUT_FILE_NAME = "Temperature.txt"; protected static final String DIAGRAMS_FILE_NAME_PREFIX = "Chart_"; protected static final String STATS_FILE_NAME_PREFIX = "Stats_"; protected static final String TASK_SEPARATOR = ";"; protected static final String JOB_SEPARATOR = ";"; protected String outputFolderName; protected String simulationIdentifier; protected ConfigurationOptions configuration; protected GSSAccumulatorsStats accStats; protected Map statsData; protected GenericUser users; protected ResourceController resourceController; protected boolean generateDiagrams = true; protected AbstractStringSerializer serializer; protected long startSimulationTime; protected long endSimulationTime; //RESOURCES protected Map> basicResStats; protected Map basicResLoad; protected Map peGanttMap; protected Map taskGanttMap; protected Timetable ganttDiagramTimetable; protected Map> resourcePowerUsageDiagrams; protected Map> resourceAirFlowDiagrams; protected Map> resourceTemperatureDiagrams; protected Map> resourceLoadDiagrams; //TASKS protected int numOfdelayedTasks = 0; protected int numOfNotExecutedTasks = 0; protected double maxCj = 0; protected boolean allTasksFinished; protected TaskSeriesCollection ganttDiagramTaskSeriesCollection; protected TaskSeriesCollection ganttDiagramWaitingTimeSeriesCollection; protected HashMap> task_processorsMap; protected JobRegistry jr; public DCWormsStatistics(String simulationIdentifier, ConfigurationOptions co, GenericUser users, String outputFolderName, ResourceController resourceController) { this.simulationIdentifier = simulationIdentifier; this.configuration = co; this.users = users; this.outputFolderName = outputFolderName; this.serializer = new StringSerializer(); this.serializer.setDefaultNumberFormat(DataCenterWorkloadSimulator.DFAULT_NUMBER_FORMAT); this.resourceController = resourceController; this.jr = new JobRegistryImpl(""); init(); } public void generateStatistics() { if(users.isSimStartTimeDefined()) this.startSimulationTime = DateTimeUtilsExt.getOffsetTime().getTimeInMillis(); else this.startSimulationTime = new DateTime(users.getSubmissionStartTime() * 1000l).getMillis(); this.endSimulationTime = DateTimeUtilsExt.currentTimeMillis(); long s = 0; long e = 0; log.info("gatherResourceStatistics"); s = System.currentTimeMillis(); gatherResourceStatistics(); e = System.currentTimeMillis(); log.info("time in sec: " + ((e - s) / MILLI_SEC)); log.info("gatherTaskStatistics"); s = System.currentTimeMillis(); gatherTaskStatistics(); e = System.currentTimeMillis(); log.info("time in sec: " + ((e - s) / MILLI_SEC)); log.info("saveSimulationStatistics"); s = System.currentTimeMillis(); saveSimulationStatistics(); e = System.currentTimeMillis(); log.info("time in sec: " + ((e - s) / MILLI_SEC)); } public String getOutputFolderName() { return outputFolderName; } private void init() { task_processorsMap = new HashMap>(); accStats = new GSSAccumulatorsStats(); statsData = new HashMap(); } public void saveSimulationStatistics() { PrintStream simulationStatsFile = null; if (configuration.createsimulationstatistics) { try { File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_" + SIMULATION_STATISTICS_OUTPUT_FILE_NAME); simulationStatsFile = new PrintStream(new FileOutputStream(file)); } catch (IOException e) { e.printStackTrace(); } } if (simulationStatsFile != null) { Object txt = accStats.serialize(this.serializer); simulationStatsFile.println(txt); } if (simulationStatsFile != null) { simulationStatsFile.close(); } } /************* RESOURCE STATISTICS SECTION **************/ private void gatherResourceStatistics() { HashMap> type_stats = new HashMap>(); for(String resourceName: resourceController.getComputingResourceLayers()){ List cStats = new ArrayList(); cStats.add(Stats.textLoad); if(ArrayUtils.contains(configuration.resForUtilizationChart, resourceName)) cStats.add(Stats.chartLoad); cStats.add(Stats.textEnergy); if(ArrayUtils.contains(configuration.resForEnergyChart, resourceName)) cStats.add(Stats.chartEnergy); cStats.add(Stats.textAirFlow); if(ArrayUtils.contains(configuration.resForAirFlowChart, resourceName)) cStats.add(Stats.chartAirFlow); cStats.add(Stats.textTemperature); if(ArrayUtils.contains(configuration.resForTemperatureChart, resourceName)) cStats.add(Stats.chartTemperature); type_stats.put(resourceName, cStats); } peGanttMap = new HashMap(); taskGanttMap = new HashMap(); resourceLoadDiagrams = new HashMap>(); resourcePowerUsageDiagrams = new HashMap>(); resourceAirFlowDiagrams = new HashMap>(); resourceTemperatureDiagrams = new HashMap>(); ganttDiagramTimetable = new Timetable(new FixedMillisecond( startSimulationTime), new FixedMillisecond(endSimulationTime)); PrintStream resourceLoadStatsFile = null; try { File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_" + RESOURCEUTILIZATION_STATISTICS_OUTPUT_FILE_NAME); resourceLoadStatsFile = new PrintStream(new FileOutputStream(file)); } catch (IOException e) { resourceLoadStatsFile = null; } PrintStream energyStatsFile = null; try { File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_" + ENERGYUSAGE_STATISTICS_OUTPUT_FILE_NAME); energyStatsFile = new PrintStream(new FileOutputStream(file)); } catch (IOException e) { energyStatsFile = null; } PrintStream airFlowStatsFile = null; try { File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_" + AIRFLOW_STATISTICS_OUTPUT_FILE_NAME); airFlowStatsFile = new PrintStream(new FileOutputStream(file)); } catch (IOException e) { airFlowStatsFile = null; } PrintStream temperatureStatsFile = null; try { File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_" + TEMPERATURE_STATISTICS_OUTPUT_FILE_NAME); temperatureStatsFile = new PrintStream(new FileOutputStream(file)); } catch (IOException e) { temperatureStatsFile = null; } basicResStats = gatherPEStats(jr.getExecutableTasks()); peStatsPostProcessing(basicResStats); basicResLoad = calculatePELoad( basicResStats); if (configuration.creatediagrams_gantt) { createPEGanttDiagram(basicResStats); } for(String resourceName: resourceController.getComputingResourceLayers()){ List resources = null; resources = new ArrayList(); for(ComputingResource compRes: resourceController.getComputingResources() ){ resources.addAll(compRes.getDescendantsByType(new UserResourceType(resourceName))); } if(resourceController.getComputingResources().get(0).getType().getName().equals(resourceName)) resources.addAll(resourceController.getComputingResources()); if(type_stats.containsKey(resourceName)){ for(ComputingResource resource: resources){ ResourceUsageStats resourceUsage = null; ResourcePowerStats energyUsage = null; ResourceAirFlowStats airFlow = null; ResourceTemperatureStats temperature = null; if(type_stats.get(resourceName).contains(Stats.textLoad)){ resourceUsage = gatherResourceLoadStats(resource, basicResStats); resourceUsage.setMeanValue(calculateMeanValue(resourceUsage)); if (resourceLoadStatsFile != null) { Object txt = resourceUsage.serialize(serializer); resourceLoadStatsFile.println(txt); } } if(type_stats.get(resourceName).contains(Stats.chartLoad)){ if (configuration.creatediagrams_resutilization) { createResourceLoadDiagram(resourceUsage); } } if(type_stats.get(resourceName).contains(Stats.textEnergy)){ energyUsage = gatherResourcePowerConsumptionStats(resource); energyUsage.setMeanValue(calculateMeanValue(energyUsage)); energyUsage.setSumValue(energyUsage.getMeanValue() * (endSimulationTime - startSimulationTime) / (3600 * MILLI_SEC)); EnergyExtension een = (EnergyExtension)(resource.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); if(resourceController.getComputingResources().contains(resource)) { if( een != null && een.getPowerProfile() != null && een.getPowerProfile().getEnergyEstimationPlugin() != null){ accStats.meanEnergyUsage.add(energyUsage.getSumValue()); } } else if( een != null && een.getPowerProfile() != null && een.getPowerProfile().getEnergyEstimationPlugin() != null){ ComputingResource parent = resource.getParent(); boolean top = true; while(parent != null){ een = (EnergyExtension)(parent.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); if(een != null && een.getPowerProfile() != null && een.getPowerProfile().getEnergyEstimationPlugin() != null) { top = false; break; } parent = parent.getParent(); } if(top == true){ accStats.meanEnergyUsage.add(energyUsage.getSumValue()); } } if (energyStatsFile != null) { Object txt = energyUsage.serialize(serializer); energyStatsFile.println(txt); } } if(type_stats.get(resourceName).contains(Stats.chartEnergy)){ if (configuration.creatediagrams_respowerusage) { createResourceEnergyDiagramData(energyUsage); } } if(type_stats.get(resourceName).contains(Stats.textAirFlow)){ airFlow = gatherResourceAirFlowStats(resource); airFlow.setMeanValue(calculateMeanValue(airFlow)); airFlow.setSumValue(airFlow.getMeanValue() * (endSimulationTime - startSimulationTime) / (60 * MILLI_SEC)); EnergyExtension een = (EnergyExtension)(resource.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); if(resourceController.getComputingResources().contains(resource)) { if( een != null /*&& een.getPp() != null*/ ){ accStats.meanAirFlow.add(airFlow.getSumValue()); } } else if( een != null && een.getAirFlowProfile() != null ){ ComputingResource parent = resource.getParent(); een = (EnergyExtension)(parent.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); boolean top = true; while(parent != null){ if(een != null && een.getAirFlowProfile() != null) { top = false; break; } parent = parent.getParent(); } if(top == true){ accStats.meanAirFlow.add(airFlow.getSumValue()); } } if (airFlowStatsFile != null) { Object txt = airFlow.serialize(serializer); airFlowStatsFile.println(txt); } } if(type_stats.get(resourceName).contains(Stats.chartAirFlow)){ if (configuration.creatediagrams_resairflow) { createResourceAirFlowDiagramData(airFlow); } } if(type_stats.get(resourceName).contains(Stats.textTemperature)){ temperature = gatherResourceTemperatureStats(resource); temperature.setMeanValue(calculateMeanValue(temperature)); temperature.setSumValue(temperature.getMeanValue() * (endSimulationTime - startSimulationTime) / (3600 * MILLI_SEC)); EnergyExtension een = (EnergyExtension)(resource.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); if(resourceController.getComputingResources().contains(resource)) { if( een != null /*&& een.getPp() != null*/ ){ accStats.meanTemperature.add(temperature.getSumValue()); } } else if( een != null && een.getThermalProfile() != null ){ ComputingResource parent = resource.getParent(); een = (EnergyExtension)(parent.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); boolean top = true; while(parent != null){ if(een != null && een.getThermalProfile() != null) { top = false; break; } parent = parent.getParent(); } if(top == true){ accStats.meanTemperature.add(temperature.getSumValue()); } } if (temperatureStatsFile != null) { Object txt = temperature.serialize(serializer); temperatureStatsFile.println(txt); } } if(type_stats.get(resourceName).contains(Stats.chartTemperature)){ if (configuration.creatediagrams_restemperature) { createResourceTemperatureDiagramData(temperature); } } } } } saveResourceGanttDiagrams(); createAccumulatedResourceSimulationStatistic(); if (temperatureStatsFile != null) { temperatureStatsFile.close(); } if (airFlowStatsFile != null) { airFlowStatsFile.close(); } if (energyStatsFile != null) { energyStatsFile.close(); } if (resourceLoadStatsFile != null) { resourceLoadStatsFile.close(); } } private void peStatsPostProcessing(Map> basicResStats){ ResourceType resType = null; for(String key: basicResStats.keySet()){ List resStats = basicResStats.get(key); resType = resStats.get(0).getResType(); break; } List resources = null; try { resources = new ArrayList(); for(ComputingResource compRes: resourceController.getComputingResources() ){ resources.addAll(compRes.getDescendantsByType(resType)); } } catch (Exception e) { return; } for(ComputingResource resource: resources){ if(!basicResStats.containsKey(resource.getName())){ basicResStats.put(resource.getName(), new ArrayList()); } } } private Map> gatherPEStats( ExecutablesList executables) { Map> basicResStats = new TreeMap>(new MapPEIdComparator()); for (ExecTask execTask:executables) { Executable exec = (Executable) execTask; List resHistItemList = exec.getUsedResources(); if(resHistItemList.size() == 0) return basicResStats; Map res = resHistItemList.get(resHistItemList.size() - 1).getResourceUnits(); ResourceUnit resUnit = res.get(StandardResourceUnitName.PE); //ProcessingElements pes = (ProcessingElements) resUnit ; if(resUnit instanceof ProcessingElements){ ProcessingElements pes = (ProcessingElements) resUnit; for(ComputingResource pe: pes){ String peName = pe.getName(); long startDate = Double.valueOf(exec.getExecStartTime()).longValue() * MILLI_SEC; long endDate = Double.valueOf(exec.getFinishTime()).longValue() * MILLI_SEC; String uniqueTaskID = getUniqueTaskId(execTask); ResStat resStat = new ResStat(peName, pe.getType(), startDate, endDate, uniqueTaskID); List resStats = basicResStats.get(peName); if (resStats == null) { resStats = new ArrayList(); resStats.add(resStat); basicResStats.put(peName, resStats); } else { resStats.add(resStat); } List peNames = task_processorsMap.get(uniqueTaskID); if (peNames == null) { peNames = new ArrayList(); peNames.add(peName); task_processorsMap.put(uniqueTaskID, peNames); } else { peNames.add(peName); } } } else if (resUnit instanceof PEUnit){ PEUnit peUnit = (PEUnit) resUnit ; } } return basicResStats; } //change this method to adjust the colors of gantt chart private String getUniqueTaskId(ExecTask execTask){ return execTask.getJobId() + "_" + execTask.getId(); } private ResourceUsageStats gatherResourceLoadStats(ComputingResource resource, Map> basicStats) { ResourceUsageStats usageStats = new ResourceUsageStats(resource.getName(), resource.getType(), "resourceLoadStats"); int cnt = 0; for(String resName: basicStats.keySet()){ try { if(resource.getDescendantByName(resName) != null || resource.getName().compareTo(resName) == 0){ createResourceLoadData(usageStats, basicStats.get(resName)); cnt++; } } catch (ResourceException e) { // TODO Auto-generated catch block e.printStackTrace(); } } for(Long key: usageStats.getHistory().keySet()){ Double value = usageStats.getHistory().get(key)/cnt; usageStats.getHistory().put(key, value); } return usageStats; } private Map createResourceLoadData(ResourceUsageStats usageStats, List resStats) { TreeMap ganttData = (TreeMap)usageStats.getHistory(); for (ResStat resStat : resStats) { long start_time = resStat.getStartDate(); long end_time = resStat.getEndDate(); if (end_time > start_time) { Double end = ganttData.get(end_time); if (end == null) { ganttData.put(end_time, 0.0); Long left = getLeftKey(ganttData, end_time); if (left != null) { Double leftValue = ganttData.get(left); ganttData.put(end_time, leftValue); } } Double start = ganttData.get(start_time); if (start == null) { ganttData.put(start_time, 0.0); Long left = getLeftKey(ganttData, start_time); if (left != null) { Double leftValue = ganttData.get(left); ganttData.put(start_time, leftValue); } } SortedMap sm = ganttData.subMap(start_time, end_time); for (Long key : sm.keySet()) { Double keyVal = ganttData.get(key); ganttData.put(key, keyVal + 1); } } } return ganttData; } private Long getLeftKey(TreeMap ganttData, Long toKey) { SortedMap sm = ganttData.headMap(toKey); if (sm.isEmpty()) { return null; } return sm.lastKey(); } private ResourcePowerStats gatherResourcePowerConsumptionStats(ComputingResource resource) { double power = 0; ResourcePowerStats resEnergyUsage = new ResourcePowerStats(resource.getName(), resource.getType(), "resourcePowerConsumptionStats"); Map usage = resEnergyUsage.getHistory(); ExtensionList extensionList = resource.getExtensionList(); if(extensionList != null){ for (Extension extension : extensionList) { if (extension.getType() == ExtensionType.ENERGY_EXTENSION) { EnergyExtension ee = (EnergyExtension)extension; if(ee.getPowerProfile() == null) break; List powerUsage = ee.getPowerProfile().getPowerUsageHistory(); if(powerUsage.size() == 0) break; long lastTime = DateTimeUtilsExt.getOffsetTime().getTimeInMillis(); long endSimulationTime = DateTimeUtilsExt.currentTimeMillis(); double lastPower = 0; powerUsage.add(new PowerUsage(endSimulationTime, ee.getPowerProfile().getPowerUsageHistory().get(ee.getPowerProfile().getPowerUsageHistory().size()-1).getValue())); for(PowerUsage pu:powerUsage){ usage.put(pu.getTimestamp(), pu.getValue()); /// System.out.println(resource.getName() + ":"+new DateTime(pu.getTimestamp())+";"+pu.getValue()); power = power + (pu.getTimestamp() - lastTime) * lastPower/ (3600 * MILLI_SEC); lastPower = pu.getValue(); lastTime = pu.getTimestamp(); } } } } //System.out.println(power); return resEnergyUsage; } private ResourceAirFlowStats gatherResourceAirFlowStats(ComputingResource resource) { ResourceAirFlowStats resAirFlow = new ResourceAirFlowStats(resource.getName(), resource.getType(), "resourceAirFlowStats"); Map airFlow = resAirFlow.getHistory(); ExtensionList extensionList = resource.getExtensionList(); if(extensionList != null){ for (Extension extension : extensionList) { if (extension.getType() == ExtensionType.ENERGY_EXTENSION) { EnergyExtension ee = (EnergyExtension)extension; if(ee.getAirFlowProfile() == null) break; List airFlowHistory = ee.getAirFlowProfile().getAirThroughputHistory(); if(airFlowHistory.size() == 0) break; long endSimulationTime = DateTimeUtilsExt.currentTimeMillis(); airFlowHistory.add(new AirFlowValue(endSimulationTime, ee.getAirFlowProfile().getAirThroughputHistory().get(ee.getAirFlowProfile().getAirThroughputHistory().size()-1).getValue())); for(AirFlowValue af:airFlowHistory){ airFlow.put(af.getTimestamp(), af.getValue()); } } } } return resAirFlow; } private ResourceTemperatureStats gatherResourceTemperatureStats(ComputingResource resource) { ResourceTemperatureStats resTemperature = new ResourceTemperatureStats(resource.getName(), resource.getType(), "resourceTemperatureStats"); Map temperature = resTemperature.getHistory(); ExtensionList extensionList = resource.getExtensionList(); if(extensionList != null){ for (Extension extension : extensionList) { if (extension.getType() == ExtensionType.ENERGY_EXTENSION) { EnergyExtension ee = (EnergyExtension)extension; if(ee.getThermalProfile() == null) break; List temperatureHistory = ee.getThermalProfile().getTemperatureHistory(); if(temperatureHistory.size() == 0) break; long endSimulationTime = DateTimeUtilsExt.currentTimeMillis(); temperatureHistory.add(new TemperatureValue(endSimulationTime, ee.getThermalProfile().getTemperatureHistory().get(ee.getThermalProfile().getTemperatureHistory().size()-1).getValue())); for(TemperatureValue af: temperatureHistory){ temperature.put(af.getTimestamp(), af.getValue()); } } } } return resTemperature; } private void createResourceLoadDiagram(ResourceUsageStats resLoadStats) { for(Long key: resLoadStats.getHistory().keySet()){ Double value = resLoadStats.getHistory().get(key) * 100; resLoadStats.getHistory().put(key, value); } XYDataset dataset = createResourceChartDataSet(resLoadStats, startSimulationTime, endSimulationTime); List loadDiagram = resourceLoadDiagrams.get(resLoadStats.getResourceType()); if(loadDiagram == null){ loadDiagram = new ArrayList(); loadDiagram.add(dataset); resourceLoadDiagrams.put(resLoadStats.getResourceType(), loadDiagram); } else { loadDiagram.add(dataset); } } private void createResourceEnergyDiagramData(ResourceDynamicStats powerConsumptionStats) { XYDataset dataset = createResourceChartDataSet(powerConsumptionStats, startSimulationTime, endSimulationTime); List energyDiagramData = resourcePowerUsageDiagrams.get(powerConsumptionStats.getResourceType()); if(energyDiagramData == null){ energyDiagramData = new ArrayList(); energyDiagramData.add(dataset); resourcePowerUsageDiagrams.put(powerConsumptionStats.getResourceType(), energyDiagramData); } else { energyDiagramData.add(dataset); } } private void createResourceTemperatureDiagramData(ResourceDynamicStats temperatureStats) { XYDataset dataset = createResourceChartDataSet(temperatureStats, startSimulationTime, endSimulationTime); List temperatureDiagramData = resourceTemperatureDiagrams.get(temperatureStats.getResourceType()); if(temperatureDiagramData == null){ temperatureDiagramData = new ArrayList(); temperatureDiagramData.add(dataset); resourceTemperatureDiagrams.put(temperatureStats.getResourceType(), temperatureDiagramData); } else { temperatureDiagramData.add(dataset); } } private void createResourceAirFlowDiagramData(ResourceDynamicStats airFlowStats) { XYDataset dataset = createResourceChartDataSet(airFlowStats, startSimulationTime, endSimulationTime); List airFlowDiagramData = resourceAirFlowDiagrams.get(airFlowStats.getResourceType()); if(airFlowDiagramData == null){ airFlowDiagramData = new ArrayList(); airFlowDiagramData.add(dataset); resourceAirFlowDiagrams.put(airFlowStats.getResourceType(), airFlowDiagramData); } else { airFlowDiagramData.add(dataset); } } private XYDataset createResourceChartDataSet( ResourceDynamicStats dynamicStats, long start, long end) { Map chartData = getResourceChartRawData(dynamicStats); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries data = new XYSeries(dynamicStats.getResourceName(), false, true); data.add(start, 0); for (Long key : chartData.keySet()) { Double val = chartData.get(key); if(key >= startSimulationTime) data.add(key, val); } data.add(end, 0); dataset.addSeries(data); return dataset; } private Map getResourceChartRawData( ResourceDynamicStats dynamicStats) { Map history = dynamicStats.getHistory(); Map chartData = new TreeMap(); for (Long key : history.keySet()) { chartData.put(key, history.get(key)); } return chartData; } private boolean saveResourceGanttDiagrams() { if (!generateDiagrams) return false; String fileName = new File(outputFolderName, DIAGRAMS_FILE_NAME_PREFIX + simulationIdentifier + "_").getAbsolutePath(); String chartName = "Gantt diagram for " + DataCenterWorkloadSimulator.SIMULATOR_NAME; String simulationTime = "Simulation time"; Title subtitle = new TextTitle("created for \"" + simulationIdentifier + "\" at " + Calendar.getInstance().getTime().toString()); JFreeChart peDiagram = null; if (configuration.creatediagrams_gantt) { peDiagram = getPEGanttDiagram(chartName, subtitle, simulationTime); if (!saveCategoryChart(peDiagram, fileName + "Gantt", "{0}")) return false; } chartName = "Load diagram for " + DataCenterWorkloadSimulator.SIMULATOR_NAME; JFreeChart resourceLoadDiagram = null; if (configuration.creatediagrams_resutilization) { String axisName = "UTILIZATION [%]"; for(ResourceType resType: resourceLoadDiagrams.keySet()){ resourceLoadDiagram = getResourceDynamicDiagram(resourceLoadDiagrams.get(resType), simulationTime, chartName, subtitle, axisName); if (!saveXYPlotChart(resourceLoadDiagram, fileName + "Resources Load - "+resType.getName())) return false; } } chartName = "Energy usage diagram for " + DataCenterWorkloadSimulator.SIMULATOR_NAME; JFreeChart resourceEnergyDiagram = null; if (configuration.creatediagrams_respowerusage) { String axisName = "POWER [W]"; for(ResourceType resType: resourcePowerUsageDiagrams.keySet()){ resourceEnergyDiagram = getResourceDynamicDiagram(resourcePowerUsageDiagrams.get(resType), simulationTime, chartName, subtitle, axisName); if (!saveXYPlotChart(resourceEnergyDiagram, fileName + "Energy - "+resType.getName())) return false; } } chartName = "Air flow diagram for " + DataCenterWorkloadSimulator.SIMULATOR_NAME; JFreeChart resourceAirFlowDiagram = null; if (configuration.creatediagrams_resairflow) { String axisName = "AIR FLOW [m^3/min]"; for(ResourceType resType: resourceAirFlowDiagrams.keySet()){ resourceAirFlowDiagram = getResourceDynamicDiagram(resourceAirFlowDiagrams.get(resType), simulationTime, chartName, subtitle, axisName); if (!saveXYPlotChart(resourceAirFlowDiagram, fileName + "AirThroughput - "+resType.getName())) return false; } } chartName = "Temperature diagram for " + DataCenterWorkloadSimulator.SIMULATOR_NAME; JFreeChart resourceTemperatureDiagram = null; if (configuration.creatediagrams_restemperature) { String axisName = "TEMPERATURE [C]"; for(ResourceType resType: resourceTemperatureDiagrams.keySet()){ resourceTemperatureDiagram = getResourceDynamicDiagram(resourceTemperatureDiagrams.get(resType), simulationTime, chartName, subtitle, axisName); if (!saveXYPlotChart(resourceTemperatureDiagram, fileName + "Temperature - "+resType.getName())) return false; } } return true; } private JFreeChart getPEGanttDiagram(String chartName, Title subtitle, String simulationTime) { String processors = "Processing Elements"; boolean tooltip = true; boolean legend = true; JFreeChart chart = TimetableChartFactory.createTimetableChart( chartName, processors, simulationTime, ganttDiagramTimetable, legend, tooltip); chart.addSubtitle(subtitle); TimetableRenderer rend = (TimetableRenderer) chart.getCategoryPlot() .getRenderer(); rend.setBackgroundBarPaint(null); return chart; } private JFreeChart getResourceDynamicDiagram(List diagramData, String simulationTime, String chartName, Title subtitle, String axisName) { boolean urls = false; boolean tooltip = true; boolean legend = true; CombinedDomainXYPlot cPlot = new CombinedDomainXYPlot(); DateAxis xAxis = new DateAxis(simulationTime); JFreeChart chart = null; for (XYDataset dataset : diagramData) { JFreeChart tChart = ChartFactory.createXYStepAreaChart("", "", null, dataset, PlotOrientation.VERTICAL, legend, tooltip, urls); XYPlot tPlot = tChart.getXYPlot(); NumberAxis yAxis = new NumberAxis(axisName); yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); tPlot.setRangeAxis(yAxis); XYStepAreaRenderer rend = (XYStepAreaRenderer) tPlot.getRenderer(); rend.setShapesVisible(false); cPlot.add(tPlot); } cPlot.setDomainAxis(xAxis); cPlot.setDomainAxisLocation(AxisLocation.TOP_OR_LEFT); chart = new JFreeChart(chartName, cPlot); chart.addSubtitle(subtitle); return chart; } private boolean saveXYPlotChart(JFreeChart c, String fileName) { c.setNotify(false); c.setAntiAlias(true); c.setTextAntiAlias(true); c.setBorderVisible(false); int height = 900; CombinedDomainXYPlot cPlot = (CombinedDomainXYPlot) c.getPlot(); int nPlots = cPlot.getSubplots().size(); if (nPlots > 3) { height = nPlots * 300; } int width = GANTT_WIDTH; if (configuration.creatediagrams_resources_scale != -1) width = (int) ((endSimulationTime - startSimulationTime) * configuration.creatediagrams_resources_scale); ChartRenderingInfo info = new ChartRenderingInfo(); File f = new File(fileName + "." + ImageFormat.PNG); final String dcwormsSubtitle = "Created by " + DataCenterWorkloadSimulator.SIMULATOR_NAME + " http://www.gssim.org/"; c.addSubtitle(new TextTitle(dcwormsSubtitle)); boolean encodeAlpha = false; int compression = 9;// values 0-9 try { ChartUtilities.saveChartAsPNG(f, c, width, height, info, encodeAlpha, compression); } catch (IOException e) { e.printStackTrace(); return false; } return true; } private void createPEGanttDiagram(Map> basicResStats) { for(String peName: basicResStats.keySet()){ TimetableEventSource pe = new TimetableEventSource(peName); ganttDiagramTimetable.addEventSource(pe); peGanttMap.put(peName, pe); for(ResStat resStat: basicResStats.get(peName)){ pe = peGanttMap.get(resStat.getPeName()); if(pe == null){ //pe = new TimetableEventSource(resStat.getPeName()); // ganttDiagramPeTimetable.addEventSource(pe); // peGanttMap.put(resStat.getPeName(), pe); } TimetableEventGroup task = taskGanttMap.get(resStat.getTaskID()); long startDate = resStat.getStartDate(); long endDate = resStat.getEndDate(); if (task == null) { task = new TimetableEventGroup(resStat.getTaskID()); taskGanttMap.put(resStat.getTaskID(), task); ganttDiagramTimetable.addEventGroup(task); } ganttDiagramTimetable.addEvent(pe, task, new FixedMillisecond(startDate), new FixedMillisecond(endDate)); } } } //TO DO private void createAccumulatedResourceSimulationStatistic() { List resources = resourceController.getComputingResources(); for(ComputingResource compRes: resources){ //for(ComputingResource child :compRes.getChildren()){ //ResourceUsageStats resourceUsage = gatherResourceLoadStats(compRes, basicResStats); //double load = calculateMeanValue(resourceUsage); double load = calculateResourceLoad(compRes, basicResLoad); accStats.meanTotalLoad.add(load); /*ResourceEnergyStats energyUsage = gatherResourceEnergyStats(compRes); energyUsage.setMeanUsage(calculateEnergyLoad(energyUsage)); accStats.meanEnergyUsage.add(energyUsage.meanUsage);*/ //} } } private Map calculatePELoad(Map> basicResStats){ Map peLoad = new HashMap(); for(String resName: basicResStats.keySet()){ List resStats = basicResStats.get(resName); double sum = 0; for(ResStat resStat:resStats){ sum += (resStat.endDate - resStat.startDate); } double load = sum / (endSimulationTime - startSimulationTime); peLoad.put(resName, load); } return peLoad; } private Double calculateResourceLoad(ComputingResource resource, Map peLoad ){ int peCnt = 0; double sum = 0; for(String resName: peLoad.keySet()){ try { if(resource.getDescendantByName(resName) != null || resource.getName().compareTo(resName) == 0){ Double load = peLoad.get(resName); sum += load; peCnt++; } } catch (ResourceException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return sum/peCnt; } private double calculateMeanValue(ResourceDynamicStats resDynamicStats ){ double meanValue = 0; long time = -1; double value = 0; Map history = resDynamicStats.getHistory(); for (Long key : history.keySet()) { if(key >= startSimulationTime){ if (time != -1) { meanValue += (value * (key - time)) / (endSimulationTime - startSimulationTime); time = key; } else { time = key; } } value = history.get(key); } return meanValue; } /************* TASK STATISTICS SECTION **************/ public void gatherTaskStatistics() { List> jobs = users.getAllReceivedJobs(); Collections.sort(jobs, new JobIdComparator()); ganttDiagramTaskSeriesCollection = new TaskSeriesCollection(); ganttDiagramWaitingTimeSeriesCollection = new TaskSeriesCollection(); PrintStream taskStatsFile = null; try { File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_" + RAW_TASKS_STATISTICS_OUTPUT_FILE_NAME); taskStatsFile = new PrintStream(new FileOutputStream(file)); } catch (IOException e) { taskStatsFile = null; } PrintStream jobStatsFile = null; if (configuration.createjobsstatistics) { try { File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_" + JOBS_STATISTICS_OUTPUT_FILE_NAME); jobStatsFile = new PrintStream(new FileOutputStream(file)); } catch (IOException e) { jobStatsFile = null; } } for (int i = 0; i < jobs.size(); i++) { Job job = (Job) jobs.get(i); List execList = jr.getExecutableTasks().getJobExecutables(job.getId()); List taskStatsList = new ArrayList(); this.serializer.setFieldSeparator(TASK_SEPARATOR); for (int j = 0; j < execList.size(); j++) { Executable task = (Executable) execList.get(j); TaskStats taskStats = createTaskStats(task); if (taskStats != null && taskStatsFile != null) { Object txt = taskStats.serialize(serializer); taskStatsFile.println(txt); } if (taskStats != null && taskStats.getExecFinishDate() != -1) { if (configuration.createsimulationstatistics) { createAccumulatedTaskSimulationStatistic(taskStats); } allTasksFinished &= task.isFinished(); if (generateDiagrams) { if (configuration.creatediagrams_tasks) createTaskDiagramData(task); if (configuration.creatediagrams_taskswaitingtime) createTaskWaitingTimeDiagramData(task); } taskStatsList.add(taskStats); } } if (configuration.createjobsstatistics && taskStatsList.size() > 0) { this.serializer.setFieldSeparator(JOB_SEPARATOR); JobStats jobStats = createJobStats(taskStatsList); if (jobStatsFile != null) { Object txt = jobStats.serialize(serializer); jobStatsFile.println(txt); } } } if (configuration.createsimulationstatistics) { accStats.makespan.add(maxCj); accStats.delayedTasks.add(numOfdelayedTasks); accStats.failedRequests.add(users.getAllSentTasks().size() - users.getFinishedTasksCount()); if(resourceController.getScheduler().getType().getName().equals("GS")){ for(Scheduler sched: resourceController.getScheduler().getChildren()){ accStats.meanQueueLength.add(getSchedulerQueueStats(sched)); } } else { accStats.meanQueueLength.add(getSchedulerQueueStats(resourceController.getScheduler())); } } saveTaskGanttDiagrams(); if (taskStatsFile != null) { taskStatsFile.close(); } if (jobStatsFile != null) { jobStatsFile.close(); } } private double getSchedulerQueueStats(Scheduler scheduler) { Sim_stat stats = scheduler.get_stat(); List measures = stats.get_measures(); for (Object[] info : measures) { String measure = (String) info[0]; if (measure .startsWith(DCWormsConstants.TASKS_QUEUE_LENGTH_MEASURE_NAME)) { return stats.average(measure); } } return 0; } private TaskStats createTaskStats(Executable task) { TaskStats taskStats = new TaskStats(task, startSimulationTime); String uniqueTaskID = taskStats.getJobID() + "_" + taskStats.getTaskID(); taskStats.setProcessorsName(task_processorsMap.get(uniqueTaskID)); return taskStats; } private JobStats createJobStats(List tasksStats) { String jobID = ((TaskStats) tasksStats.get(0)).getJobID(); JobStats jobStats = new JobStats(jobID); double maxCj = 0; for (int i = 0; i < tasksStats.size(); i++) { TaskStats task = (TaskStats) tasksStats.get(i); jobStats.meanTaskStartTime.add(task.getStartTime()); jobStats.meanTaskCompletionTime.add(task.getCompletionTime()); maxCj = Math.max(maxCj, task.getCompletionTime()); jobStats.meanTaskExecutionTime.add(task.getExecutionTime()); jobStats.meanTaskWaitingTime.add(task.getWaitingTime()); jobStats.meanTaskFlowTime.add(task.getFlowTime()); jobStats.meanTaskGQ_WaitingTime.add(task.getGQ_WaitingTime()); jobStats.lateness.add(task.getLateness()); jobStats.tardiness.add(task.getTardiness()); } jobStats.makespan.add(maxCj); return jobStats; } private void createAccumulatedTaskSimulationStatistic(TaskStats taskStats) { accStats.meanTaskFlowTime.add(taskStats.getFlowTime()); accStats.meanTaskExecutionTime.add(taskStats.getExecutionTime()); accStats.meanTaskCompletionTime.add(taskStats.getCompletionTime()); accStats.meanTaskWaitingTime.add(taskStats.getWaitingTime()); accStats.meanTaskStartTime.add(taskStats.getStartTime()); accStats.lateness.add(taskStats.getLateness()); accStats.tardiness.add(taskStats.getTardiness()); if (taskStats.getExecFinishDate() == -1) { numOfNotExecutedTasks++; } if (taskStats.getTardiness() > 0.0) { numOfdelayedTasks++; } maxCj = Math.max(maxCj, taskStats.getCompletionTime()); } private void createTaskDiagramData(Executable task) { String uniqueTaskID = task.getJobId() + "_" + task.getId(); String resID = task.getSchedulerName(); long execStartTime = Double.valueOf(task.getExecStartTime()).longValue() * MILLI_SEC; long execEndTime = Double.valueOf(task.getFinishTime()).longValue() * MILLI_SEC; TaskSeries taskRes = ganttDiagramTaskSeriesCollection.getSeries(resID); if (taskRes == null) { taskRes = new TaskSeries(resID); ganttDiagramTaskSeriesCollection.add(taskRes); } org.jfree.data.gantt.Task ganttTask = new org.jfree.data.gantt.Task(uniqueTaskID, new Date(execStartTime), new Date(execEndTime)); if (!task.isFinished()) { ganttTask.setPercentComplete(1.0); } taskRes.add(ganttTask); } private void createTaskWaitingTimeDiagramData(Executable task) { String uniqueTaskID = task.getJobId() + "_" + task.getId(); String resID = task.getSchedulerName(); long execStartTime = Double.valueOf(task.getExecStartTime()).longValue() * MILLI_SEC; long execEndTime = Double.valueOf(task.getFinishTime()).longValue() * MILLI_SEC; TaskSeries waitRes = ganttDiagramWaitingTimeSeriesCollection.getSeries(resID); if (waitRes == null) { waitRes = new TaskSeries(resID); ganttDiagramWaitingTimeSeriesCollection.add(waitRes); } long sub = Double.valueOf(task.getSubmissionTime()).longValue() * MILLI_SEC; org.jfree.data.gantt.Task wait_exec = new org.jfree.data.gantt.Task(uniqueTaskID, new Date(sub), new Date( execEndTime)); org.jfree.data.gantt.Task exec = new org.jfree.data.gantt.Task(uniqueTaskID, new Date(execStartTime), new Date( execEndTime)); if (!task.isFinished()) { exec.setPercentComplete(1.0); } wait_exec.addSubtask(wait_exec); wait_exec.addSubtask(exec); waitRes.add(wait_exec); } private boolean saveTaskGanttDiagrams() { JFreeChart taskDiagram = null; JFreeChart waitingTimeDiagram = null; if (!generateDiagrams) return false; String fileName = new File(outputFolderName, DIAGRAMS_FILE_NAME_PREFIX + simulationIdentifier + "_") .getAbsolutePath(); String chartName = "Task diagram for " + DataCenterWorkloadSimulator.SIMULATOR_NAME; String simulationTime = "Simulation time"; Title subtitle = new TextTitle("created for \"" + simulationIdentifier + "\" at " + Calendar.getInstance().getTime().toString()); if (configuration.creatediagrams_tasks) { taskDiagram = getTaskDiagram(chartName, subtitle, simulationTime); if (!saveCategoryChart(taskDiagram, fileName + "Tasks", null /* "{0}" */)) return false; } chartName = "Task waiting times diagram for " + DataCenterWorkloadSimulator.SIMULATOR_NAME; if (configuration.creatediagrams_taskswaitingtime) { waitingTimeDiagram = getWaitingTimeDiagram(chartName, subtitle, simulationTime); if (!saveCategoryChart(waitingTimeDiagram, fileName + "Waiting_Time", null /* "Task {1} at {0}" */)) return false; } return true; } private JFreeChart getTaskDiagram(String chartName, Title subtitle, String simulationTime) { String tasks = "Tasks"; boolean urls = false; boolean tooltip = true; boolean legend = true; JFreeChart chart = ChartFactory.createGanttChart(chartName, tasks, simulationTime, ganttDiagramTaskSeriesCollection, legend, tooltip, urls); chart.addSubtitle(subtitle); GanttRenderer re = (GanttRenderer) chart.getCategoryPlot().getRenderer(); re.setCompletePaint(Color.black); return chart; } private JFreeChart getWaitingTimeDiagram(String chartName, Title subtitle, String simulationTime) { String tasks = "Tasks"; boolean urls = false; boolean tooltip = true; boolean legend = true; JFreeChart chart = ChartFactory.createGanttChart(chartName, tasks, simulationTime, ganttDiagramWaitingTimeSeriesCollection, legend, tooltip, urls); chart.addSubtitle(subtitle); chart.getPlot().setForegroundAlpha(ALPHA); GanttRenderer re = (GanttRenderer) chart.getCategoryPlot().getRenderer(); re.setCompletePaint(Color.black); return chart; } private boolean saveCategoryChart(JFreeChart c, String fileName, String labelFormat) { c.setNotify(false); c.setAntiAlias(true); c.setTextAntiAlias(true); c.setBorderVisible(false); CategoryPlot categoryplot = (CategoryPlot) c.getPlot(); categoryplot.setDomainGridlinesVisible(true); if (labelFormat != null) { CategoryItemRenderer rend = categoryplot.getRenderer(); rend.setBaseItemLabelsVisible(true); ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER); rend.setBasePositiveItemLabelPosition(position); NumberFormat nf = NumberFormat.getInstance(); CategoryItemLabelGenerator gen = new StandardCategoryItemLabelGenerator(labelFormat, nf); rend.setBaseItemLabelGenerator(gen); } int rows = c.getCategoryPlot().getDataset().getColumnKeys().size(); int height = 900; if (rows > 45) { height = rows * 20; } int width = calculateChartWidth(c); CategoryItemRenderer rend = c.getCategoryPlot().getRenderer(); for (int i = 0; i < c.getCategoryPlot().getDataset().getRowKeys().size(); i++) { Paint collor = c.getCategoryPlot().getDrawingSupplier().getNextPaint(); rend.setSeriesOutlinePaint(i, collor); rend.setSeriesPaint(i, collor); } ChartRenderingInfo info = new ChartRenderingInfo(); // info.setEntityCollection(null); File f = new File(fileName + "." + ImageFormat.PNG); final String dcwormsSubtitle = "Created by " + DataCenterWorkloadSimulator.SIMULATOR_NAME + " http://www.gssim.org/"; c.addSubtitle(new TextTitle(dcwormsSubtitle)); boolean encodeAlpha = false; int compression = 9; try { ChartUtilities.saveChartAsPNG(f, c, width, height, info, encodeAlpha, compression); } catch (IOException e) { e.printStackTrace(); return false; } catch (Exception e) { if (log.isErrorEnabled()) log.error("The png file (" + fileName + ")\nwill not be generated (It can be too large data size problem)", e); } catch (Throwable t) { log.error("The png file (" + fileName + ")\nwill not be generated (It can be too large data size problem)", t); } return true; } private int calculateChartWidth(JFreeChart c) { int ganttWidth = GANTT_WIDTH; int rows = c.getCategoryPlot().getDataset().getColumnKeys().size(); if (rows > 45) { int height = rows * 20; ganttWidth = Math.max((int) (height * 1.5), GANTT_WIDTH); } return ganttWidth; } private static class JobIdComparator implements Comparator> { public int compare(JobInterface o1, JobInterface o2) { Integer o1int; Integer o2int; try{ o1int = Integer.parseInt(o1.getId()); o2int = Integer.parseInt(o2.getId()); return o1int.compareTo(o2int); } catch(NumberFormatException e){ return o1.getId().compareTo(o2.getId()); } } } private static class MapPEIdComparator implements Comparator { public int compare(String o1, String o2) { Integer o1int; Integer o2int; String o1string; String o2string; o1string = o1.substring(0, o1.indexOf("_")); o2string = o2.substring(0, o2.indexOf("_")); o1int = Integer.parseInt(o1.substring(o1.indexOf("_")+1)); o2int = Integer.parseInt(o2.substring(o2.indexOf("_")+1)); if(o1string.compareTo(o2string) != 0) return o1string.compareTo(o2string); else return o1int.compareTo(o2int); } } public GSSAccumulator getStats(String name) { return statsData.get(name); } public boolean accumulatedStats() { return configuration.createsimulationstatistics; } } class ResStat{ public long getStartDate() { return startDate; } public void setStartDate(long startDate) { this.startDate = startDate; } public long getEndDate() { return endDate; } public void setEndDate(long endDate) { this.endDate = endDate; } public String getTaskID() { return taskID; } public void setTaskID(String taskID) { this.taskID = taskID; } public ResStat( String peName, long startDate, long endDate, String taskID) { super(); this.startDate = startDate; this.endDate = endDate; this.taskID = taskID; this.peName = peName; } public String getPeName() { return peName; } public void setPeName(String peName) { this.peName = peName; } public ResStat(String peName, ResourceType resType, long startDate, long endDate, String taskID) { super(); this.peName = peName; this.resType = resType; this.startDate = startDate; this.endDate = endDate; this.taskID = taskID; } String peName; ResourceType resType; long startDate; long endDate; String taskID; public ResourceType getResType() { return resType; } public void setResType(ResourceType resType) { this.resType = resType; } } enum Stats{ textLoad, chartLoad, textEnergy, chartEnergy, textAirFlow, chartAirFlow, textTemperature, chartTemperature; }