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.DecimalFormat; 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.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; 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.SimulatedEnvironment; import schedframe.resources.CustomResourceType; import schedframe.resources.ResourceType; 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.MeasurementHistory; 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.computing.profiles.load.LoadExtension; import schedframe.resources.devices.Device; import schedframe.resources.devices.PhysicalResource; import schedframe.resources.units.ProcessingElements; import schedframe.resources.units.ResourceUnit; import schedframe.resources.units.ResourceUnitName; import schedframe.resources.units.StandardResourceUnitName; import schedframe.scheduling.ExecutionHistoryItem; import schedframe.scheduling.ResourceItem; 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.CoolEmAllMetricsCalculator; import simulator.stats.DCwormsAccumulator; import simulator.stats.DCwormsMetricsCalculator; import simulator.stats.MetricsCalculator; import simulator.stats.SimulationStatistics; import simulator.stats.implementation.out.CoolEmAllStringSerializer; 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; import example.energy.coolemall.CoolEmAllTestbedMeasurements; import gridsim.dcworms.DCWormsTags; 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 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 RESOURCEOCCUPANCY_STATISTICS_OUTPUT_FILE_NAME = "ResourceOccupancy.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 = "Airflow.txt"; protected static final String TEMPERATURE_STATISTICS_OUTPUT_FILE_NAME = "Temperature.txt"; protected static final String USEFUL_WORK_STATISTICS_OUTPUT_FILE_NAME = "UsefulWork.txt"; protected static final String DEVICE_STATISTICS_OUTPUT_FILE_NAME = "Devices.txt"; protected static final String NODES_AVAILABILITY_STATISTICS_OUTPUT_FILE_NAME = "NodesAvailability.txt"; protected static final String METRICS_STATISTICS_OUTPUT_FILE_NAME = "Metrics.txt"; protected static final String RESOURCE_HISTORY_OUTPUT_FILE_NAME = "ResourceHistyory.txt"; protected static final String DIAGRAMS_FILE_NAME_PREFIX = "Chart_"; protected static final String STATS_FILE_NAME_PREFIX = "Stats_"; protected static final String SEPARATOR = ";"; protected String outputFolderName; protected String simulationIdentifier; protected ConfigurationOptions configuration; protected GSSAccumulatorsStats accStats; protected Map statsData; protected GenericUser users; protected SimulatedEnvironment resourceController; protected boolean generateDiagrams = true; protected StringSerializer serializer; protected long startSimulationTime; protected long endSimulationTime; //RESOURCES protected Map> peStats; protected Timetable ganttDiagramTimetable; protected Map> resourcePowerUsageDiagrams; protected Map> resourceAirflowDiagrams; protected Map> resourceTemperatureDiagrams; protected Map> resourceOccupancyDiagrams; protected Map> resourceUtilizationDiagrams; //TASKS protected int numOfdelayedTasks = 0; protected int numOfNotExecutedTasks = 0; protected double maxCj = 0; protected boolean allTasksFinished; protected TaskSeriesCollection ganttDiagramTaskSeriesCollection; protected TaskSeriesCollection ganttDiagramWaitingTimeSeriesCollection; protected Map> taskToPEMap; protected JobRegistry jobRegistry; protected MetricsCalculator metCalc; public DCWormsStatistics(String simulationIdentifier, ConfigurationOptions co, GenericUser users, String outputFolderName, SimulatedEnvironment resourceController) { this.simulationIdentifier = simulationIdentifier; this.configuration = co; this.users = users; this.outputFolderName = outputFolderName; this.resourceController = resourceController; this.jobRegistry = new JobRegistryImpl(); if(users.isSimStartTimeDefined()) this.startSimulationTime = DateTimeUtilsExt.getOffsetTime().getTimeInMillis(); else this.startSimulationTime = new DateTime(users.getSubmissionStartTime() * 1000l).getMillis(); this.endSimulationTime = DateTimeUtilsExt.currentTimeMillis(); init(); } private void init() { taskToPEMap = new HashMap>(jobRegistry.getFinishedTasks().size()); statsData = new HashMap(2); accStats = new GSSAccumulatorsStats(); this.serializer = new StringSerializer(); this.metCalc = new DCwormsMetricsCalculator(startSimulationTime, endSimulationTime, endSimulationTime); if(DataCenterWorkloadSimulator.MODE.equals("CoolEmAll")){ this.serializer = new CoolEmAllStringSerializer(); this.metCalc = new CoolEmAllMetricsCalculator(startSimulationTime, endSimulationTime, endSimulationTime); } this.serializer.setDefaultNumberFormat(DataCenterWorkloadSimulator.DFAULT_NUMBER_FORMAT); } public void generateStatistics() { 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; } 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); DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(3); df.setGroupingUsed(false); /*log.info("#STATS " + "Performance statistics"); log.info("#STATS " + "Makespan: " + accStats.makespan.getMean() + " [s]"); log.info("#STATS " + "Task completion time - " + "min: " + accStats.meanTaskCompletionTime.getMin() + "; max: " + accStats.meanTaskCompletionTime.getMax() + " [s]"); log.info("#STATS " + "Mean task execution time: " + accStats.meanTaskExecutionTime.getMean() + " [s]"); log.info("#STATS " + "System load: " + accStats.meanTotalLoad.getMean() * 100 + " [%]");*/ System.out.println("#STATS " + "===== Performance statistics ====="); System.out.println("#STATS " + "Makespan: " + df.format(accStats.makespan.getMean()) + " [s]"); System.out.println("#STATS " + "Task completion time - " + "min: " + df.format(accStats.meanTaskCompletionTime.getMin()) + " [s]" + "; max: " + df.format(accStats.meanTaskCompletionTime.getMax()) + " [s]" + "; mean: " + df.format(accStats.meanTaskCompletionTime.getMean()) + " [s]"); System.out.println("#STATS " + "Mean task execution time: " + df.format(accStats.meanTaskExecutionTime.getMean()) + " [s]"); System.out.println("#STATS " + "System occupancy: " + df.format(accStats.meanTotalOccupancy.getMean() * 100) + " [%]"); System.out.println("#STATS " + "System load: " + df.format(accStats.meanTotalLoad.getMean() * 100) + " [%]"); simulationStatsFile.println(txt); } if (simulationStatsFile != null) { simulationStatsFile.close(); } } /************* RESOURCE STATISTICS SECTION **************/ public void gatherResourceStatistics() { HashMap> type_stats = new HashMap>(); for(String resourceTypeName: resourceController.getComputingResourceLayers()){ List cStats = new ArrayList(); /*if(ArrayUtils.contains(configuration.compResForUtilizationText, resourceTypeName)) cStats.add(Stats.textLoad); if(ArrayUtils.contains(configuration.compResForEnergyText, resourceTypeName)) cStats.add(Stats.textEnergy); if(ArrayUtils.contains(configuration.compResForAirflowText, resourceTypeName)) cStats.add(Stats.textAirFlow); if(ArrayUtils.contains(configuration.compResForTemperatureText, resourceTypeName)) cStats.add(Stats.textTemperature);*/ cStats.add(Stats.textLoad); if(ArrayUtils.contains(configuration.compResForUtilizationChart, resourceTypeName)) cStats.add(Stats.chartLoad); cStats.add(Stats.textEnergy); if(ArrayUtils.contains(configuration.compResForEnergyChart, resourceTypeName)) cStats.add(Stats.chartEnergy); cStats.add(Stats.textAirflow); if(ArrayUtils.contains(configuration.compResForAirflowChart, resourceTypeName)) cStats.add(Stats.chartAirflow); cStats.add(Stats.textTemperature); if(ArrayUtils.contains(configuration.compResForTemperatureChart, resourceTypeName)) cStats.add(Stats.chartTemperature); type_stats.put(resourceTypeName, cStats); } resourceOccupancyDiagrams = new HashMap>(2); resourceUtilizationDiagrams = new HashMap>(2); resourcePowerUsageDiagrams = new HashMap>(2); resourceAirflowDiagrams = new HashMap>(2); resourceTemperatureDiagrams = new HashMap>(2); ganttDiagramTimetable = new Timetable(new FixedMillisecond( startSimulationTime), new FixedMillisecond(endSimulationTime)); PrintStream resourceOccupancyStatsFile = null; try { File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_" + RESOURCEOCCUPANCY_STATISTICS_OUTPUT_FILE_NAME); resourceOccupancyStatsFile = new PrintStream(new FileOutputStream(file)); } catch (IOException e) { resourceOccupancyStatsFile = null; } PrintStream resourceUtilizationStatsFile = null; try { File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_" + RESOURCEUTILIZATION_STATISTICS_OUTPUT_FILE_NAME); resourceUtilizationStatsFile = new PrintStream(new FileOutputStream(file)); } catch (IOException e) { resourceUtilizationStatsFile = 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; } PrintStream deviceStatsFile = null; try { File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_" + DEVICE_STATISTICS_OUTPUT_FILE_NAME); deviceStatsFile = new PrintStream(new FileOutputStream(file)); } catch (IOException e) { deviceStatsFile = null; } /*PrintStream nodesAvailabilityStatsFile = null; try { File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_" + NODES_AVAILABILITY_STATISTICS_OUTPUT_FILE_NAME); nodesAvailabilityStatsFile = new PrintStream(new FileOutputStream(file)); } catch (IOException e) { nodesAvailabilityStatsFile = null; }*/ PrintStream metricsStatsFile = null; try { File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_" + METRICS_STATISTICS_OUTPUT_FILE_NAME); metricsStatsFile = new PrintStream(new FileOutputStream(file)); } catch (IOException e) { metricsStatsFile = null; } PrintStream usefulWorkStatsFile = null; try { File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_" + USEFUL_WORK_STATISTICS_OUTPUT_FILE_NAME); usefulWorkStatsFile = new PrintStream(new FileOutputStream(file)); } catch (IOException e) { usefulWorkStatsFile = null; } peStats = gatherPEStatsMulti(jobRegistry.getTasks()); peStatsPostProcessing(peStats); if (configuration.creatediagrams_gantt) { createGanttDiagram(peStats); } for(String resourceTypeName: resourceController.getComputingResourceLayers()){ DCwormsAccumulator resourceEnergyAccumulator = new DCwormsAccumulator(); DCwormsAccumulator maxResourceEnergyAccumulator = new DCwormsAccumulator(); DCwormsAccumulator calculationsEnergyAccumulator = new DCwormsAccumulator(); //DCwormsAccumulator tempAboveThresholdAccumulator = new DCwormsAccumulator(); //DCwormsAccumulator tempAboveThresholdAccumulatorH = new DCwormsAccumulator(); List compResources = new ArrayList(); for(ComputingResource compRes: resourceController.getComputingResources() ){ compResources.addAll(compRes.getDescendantsByType(new CustomResourceType(resourceTypeName))); } if(resourceController.getComputingResources().get(0).getType().getName().equals(resourceTypeName)) compResources.addAll(resourceController.getComputingResources()); if(type_stats.containsKey(resourceTypeName)){ for(ComputingResource compResource: compResources){ ResourceUsageStats resourceUtilization = null; ResourceUsageStats resourceOccupancy = null; ResourcePowerStats energyUsage = null; ResourceAirflowStats airflow = null; ResourceTemperatureStats temperature = null; ResourceUsefulWorkStats usefulWork = null; if(type_stats.get(resourceTypeName).contains(Stats.textLoad)){ resourceOccupancy = gatherResourceOccupancyStats(compResource, peStats); resourceOccupancy.setMeanValue(calculateMeanValue(resourceOccupancy)); if (resourceOccupancyStatsFile != null) { Object txt = resourceOccupancy.serialize(serializer); resourceOccupancyStatsFile.print(txt); } resourceUtilization = gatherResourceUtlizationStats(compResource); resourceUtilization.setMeanValue(calculateMeanValue(resourceUtilization)); if (resourceUtilizationStatsFile != null) { Object txt = resourceUtilization.serialize(serializer); resourceUtilizationStatsFile.print(txt); } } if(type_stats.get(resourceTypeName).contains(Stats.chartLoad)){ if (configuration.creatediagrams_resutilization) { createResourceOccupancyDiagram(resourceOccupancy); createResourceUtilizationDiagram(resourceUtilization); } } if(type_stats.get(resourceTypeName).contains(Stats.textEnergy)){ energyUsage = gatherResourcePowerConsumptionStats(compResource); energyUsage.setMeanValue(calculateMeanValue(energyUsage)); energyUsage.setSumValue(energyUsage.getMeanValue() * (endSimulationTime - startSimulationTime) / (3600 * MILLI_SEC)); resourceEnergyAccumulator.add(energyUsage.getSumValue()); maxResourceEnergyAccumulator.add(calculateMaxValue(energyUsage)); double calculationsEnergy = 0; try { boolean doCalc = false; double load = 0; long prevTimestamp = 0; for(Long key: energyUsage.getHistory().keySet()){ if(doCalc){ if(resourceTypeName.equals("Rack")){ calculationsEnergy = calculationsEnergy + CoolEmAllTestbedMeasurements.OTHER_DEVICES_POWER_CONSUMPTION * (key - prevTimestamp) /(3600.0 * MILLI_SEC); }/* else if(resourceTypeName.equals("Processor")){ Processor proc =( Processor) compResource; double maxPower = proc.getPowerInterface().getLowestPState().getLoadPowerUsage().get(100.0); calculationsEnergy = calculationsEnergy + load * maxPower * (key - prevTimestamp) /(3600.0 * MILLI_SEC); }*/ else calculationsEnergy = calculationsEnergy + load * energyUsage.getHistory().get(prevTimestamp) * (key - prevTimestamp) /(3600.0 * MILLI_SEC); doCalc = false; load = 0; } if(resourceUtilization.getHistory().get(key) != null){ load = resourceUtilization.getHistory().get(key); if(load > 0 ){ doCalc = true; prevTimestamp = key; } } } calculationsEnergyAccumulator.add(calculationsEnergy); } catch (Exception e) { e.printStackTrace(); } EnergyExtension een = (EnergyExtension)(compResource.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); if(resourceController.getComputingResources().contains(compResource)) { 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 = compResource.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.print(txt); } for(Device device: compResource.getResourceCharacteristic().getDevices()){ DCwormsAccumulator devAccumulator = new DCwormsAccumulator(); ResourcePowerStats deviceEnergyUsage = gatherResourcePowerConsumptionStats(device); deviceEnergyUsage.setMeanValue(calculateMeanValue(deviceEnergyUsage)); deviceEnergyUsage.setSumValue(deviceEnergyUsage.getMeanValue() * (endSimulationTime - startSimulationTime) / (3600 * MILLI_SEC)); devAccumulator.add(deviceEnergyUsage.getSumValue()); //TODO - type and name may be the same (results are 2 times bigger) metCalc.addMetricsData(device.getType().getName(), devAccumulator); metCalc.addMetricsData(device.getFullName(), devAccumulator); if (deviceStatsFile != null) { Object txt = deviceEnergyUsage.serialize(serializer); deviceStatsFile.print(txt); } if(ArrayUtils.contains(configuration.compResForEnergyChart, device.getType().getName())){ if (configuration.creatediagrams_respowerusage) { createResourceEnergyDiagramData(deviceEnergyUsage); } } } } if(type_stats.get(resourceTypeName).contains(Stats.chartEnergy)){ if (configuration.creatediagrams_respowerusage) { createResourceEnergyDiagramData(energyUsage); } } if(type_stats.get(resourceTypeName).contains(Stats.textAirflow)){ airflow = gatherResourceAirflowStats(compResource); airflow.setMeanValue(calculateMeanValue(airflow)); airflow.setSumValue(airflow.getMeanValue() * (endSimulationTime - startSimulationTime) / (60 * MILLI_SEC)); EnergyExtension een = (EnergyExtension)(compResource.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); if(resourceController.getComputingResources().contains(compResource)) { if( een != null && een.getAirflowProfile() != null && een.getPowerProfile().getEnergyEstimationPlugin() != null){ accStats.meanAirflow.add(airflow.getMeanValue()); } } else if( een != null && een.getAirflowProfile() != null ){ ComputingResource parent = compResource.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.getMeanValue()); } } if (airflowStatsFile != null) { Object txt = airflow.serialize(serializer); airflowStatsFile.print(txt); } for(Device device: compResource.getResourceCharacteristic().getDevices()){ ResourceAirflowStats deviceAirflow = gatherResourceAirflowStats(device); deviceAirflow.setMeanValue(calculateMeanValue(deviceAirflow)); deviceAirflow.setSumValue(deviceAirflow.getMeanValue() * (endSimulationTime - startSimulationTime) / (60 * MILLI_SEC)); if (deviceStatsFile != null) { Object txt = deviceAirflow.serialize(serializer); deviceStatsFile.print(txt); } if(ArrayUtils.contains(configuration.compResForAirflowChart, device.getType().getName())){ if (configuration.creatediagrams_resairflow) { createResourceAirflowDiagramData(deviceAirflow); } } } } if(type_stats.get(resourceTypeName).contains(Stats.chartAirflow)){ if (configuration.creatediagrams_resairflow) { createResourceAirflowDiagramData(airflow); } } if(type_stats.get(resourceTypeName).contains(Stats.textTemperature)){ temperature = gatherResourceTemperatureStats(compResource); temperature.setMeanValue(calculateMeanValue(temperature)); temperature.setSumValue(temperature.getMeanValue() * (endSimulationTime - startSimulationTime) / (3600 * MILLI_SEC)); /*if(resourceTypeName.equals("Processor")){ tempAboveThresholdAccumulator.add(calculateTempExcTime(temperature)); tempAboveThresholdAccumulatorH.add(calculateTempExcTimeH(temperature)); }*/ EnergyExtension een = (EnergyExtension)(compResource.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); if(resourceController.getComputingResources().contains(compResource)) { if( een != null && een.getThermalProfile() != null && een.getPowerProfile().getEnergyEstimationPlugin() != null){ accStats.meanTemperature.add(temperature.getMeanValue()); } } else if( een != null && een.getThermalProfile() != null ){ ComputingResource parent = compResource.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.getMeanValue()); } } if (temperatureStatsFile != null) { Object txt = temperature.serialize(serializer); temperatureStatsFile.print(txt); } for(Device device: compResource.getResourceCharacteristic().getDevices()){ ResourceTemperatureStats deviceTemperature = gatherResourceTemperatureStats(device); deviceTemperature.setMeanValue(calculateMeanValue(deviceTemperature)); deviceTemperature.setSumValue(deviceTemperature.getMeanValue() * (endSimulationTime - startSimulationTime) / (3600 * MILLI_SEC)); if (deviceStatsFile != null) { Object txt = deviceTemperature.serialize(serializer); deviceStatsFile.print(txt); } if(ArrayUtils.contains(configuration.compResForTemperatureChart, device.getType().getName())){ if (configuration.creatediagrams_restemperature) { createResourceTemperatureDiagramData(deviceTemperature); } } } } if(type_stats.get(resourceTypeName).contains(Stats.chartTemperature)){ if (configuration.creatediagrams_restemperature) { createResourceTemperatureDiagramData(temperature); } } if(type_stats.get(resourceTypeName).contains(Stats.textLoad)){ usefulWork = gatherResourceUsefulWorkStats(compResource); if (usefulWorkStatsFile != null) { Object txt = usefulWork.serialize(serializer); usefulWorkStatsFile.print(txt); } } /*if (nodesAvailabilityStatsFile != null) { ResourceAvailabilityStats ras = new ResourceAvailabilityStats(compResource.getFullName(), compResource.getType(), "availableNodes", compResource.getChildren().size(), endSimulationTime); Object txt = ras.serialize(serializer); nodesAvailabilityStatsFile.print(txt); ras = gatherResourceAvailabilityStats(compResource); txt = ras.serialize(serializer); nodesAvailabilityStatsFile.print(txt); }*/ } metCalc.addMetricsData(resourceTypeName + "_CALC", calculationsEnergyAccumulator); metCalc.addMetricsData(resourceTypeName, resourceEnergyAccumulator); metCalc.addMetricsData(resourceTypeName + "_MAX", maxResourceEnergyAccumulator); /*if(resourceTypeName.equals("Processor")){ metCalc.addMetricsData(resourceTypeName + "_TEMPEXC", tempAboveThresholdAccumulator); metCalc.addMetricsData(resourceTypeName + "_TEMPHEXC", tempAboveThresholdAccumulatorH); }*/ } } if (metricsStatsFile != null) { //log.info("#STATS " + "Metrics"); System.out.println("#STATS " + "===== Metrics ====="); for(MetricsStats metric: metCalc.calulateMetrics()){ Object txt = metric.serialize(serializer); //log.info("#STATS " + metric.getResourceName() + " " + metric.getMetricName() + ": " + metric.getValue()); DecimalFormat df = new DecimalFormat(); df.setMaximumFractionDigits(3); df.setGroupingUsed(false); System.out.println("#STATS " + metric.getMetricName().replaceAll("_", " ") + ": " + df.format(metric.getValue()) + " [" + metric.getUnit() + "]"); metricsStatsFile.println(txt); } } saveResourceDiagrams(); createAccumulatedResourceSimulationStatistic(); if (temperatureStatsFile != null) { temperatureStatsFile.close(); } if (airflowStatsFile != null) { airflowStatsFile.close(); } if (energyStatsFile != null) { energyStatsFile.close(); } if (resourceOccupancyStatsFile != null) { resourceOccupancyStatsFile.close(); } if (resourceUtilizationStatsFile != null) { resourceUtilizationStatsFile.close(); } if (usefulWorkStatsFile != null) { usefulWorkStatsFile.close(); } if (deviceStatsFile != null) { deviceStatsFile.close(); } /*if (nodesAvailabilityStatsFile != null) { nodesAvailabilityStatsFile.close(); }*/ if (metricsStatsFile != null) { metricsStatsFile.close(); } } /*private double calculateTempExcTime(ResourceTemperatureStats temperature) { double overall = 0; long prevt = 0; //double prevTemp; boolean exceeded = false; for(Long t: temperature.getHistory().keySet()){ if(exceeded){ overall = overall + (t - prevt); exceeded = false; } double temp = temperature.getHistory().get(t); if(temp > EnvironmentConditions.i5_statsTThres){ prevt = t; exceeded = true; //prevTemp = temp; } } return overall; } private double calculateTempExcTimeH(ResourceTemperatureStats temperature) { double overall = 0; long prevt = 0; //double prevTemp; boolean exceeded = false; for(Long t: temperature.getHistory().keySet()){ if(exceeded){ overall = overall + (t - prevt); exceeded = false; } double temp = temperature.getHistory().get(t); if(temp > EnvironmentConditions.i5_statsTThresH){ prevt = t; exceeded = true; //prevTemp = temp; } } return overall; }*/ private void peStatsPostProcessing(Map> basicResStats){ ResourceType resType = null; for(ComputingResource pe: basicResStats.keySet()){ List resStats = basicResStats.get(pe); 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)){ basicResStats.put(resource, new ArrayList()); } } } //TO DELETE /*private Map> gatherPEStats(ExecutablesList executables) { Map> basicResStats = new TreeMap>(new peIdComparator()); for (ExecTask execTask:executables) { Executable exec = (Executable) execTask; LinkedList resourceHistory = exec.getAllocatedResources(); if(resourceHistory.size() == 0) continue; Map res = exec.getAllocatedResources().getLast().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.getFullName(); long startDate = Double.valueOf(exec.getExecStartTime()).longValue() * MILLI_SEC; long endDate = Double.valueOf(exec.getFinishTime()).longValue() * MILLI_SEC; String appID = getAppId(execTask); ResStat resStat = new ResStat(peName, pe.getType(), startDate, endDate, appID); List resStats = basicResStats.get(pe); if (resStats == null) { resStats = new ArrayList(); resStats.add(resStat); basicResStats.put(pe, resStats); } else { resStats.add(resStat); } String uniqueTaskID = getUniqueTaskId(execTask); Set peNames = taskToPEMap.get(uniqueTaskID); if (peNames == null) { peNames = new HashSet(); peNames.add(pe); taskToPEMap.put(uniqueTaskID, peNames); } else { peNames.add(pe); } try{ double usefulWork = execTask.getExecutionProfile().getUsefulWork()/pes.size(); //double usefulWork = gatherUsefulWorkStats(pe).getValue(); DCwormsAccumulator uwAcc; if(metCalc.getMetricsData().containsKey("UW_" + pe.getFullName())){ uwAcc = metCalc.getMetricsData().get("UW_" + pe.getFullName()).get(0); uwAcc.add(usefulWork); } else { uwAcc = new DCwormsAccumulator(); uwAcc.add(usefulWork); metCalc.addMetricsData("UW_" + pe.getFullName(), uwAcc); } } catch (Exception e){ } } } } return basicResStats; }*/ private Map> gatherPEStatsMulti(ExecutablesList executables) { Map> basicResStats = new TreeMap>(new peIdComparator()); for (ExecTask execTask:executables) { Executable exec = (Executable) execTask; LinkedList resourceHistory = exec.getAllocatedResources(); if(resourceHistory.size() == 0) continue; for(int i = 0; i < resourceHistory.size(); i++){ ResourceItem resHistItem = resourceHistory.get(i); Map res = resHistItem.getResourceUnits(); ResourceUnit resUnit = res.get(StandardResourceUnitName.PE); //ProcessingElements pes = (ProcessingElements) resUnit ; LinkedList execHistory = exec.getExecutionHistory(); long st = -1, et; for(int j = 0; j < execHistory .size(); j++){ ExecutionHistoryItem execHistItem = execHistory.get(j); if(execHistItem.getStatus() == DCWormsTags.PAUSED || execHistItem.getResIndex() != i){ continue; } if(st == -1){ st = execHistItem.getTimeStamp(); } if(j < execHistory.size() - 1 && (execHistory.get(j + 1).getResIndex() != execHistItem.getResIndex() || execHistory.get(j + 1).getStatus() == DCWormsTags.PAUSED) || j + 1 == execHistory.size()){ if(j < execHistory.size() -1 && (execHistory.get(j + 1).getResIndex() != execHistItem.getResIndex() || execHistory.get(j + 1).getStatus() == DCWormsTags.PAUSED)) et = execHistory.get(j + 1).getTimeStamp(); else et = Double.valueOf(exec.getFinishTime()).longValue() * MILLI_SEC; if(resUnit instanceof ProcessingElements){ ProcessingElements pes = (ProcessingElements) resUnit; for(ComputingResource pe: pes){ String peName = pe.getFullName(); long startDate = st; long endDate; if(i == resourceHistory.size() - 1){ endDate = Double.valueOf(exec.getFinishTime()).longValue() * MILLI_SEC; }else { endDate = et; } String appID = getAppId(execTask); ResStat resStat = new ResStat(peName, pe.getType(), startDate, endDate, appID); List resStats = basicResStats.get(pe); if (resStats == null) { resStats = new ArrayList(); resStats.add(resStat); basicResStats.put(pe, resStats); } else { resStats.add(resStat); } String uniqueTaskID = getUniqueTaskId(execTask); Set peNames = taskToPEMap.get(uniqueTaskID); if (peNames == null) { peNames = new HashSet(); peNames.add(pe); taskToPEMap.put(uniqueTaskID, peNames); } else { peNames.add(pe); } try{ double usefulWork = execTask.getExecutionProfile().getUsefulWork()/pes.size(); usefulWork = ((et - st) / (1000 * getExecutionTime(execTask))) * usefulWork; DCwormsAccumulator uwAcc; if(metCalc.getMetricsData().containsKey("UW_" + pe.getFullName())){ uwAcc = metCalc.getMetricsData().get("UW_" + pe.getFullName()).get(0); uwAcc.add(usefulWork); } else { uwAcc = new DCwormsAccumulator(); uwAcc.add(usefulWork); metCalc.addMetricsData("UW_" + pe.getFullName(), uwAcc); } } catch (Exception e){ } } } st = -1; } } } } return basicResStats; } private double getExecutionTime(ExecTask execTask) { double executionTime = 0; long previousTimestamp = 0; int previousStatus = DCWormsTags.CREATED; for(ExecutionHistoryItem execHistItem: execTask.getExecutionHistory()){ if(previousStatus == DCWormsTags.INEXEC){ executionTime = executionTime + (execHistItem.getTimeStamp()/1000 - previousTimestamp); } previousTimestamp = execHistItem.getTimeStamp()/1000; previousStatus = execHistItem.getStatus(); } return executionTime; //return task.getFinishTime() - task.getExecStartTime(); } private String getUniqueTaskId(ExecTask execTask){ return execTask.getJobId() + "_" + execTask.getId(); } //change this method to adjust the colors of gantt chart protected String getAppId(ExecTask execTask){ String taskId = execTask.getJobId() + "_" + execTask.getId(); if(execTask.getApplicationName() != null){ taskId = execTask.getApplicationName(); } return taskId; } //TO DELETE /*private ResourceUsageStats gatherResourceOccupancyStatsOld(ComputingResource resource, Map> basicStats) { String usageType = null; if(resource.getResourceCharacteristic().getParameters().get("load-sensor") != null){ usageType = resource.getResourceCharacteristic().getParameters().get("load-sensor").get(0).getContent(); } ResourceUsageStats usageStats = new ResourceUsageStats(resource.getFullName(), resource.getType(), usageType); int cnt = 0; System.out.println("a: " + System.currentTimeMillis()); for(String resName: basicStats.keySet()){ if(resource.getDescendantByName(resName) != null || resource.getFullName().compareTo(resName) == 0){ createResourceLoadData(usageStats, basicStats.get(resName)); cnt++; } } System.out.println("b: " + System.currentTimeMillis()); for(Long key: usageStats.getHistory().keySet()){ Double value = usageStats.getHistory().get(key)/cnt; usageStats.getHistory().put(key, value); } return usageStats; } */ private ResourceUsageStats gatherResourceOccupancyStats(ComputingResource compRes, Map> basicStats) { String usageType = null; if(compRes.getResourceCharacteristic().getParameters().get("load-sensor")!= null){ usageType = compRes.getResourceCharacteristic().getParameters().get("load-sensor").get(0).getContent(); } ResourceUsageStats usageStats = new ResourceUsageStats(compRes.getFullName(), compRes.getType(), usageType); int cnt = 0; if(basicStats.containsKey(compRes)){ createResourceLoadData(usageStats, basicStats.get(compRes)); cnt++; } else { for(ComputingResource pe: basicStats.keySet()){ if(compRes.contains(pe)){ createResourceLoadData(usageStats, basicStats.get(pe)); cnt++; } } } for(Long key: usageStats.getHistory().keySet()){ Double value = usageStats.getHistory().get(key)/cnt; usageStats.getHistory().put(key, value); } return usageStats; } private ResourceAvailabilityStats gatherResourceAvailabilityStats(ComputingResource resource) { String usageType = new String ("usedNodes"); int usedResources = 0; for(ComputingResource compResource: resource.getChildren()){ double meanLoad = calculateMeanValue(gatherResourceOccupancyStats(compResource, peStats)); if(meanLoad > 0){ usedResources++; } } ResourceAvailabilityStats availabilityStats = new ResourceAvailabilityStats(resource.getFullName(), resource.getType(), usageType, usedResources, endSimulationTime); return availabilityStats; } private ResourceUsefulWorkStats gatherResourceUsefulWorkStats(ComputingResource compResource) { String usageType = "usefulWork"; double usefulWork = 0; JobRegistry jr = new JobRegistryImpl(compResource); for(ExecTask task: jr.getFinishedTasks()){ usefulWork = usefulWork + task.getExecutionProfile().getUsefulWork(); } ResourceUsefulWorkStats usefulWorkStats = new ResourceUsefulWorkStats(compResource.getFullName(), compResource.getType(), usageType, usefulWork, endSimulationTime); return usefulWorkStats; } 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); } } } if(ganttData.get(startSimulationTime) == null) ganttData.put(startSimulationTime, 0.0); if(ganttData.get(endSimulationTime) == null) ganttData.put(endSimulationTime, 0.0); return ganttData; } private Long getLeftKey(TreeMap ganttData, Long toKey) { SortedMap sm = ganttData.headMap(toKey); if (sm.isEmpty()) { return null; } return sm.lastKey(); } private ResourceUsageStats gatherResourceUtlizationStats(PhysicalResource resource) { String usageType = null; if(resource.getResourceCharacteristic().getParameters().get("load-sensor")!= null){ usageType = resource.getResourceCharacteristic().getParameters().get("load-sensor").get(0).getContent(); } ResourceUsageStats resUtlization = new ResourceUsageStats(resource.getFullName(), resource.getType(), usageType); Map usage = resUtlization.getHistory(); ExtensionList extensionList = resource.getExtensionList(); if(extensionList != null){ for (Extension extension : extensionList) { if (extension.getType() == ExtensionType.LOAD_EXTENSION) { LoadExtension le = (LoadExtension)extension; if(le.getLoadProfile() == null) break; List loadHistory = le.getLoadProfile().getUtilizationHistory(); if(loadHistory.size() == 0) break; long endSimulationTime = DateTimeUtilsExt.currentTimeMillis(); loadHistory.add(new MeasurementHistory(endSimulationTime, le.getLoadProfile().getUtilizationHistory().get(le.getLoadProfile().getUtilizationHistory().size() - 1).getValue())); for(MeasurementHistory l:loadHistory){ usage.put(l.getTimestamp(), l.getValue()/100); } } } } return resUtlization; } private ResourcePowerStats gatherResourcePowerConsumptionStats(PhysicalResource resource) { double power = 0; String usageType = null; if(resource.getResourceCharacteristic().getParameters().get("power-sensor") != null){ usageType = resource.getResourceCharacteristic().getParameters().get("power-sensor").get(0).getContent(); } ResourcePowerStats resEnergyUsage = new ResourcePowerStats(resource.getFullName(), resource.getType(), usageType); 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()); power = power + (pu.getTimestamp() - lastTime) * lastPower/ (3600 * MILLI_SEC); lastPower = pu.getValue(); lastTime = pu.getTimestamp(); } } } } return resEnergyUsage; } private ResourceAirflowStats gatherResourceAirflowStats(PhysicalResource resource) { String usageType = null; if(resource.getResourceCharacteristic().getParameters().get("airflow_volume-sensor") != null){ usageType = resource.getResourceCharacteristic().getParameters().get("airflow_volume-sensor").get(0).getContent(); } ResourceAirflowStats resAirflow = new ResourceAirflowStats(resource.getFullName(), resource.getType(), usageType); 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().getAirflowHistory(); if(airflowHistory.size() == 0) break; long endSimulationTime = DateTimeUtilsExt.currentTimeMillis(); airflowHistory.add(new AirflowValue(endSimulationTime, ee.getAirflowProfile().getAirflowHistory().get(ee.getAirflowProfile().getAirflowHistory().size()-1).getValue())); for(AirflowValue af:airflowHistory){ airflow.put(af.getTimestamp(), af.getValue()); } } } } return resAirflow; } private ResourceTemperatureStats gatherResourceTemperatureStats(PhysicalResource resource) { String usageType = null; if(resource.getResourceCharacteristic().getParameters().get("temperature-sensor")!= null){ usageType = resource.getResourceCharacteristic().getParameters().get("temperature-sensor").get(0).getContent(); } ResourceTemperatureStats resTemperature = new ResourceTemperatureStats(resource.getFullName(), resource.getType(), usageType); 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 createResourceOccupancyDiagram(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 occupancyDiagram = resourceOccupancyDiagrams.get(resLoadStats.getResourceType().getName()); if(occupancyDiagram == null){ occupancyDiagram = new ArrayList(); occupancyDiagram.add(dataset); resourceOccupancyDiagrams.put(resLoadStats.getResourceType().getName(), occupancyDiagram); } else { occupancyDiagram.add(dataset); } } private void createResourceUtilizationDiagram(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 utilizationDiagram = resourceUtilizationDiagrams.get(resLoadStats.getResourceType().getName()); if(utilizationDiagram == null){ utilizationDiagram = new ArrayList(); utilizationDiagram.add(dataset); resourceUtilizationDiagrams.put(resLoadStats.getResourceType().getName(), utilizationDiagram); } else { utilizationDiagram.add(dataset); } } private void createResourceEnergyDiagramData(ResourceDynamicStats powerConsumptionStats) { XYDataset dataset = createResourceChartDataSet(powerConsumptionStats, startSimulationTime, endSimulationTime); List energyDiagramData = resourcePowerUsageDiagrams.get(powerConsumptionStats.getResourceType().getName()); if(energyDiagramData == null){ energyDiagramData = new ArrayList(); energyDiagramData.add(dataset); resourcePowerUsageDiagrams.put(powerConsumptionStats.getResourceType().getName(), energyDiagramData); } else { energyDiagramData.add(dataset); } } private void createResourceTemperatureDiagramData(ResourceDynamicStats temperatureStats) { XYDataset dataset = createResourceChartDataSet(temperatureStats, startSimulationTime, endSimulationTime); List temperatureDiagramData = resourceTemperatureDiagrams.get(temperatureStats.getResourceType().getName()); if(temperatureDiagramData == null){ temperatureDiagramData = new ArrayList(); temperatureDiagramData.add(dataset); resourceTemperatureDiagrams.put(temperatureStats.getResourceType().getName(), temperatureDiagramData); } else { temperatureDiagramData.add(dataset); } } private void createResourceAirflowDiagramData(ResourceDynamicStats airflowStats) { XYDataset dataset = createResourceChartDataSet(airflowStats, startSimulationTime, endSimulationTime); List airflowDiagramData = resourceAirflowDiagrams.get(airflowStats.getResourceType().getName()); if(airflowDiagramData == null){ airflowDiagramData = new ArrayList(); airflowDiagramData.add(dataset); resourceAirflowDiagrams.put(airflowStats.getResourceType().getName(), 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 saveResourceDiagrams() { 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 resourceOccupancyDiagram = null; if (configuration.creatediagrams_resutilization) { String axisName = "OCCUPANCY [%]"; for(String resType: resourceOccupancyDiagrams.keySet()){ resourceOccupancyDiagram = getResourceDynamicDiagram(resourceOccupancyDiagrams.get(resType), simulationTime, chartName, subtitle, axisName); if (!saveXYPlotChart(resourceOccupancyDiagram, fileName + "ResourcesOccupancy_" + resType)) return false; } } chartName = "Utilization diagram for " + DataCenterWorkloadSimulator.SIMULATOR_NAME; JFreeChart resourceUtilizationDiagram = null; if (configuration.creatediagrams_resutilization) { String axisName = "UTILIZATION [%]"; for(String resType: resourceUtilizationDiagrams.keySet()){ resourceUtilizationDiagram = getResourceDynamicDiagram(resourceUtilizationDiagrams.get(resType), simulationTime, chartName, subtitle, axisName); if (!saveXYPlotChart(resourceUtilizationDiagram, fileName + "ResourcesUtilization_" + resType)) return false; } } chartName = "Energy usage diagram for " + DataCenterWorkloadSimulator.SIMULATOR_NAME; JFreeChart resourceEnergyDiagram = null; if (configuration.creatediagrams_respowerusage) { String axisName = "POWER [W]"; for(String resType: resourcePowerUsageDiagrams.keySet()){ resourceEnergyDiagram = getResourceDynamicDiagram(resourcePowerUsageDiagrams.get(resType), simulationTime, chartName, subtitle, axisName); if (!saveXYPlotChart(resourceEnergyDiagram, fileName + "Energy_" + resType)) 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(String resType: resourceAirflowDiagrams.keySet()){ resourceAirflowDiagram = getResourceDynamicDiagram(resourceAirflowDiagrams.get(resType), simulationTime, chartName, subtitle, axisName); if (!saveXYPlotChart(resourceAirflowDiagram, fileName + "Airflow_" + resType)) return false; } } chartName = "Temperature diagram for " + DataCenterWorkloadSimulator.SIMULATOR_NAME; JFreeChart resourceTemperatureDiagram = null; if (configuration.creatediagrams_restemperature) { String axisName = "TEMPERATURE [C]"; for(String resType: resourceTemperatureDiagrams.keySet()){ resourceTemperatureDiagram = getResourceDynamicDiagram(resourceTemperatureDiagrams.get(resType), simulationTime, chartName, subtitle, axisName); if (!saveXYPlotChart(resourceTemperatureDiagram, fileName + "Temperature_" + resType)) 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(); /*Font fontt=new Font("Arial",Font.BOLD,26); c.getTitle().setFont(fontt); Font font=new Font("Arial",0,20); CombinedDomainXYPlot p = (CombinedDomainXYPlot)c.getPlot(); ValueAxis daxis = p.getDomainAxis(); daxis.setTickLabelFont(font); daxis.setLabelFont(font); font=new Font("Arial",0,20); XYPlot sp= (XYPlot) p.getSubplots().get(0); ValueAxis raxis = sp.getRangeAxis(); raxis.setTickLabelFont(font); raxis.setLabelFont(font); NumberAxis range = (NumberAxis) sp.getRangeAxis(); range.setTickUnit(new NumberTickUnit(100));*/ 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 createGanttDiagram(Map> basicResStats) { Map peGanttMap = new HashMap(); Map taskGanttMap = new HashMap(); for(ComputingResource pe: basicResStats.keySet()){ TimetableEventSource peES = new TimetableEventSource(pe.getFullName()); ganttDiagramTimetable.addEventSource(peES); peGanttMap.put(pe.getFullName(), peES); for(ResStat resStat: basicResStats.get(pe)){ peES = peGanttMap.get(resStat.getPeName()); if(peES == null){ //pe = new TimetableEventSource(resStat.getPeName()); // ganttDiagramPeTimetable.addEventSource(pe); // peGanttMap.put(resStat.getPeName(), pe); } TimetableEventGroup taskEG = taskGanttMap.get(resStat.getTaskID()); long startDate = resStat.getStartDate(); long endDate = resStat.getEndDate(); if (taskEG == null) { taskEG = new TimetableEventGroup(resStat.getTaskID()); taskGanttMap.put(resStat.getTaskID(), taskEG); ganttDiagramTimetable.addEventGroup(taskEG); } ganttDiagramTimetable.addEvent(peES, taskEG, new FixedMillisecond(startDate), new FixedMillisecond(endDate)); } } } //TO DO private void createAccumulatedResourceSimulationStatistic() { Map basicResLoad = calculatePELoad(peStats); 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.meanTotalOccupancy.add(load); ResourceUsageStats resourceUtilization = gatherResourceUtlizationStats(compRes); accStats.meanTotalLoad.add(calculateMeanValue(resourceUtilization)); /*ResourceEnergyStats energyUsage = gatherResourceEnergyStats(compRes); energyUsage.setMeanUsage(calculateEnergyLoad(energyUsage)); accStats.meanEnergyUsage.add(energyUsage.meanUsage);*/ //} } } private Map calculatePELoad(Map> basicResStats){ Map peLoad = new HashMap(); for(ComputingResource compRes: basicResStats.keySet()){ List resStats = basicResStats.get(compRes); double sum = 0; for(ResStat resStat:resStats){ sum += (resStat.endDate - resStat.startDate); } double load = sum / (endSimulationTime - startSimulationTime); peLoad.put(compRes, load); } return peLoad; } private Double calculateResourceLoad(ComputingResource compRes, Map peLoad ){ int peCnt = 0; double sum = 0; for(ComputingResource pe: peLoad.keySet()){ if(compRes.contains(pe)){ Double load = peLoad.get(pe); sum += load; peCnt++; } } 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; } private double calculateMaxValue(ResourceDynamicStats resDynamicStats){ double maxValue = 0; Map history = resDynamicStats.getHistory(); for (Long key : history.keySet()) { if(history.get(key) > maxValue){ maxValue = history.get(key) ; } } return maxValue; } /************* 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 + "_" + 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 = jobRegistry.getTasks().getExecutables(job.getId()); List taskStatsList = new ArrayList(); this.serializer.setFieldSeparator(SEPARATOR); for (int j = 0; j < execList.size(); j++) { Executable task = (Executable) execList.get(j); if(task.isFinished() == false){ continue; } 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(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 = getUniqueTaskId(task); taskStats.setProcessors(taskToPEMap.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 = getUniqueTaskId(task); 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 = getUniqueTaskId(task); 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 = getTaskWaitingTimeDiagram(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 getTaskWaitingTimeDiagram(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); /*Font fontt=new Font("Arial",Font.BOLD,26); c.getTitle().setFont(fontt); Font font=new Font("Arial",0,20); CategoryPlot p = (CategoryPlot)c.getPlot(); CategoryAxis daxis = p.getDomainAxis(); daxis.setTickLabelFont(font); daxis.setLabelFont(font); font=new Font("Arial",0,20); ValueAxis raxis = p.getRangeAxis(); raxis.setTickLabelFont(font); raxis.setLabelFont(font); font=new Font("Arial",0,20); c.getLegend().setItemFont(font); */ 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 peIdComparator implements Comparator { public int compare(ComputingResource o1, ComputingResource o2) { Integer o1int = 0; Integer o2int = 0; String o1string = null; String o2string = null; try { if(o1.getFullName().contains("_")){ o1string = o1.getFullName().substring(0, o1.getFullName().lastIndexOf("_")); o1int = Integer.parseInt(o1.getFullName().substring(o1.getFullName().lastIndexOf("_") + 1)); } else { o1string = o1.getFullName(); } if(o2.getFullName().contains("_")){ o2string = o2.getFullName().substring(0, o2.getFullName().lastIndexOf("_")); o2int = Integer.parseInt(o2.getFullName().substring(o2.getFullName().lastIndexOf("_") + 1)); }else { o2string = o2.getFullName(); } } catch (Exception e) { o1int = 0; o2int = 0; o1string = o1.getFullName(); o2string = o2.getFullName(); } if(o1int.compareTo(o2int) != 0) return o1int.compareTo(o2int); else return o1string.compareTo(o2string); } } public DCwormsAccumulator 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) { 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) { 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, textUsefulWork; }