[477] | 1 | package simulator.stats.implementation; |
---|
| 2 | |
---|
| 3 | import java.awt.Color; |
---|
| 4 | import java.awt.Paint; |
---|
| 5 | import java.io.File; |
---|
| 6 | import java.io.FileOutputStream; |
---|
| 7 | import java.io.IOException; |
---|
| 8 | import java.io.PrintStream; |
---|
| 9 | import java.text.NumberFormat; |
---|
| 10 | import java.util.ArrayList; |
---|
| 11 | import java.util.Calendar; |
---|
| 12 | import java.util.Collections; |
---|
| 13 | import java.util.Comparator; |
---|
| 14 | import java.util.Date; |
---|
| 15 | import java.util.HashMap; |
---|
| 16 | import java.util.List; |
---|
| 17 | import java.util.Map; |
---|
| 18 | import java.util.SortedMap; |
---|
| 19 | import java.util.TreeMap; |
---|
| 20 | |
---|
[490] | 21 | import org.apache.commons.lang.ArrayUtils; |
---|
[477] | 22 | import org.apache.commons.logging.Log; |
---|
| 23 | import org.apache.commons.logging.LogFactory; |
---|
| 24 | import org.jfree.chart.ChartFactory; |
---|
| 25 | import org.jfree.chart.ChartRenderingInfo; |
---|
| 26 | import org.jfree.chart.ChartUtilities; |
---|
| 27 | import org.jfree.chart.JFreeChart; |
---|
| 28 | import org.jfree.chart.axis.AxisLocation; |
---|
| 29 | import org.jfree.chart.axis.DateAxis; |
---|
| 30 | import org.jfree.chart.axis.NumberAxis; |
---|
| 31 | import org.jfree.chart.encoders.ImageFormat; |
---|
| 32 | import org.jfree.chart.labels.CategoryItemLabelGenerator; |
---|
| 33 | import org.jfree.chart.labels.ItemLabelAnchor; |
---|
| 34 | import org.jfree.chart.labels.ItemLabelPosition; |
---|
| 35 | import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; |
---|
| 36 | import org.jfree.chart.plot.CategoryPlot; |
---|
| 37 | import org.jfree.chart.plot.CombinedDomainXYPlot; |
---|
| 38 | import org.jfree.chart.plot.PlotOrientation; |
---|
| 39 | import org.jfree.chart.plot.XYPlot; |
---|
| 40 | import org.jfree.chart.renderer.category.CategoryItemRenderer; |
---|
| 41 | import org.jfree.chart.renderer.category.GanttRenderer; |
---|
| 42 | import org.jfree.chart.renderer.xy.XYStepAreaRenderer; |
---|
| 43 | import org.jfree.chart.title.TextTitle; |
---|
| 44 | import org.jfree.chart.title.Title; |
---|
| 45 | import org.jfree.data.gantt.TaskSeries; |
---|
| 46 | import org.jfree.data.gantt.TaskSeriesCollection; |
---|
| 47 | import org.jfree.data.time.FixedMillisecond; |
---|
| 48 | import org.jfree.data.xy.XYDataset; |
---|
| 49 | import org.jfree.data.xy.XYSeries; |
---|
| 50 | import org.jfree.data.xy.XYSeriesCollection; |
---|
| 51 | import org.jfree.ui.TextAnchor; |
---|
[687] | 52 | import org.joda.time.DateTime; |
---|
[477] | 53 | import org.joda.time.DateTimeUtilsExt; |
---|
| 54 | |
---|
[481] | 55 | import schedframe.ExecutablesList; |
---|
[477] | 56 | import schedframe.ResourceController; |
---|
| 57 | import schedframe.exceptions.ResourceException; |
---|
| 58 | import schedframe.resources.ResourceType; |
---|
[490] | 59 | import schedframe.resources.UserResourceType; |
---|
[477] | 60 | import schedframe.resources.computing.ComputingResource; |
---|
| 61 | import schedframe.resources.computing.extensions.Extension; |
---|
| 62 | import schedframe.resources.computing.extensions.ExtensionList; |
---|
| 63 | import schedframe.resources.computing.extensions.ExtensionType; |
---|
| 64 | import schedframe.resources.computing.profiles.energy.EnergyExtension; |
---|
[495] | 65 | import schedframe.resources.computing.profiles.energy.airthroughput.AirFlowValue; |
---|
[477] | 66 | import schedframe.resources.computing.profiles.energy.power.PowerUsage; |
---|
[821] | 67 | import schedframe.resources.computing.profiles.energy.thermal.TemperatureValue; |
---|
[477] | 68 | import schedframe.resources.units.PEUnit; |
---|
| 69 | import schedframe.resources.units.ProcessingElements; |
---|
| 70 | import schedframe.resources.units.ResourceUnit; |
---|
| 71 | import schedframe.resources.units.ResourceUnitName; |
---|
| 72 | import schedframe.resources.units.StandardResourceUnitName; |
---|
| 73 | import schedframe.scheduling.ResourceHistoryItem; |
---|
| 74 | import schedframe.scheduling.Scheduler; |
---|
[481] | 75 | import schedframe.scheduling.manager.tasks.JobRegistry; |
---|
[477] | 76 | import schedframe.scheduling.manager.tasks.JobRegistryImpl; |
---|
| 77 | import schedframe.scheduling.tasks.Job; |
---|
| 78 | import schedframe.scheduling.tasks.JobInterface; |
---|
| 79 | import simulator.ConfigurationOptions; |
---|
[481] | 80 | import simulator.DCWormsConstants; |
---|
[477] | 81 | import simulator.DataCenterWorkloadSimulator; |
---|
| 82 | import simulator.GenericUser; |
---|
| 83 | import simulator.stats.GSSAccumulator; |
---|
| 84 | import simulator.stats.SimulationStatistics; |
---|
| 85 | import simulator.stats.implementation.out.AbstractStringSerializer; |
---|
| 86 | import simulator.stats.implementation.out.StringSerializer; |
---|
| 87 | import csiro.mit.utils.jfreechart.timetablechart.TimetableChartFactory; |
---|
| 88 | import csiro.mit.utils.jfreechart.timetablechart.data.Timetable; |
---|
| 89 | import csiro.mit.utils.jfreechart.timetablechart.data.TimetableEventGroup; |
---|
| 90 | import csiro.mit.utils.jfreechart.timetablechart.data.TimetableEventSource; |
---|
| 91 | import csiro.mit.utils.jfreechart.timetablechart.renderer.TimetableRenderer; |
---|
[490] | 92 | import dcworms.schedframe.scheduling.ExecTask; |
---|
| 93 | import dcworms.schedframe.scheduling.Executable; |
---|
[477] | 94 | import eduni.simjava.Sim_stat; |
---|
| 95 | |
---|
[481] | 96 | public class DCWormsStatistics implements SimulationStatistics { |
---|
[477] | 97 | |
---|
[481] | 98 | private Log log = LogFactory.getLog(DCWormsStatistics.class); |
---|
[477] | 99 | |
---|
| 100 | protected static float ALPHA = 0.5f; |
---|
| 101 | protected static int GANTT_WIDTH = 1200; |
---|
[495] | 102 | |
---|
[481] | 103 | protected static final int MILLI_SEC = 1000; |
---|
[477] | 104 | |
---|
| 105 | protected static final String RAW_TASKS_STATISTICS_OUTPUT_FILE_NAME = "Tasks.txt"; |
---|
| 106 | protected static final String JOBS_STATISTICS_OUTPUT_FILE_NAME = "Jobs.txt"; |
---|
| 107 | |
---|
| 108 | protected static final String SIMULATION_STATISTICS_OUTPUT_FILE_NAME = "Simulation.txt"; |
---|
[495] | 109 | protected static final String RESOURCEUTILIZATION_STATISTICS_OUTPUT_FILE_NAME = "ResourceUtilization.txt"; |
---|
| 110 | protected static final String ENERGYUSAGE_STATISTICS_OUTPUT_FILE_NAME = "EnergyUsage.txt"; |
---|
| 111 | protected static final String AIRFLOW_STATISTICS_OUTPUT_FILE_NAME = "AirThroughput.txt"; |
---|
[821] | 112 | protected static final String TEMPERATURE_STATISTICS_OUTPUT_FILE_NAME = "Temperature.txt"; |
---|
[477] | 113 | |
---|
| 114 | protected static final String DIAGRAMS_FILE_NAME_PREFIX = "Chart_"; |
---|
| 115 | protected static final String STATS_FILE_NAME_PREFIX = "Stats_"; |
---|
| 116 | |
---|
| 117 | protected static final String TASK_SEPARATOR = ";"; |
---|
| 118 | protected static final String JOB_SEPARATOR = ";"; |
---|
| 119 | |
---|
| 120 | protected String outputFolderName; |
---|
| 121 | |
---|
| 122 | protected String simulationIdentifier; |
---|
| 123 | protected ConfigurationOptions configuration; |
---|
| 124 | |
---|
| 125 | protected GSSAccumulatorsStats accStats; |
---|
| 126 | protected Map<String, GSSAccumulator> statsData; |
---|
| 127 | |
---|
[495] | 128 | protected GenericUser users; |
---|
[477] | 129 | protected ResourceController resourceController; |
---|
| 130 | protected boolean generateDiagrams = true; |
---|
| 131 | protected AbstractStringSerializer serializer; |
---|
| 132 | protected long startSimulationTime; |
---|
| 133 | protected long endSimulationTime; |
---|
| 134 | |
---|
| 135 | //RESOURCES |
---|
[496] | 136 | protected Map<String, List<ResStat>> basicResStats; |
---|
| 137 | protected Map<String, Double> basicResLoad; |
---|
| 138 | |
---|
| 139 | protected Map<String, TimetableEventSource> peGanttMap; |
---|
| 140 | protected Map<String, TimetableEventGroup> taskGanttMap; |
---|
| 141 | |
---|
| 142 | protected Timetable ganttDiagramTimetable; |
---|
[495] | 143 | protected Map<ResourceType, List<XYDataset>> resourcePowerUsageDiagrams; |
---|
| 144 | protected Map<ResourceType, List<XYDataset>> resourceAirFlowDiagrams; |
---|
[821] | 145 | protected Map<ResourceType, List<XYDataset>> resourceTemperatureDiagrams; |
---|
[477] | 146 | protected Map<ResourceType, List<XYDataset>> resourceLoadDiagrams; |
---|
| 147 | |
---|
| 148 | //TASKS |
---|
| 149 | protected int numOfdelayedTasks = 0; |
---|
| 150 | protected int numOfNotExecutedTasks = 0; |
---|
| 151 | protected double maxCj = 0; |
---|
| 152 | |
---|
| 153 | protected boolean allTasksFinished; |
---|
| 154 | protected TaskSeriesCollection ganttDiagramTaskSeriesCollection; |
---|
| 155 | protected TaskSeriesCollection ganttDiagramWaitingTimeSeriesCollection; |
---|
| 156 | protected HashMap<String, List<String>> task_processorsMap; |
---|
| 157 | |
---|
[490] | 158 | protected JobRegistry jr; |
---|
[477] | 159 | |
---|
| 160 | |
---|
[481] | 161 | public DCWormsStatistics(String simulationIdentifier, ConfigurationOptions co, GenericUser users, |
---|
[477] | 162 | String outputFolderName, ResourceController resourceController) { |
---|
| 163 | this.simulationIdentifier = simulationIdentifier; |
---|
| 164 | this.configuration = co; |
---|
| 165 | this.users = users; |
---|
| 166 | |
---|
| 167 | this.outputFolderName = outputFolderName; |
---|
| 168 | |
---|
[493] | 169 | this.serializer = new StringSerializer(); |
---|
[477] | 170 | this.serializer.setDefaultNumberFormat(DataCenterWorkloadSimulator.DFAULT_NUMBER_FORMAT); |
---|
| 171 | |
---|
| 172 | this.resourceController = resourceController; |
---|
[495] | 173 | this.jr = new JobRegistryImpl(""); |
---|
[477] | 174 | init(); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | public void generateStatistics() { |
---|
| 178 | |
---|
[687] | 179 | if(users.isSimStartTimeDefined()) |
---|
| 180 | this.startSimulationTime = DateTimeUtilsExt.getOffsetTime().getTimeInMillis(); |
---|
| 181 | else |
---|
| 182 | this.startSimulationTime = new DateTime(users.getSubmissionStartTime() * 1000l).getMillis(); |
---|
[477] | 183 | this.endSimulationTime = DateTimeUtilsExt.currentTimeMillis(); |
---|
| 184 | |
---|
| 185 | long s = 0; |
---|
| 186 | long e = 0; |
---|
| 187 | |
---|
| 188 | log.info("gatherResourceStatistics"); |
---|
| 189 | s = System.currentTimeMillis(); |
---|
| 190 | gatherResourceStatistics(); |
---|
| 191 | e = System.currentTimeMillis(); |
---|
[481] | 192 | log.info("time in sec: " + ((e - s) / MILLI_SEC)); |
---|
[477] | 193 | |
---|
| 194 | log.info("gatherTaskStatistics"); |
---|
| 195 | s = System.currentTimeMillis(); |
---|
| 196 | gatherTaskStatistics(); |
---|
| 197 | e = System.currentTimeMillis(); |
---|
[481] | 198 | log.info("time in sec: " + ((e - s) / MILLI_SEC)); |
---|
[477] | 199 | |
---|
| 200 | log.info("saveSimulationStatistics"); |
---|
| 201 | s = System.currentTimeMillis(); |
---|
| 202 | saveSimulationStatistics(); |
---|
| 203 | e = System.currentTimeMillis(); |
---|
[481] | 204 | log.info("time in sec: " + ((e - s) / MILLI_SEC)); |
---|
[477] | 205 | } |
---|
| 206 | |
---|
| 207 | |
---|
| 208 | public String getOutputFolderName() { |
---|
| 209 | return outputFolderName; |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | private void init() { |
---|
| 213 | task_processorsMap = new HashMap<String, List<String>>(); |
---|
| 214 | accStats = new GSSAccumulatorsStats(); |
---|
| 215 | statsData = new HashMap<String, GSSAccumulator>(); |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | public void saveSimulationStatistics() { |
---|
| 219 | PrintStream simulationStatsFile = null; |
---|
| 220 | if (configuration.createsimulationstatistics) { |
---|
| 221 | try { |
---|
| 222 | File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_" |
---|
| 223 | + SIMULATION_STATISTICS_OUTPUT_FILE_NAME); |
---|
| 224 | simulationStatsFile = new PrintStream(new FileOutputStream(file)); |
---|
| 225 | } catch (IOException e) { |
---|
| 226 | e.printStackTrace(); |
---|
| 227 | } |
---|
| 228 | } |
---|
| 229 | if (simulationStatsFile != null) { |
---|
| 230 | Object txt = accStats.serialize(this.serializer); |
---|
| 231 | simulationStatsFile.println(txt); |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | if (simulationStatsFile != null) { |
---|
| 235 | simulationStatsFile.close(); |
---|
| 236 | } |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | /************* RESOURCE STATISTICS SECTION **************/ |
---|
| 240 | private void gatherResourceStatistics() { |
---|
| 241 | |
---|
[490] | 242 | HashMap<String, List<Stats>> type_stats = new HashMap<String, List<Stats>>(); |
---|
[477] | 243 | |
---|
[490] | 244 | for(String resourceName: resourceController.getComputingResourceLayers()){ |
---|
| 245 | List<Stats> cStats = new ArrayList<Stats>(); |
---|
| 246 | cStats.add(Stats.textLoad); |
---|
| 247 | if(ArrayUtils.contains(configuration.resForUtilizationChart, resourceName)) |
---|
| 248 | cStats.add(Stats.chartLoad); |
---|
| 249 | cStats.add(Stats.textEnergy); |
---|
| 250 | if(ArrayUtils.contains(configuration.resForEnergyChart, resourceName)) |
---|
| 251 | cStats.add(Stats.chartEnergy); |
---|
[495] | 252 | cStats.add(Stats.textAirFlow); |
---|
| 253 | if(ArrayUtils.contains(configuration.resForAirFlowChart, resourceName)) |
---|
| 254 | cStats.add(Stats.chartAirFlow); |
---|
[821] | 255 | cStats.add(Stats.textTemperature); |
---|
| 256 | if(ArrayUtils.contains(configuration.resForTemperatureChart, resourceName)) |
---|
| 257 | cStats.add(Stats.chartTemperature); |
---|
[490] | 258 | type_stats.put(resourceName, cStats); |
---|
| 259 | } |
---|
[477] | 260 | |
---|
| 261 | peGanttMap = new HashMap<String, TimetableEventSource>(); |
---|
[495] | 262 | taskGanttMap = new HashMap<String, TimetableEventGroup>(); |
---|
[477] | 263 | |
---|
| 264 | resourceLoadDiagrams = new HashMap<ResourceType, List<XYDataset>>(); |
---|
[495] | 265 | resourcePowerUsageDiagrams = new HashMap<ResourceType, List<XYDataset>>(); |
---|
| 266 | resourceAirFlowDiagrams = new HashMap<ResourceType, List<XYDataset>>(); |
---|
[821] | 267 | resourceTemperatureDiagrams = new HashMap<ResourceType, List<XYDataset>>(); |
---|
[477] | 268 | |
---|
[496] | 269 | ganttDiagramTimetable = new Timetable(new FixedMillisecond( |
---|
[477] | 270 | startSimulationTime), new FixedMillisecond(endSimulationTime)); |
---|
| 271 | |
---|
| 272 | PrintStream resourceLoadStatsFile = null; |
---|
| 273 | try { |
---|
| 274 | File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX |
---|
| 275 | + simulationIdentifier + "_" |
---|
[495] | 276 | + RESOURCEUTILIZATION_STATISTICS_OUTPUT_FILE_NAME); |
---|
[477] | 277 | resourceLoadStatsFile = new PrintStream(new FileOutputStream(file)); |
---|
| 278 | } catch (IOException e) { |
---|
| 279 | resourceLoadStatsFile = null; |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | PrintStream energyStatsFile = null; |
---|
| 283 | try { |
---|
| 284 | File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX |
---|
| 285 | + simulationIdentifier + "_" |
---|
| 286 | + ENERGYUSAGE_STATISTICS_OUTPUT_FILE_NAME); |
---|
| 287 | energyStatsFile = new PrintStream(new FileOutputStream(file)); |
---|
| 288 | } catch (IOException e) { |
---|
| 289 | energyStatsFile = null; |
---|
| 290 | } |
---|
[495] | 291 | |
---|
| 292 | PrintStream airFlowStatsFile = null; |
---|
| 293 | try { |
---|
| 294 | File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX |
---|
| 295 | + simulationIdentifier + "_" |
---|
| 296 | + AIRFLOW_STATISTICS_OUTPUT_FILE_NAME); |
---|
| 297 | airFlowStatsFile = new PrintStream(new FileOutputStream(file)); |
---|
| 298 | } catch (IOException e) { |
---|
| 299 | airFlowStatsFile = null; |
---|
| 300 | } |
---|
[821] | 301 | |
---|
| 302 | PrintStream temperatureStatsFile = null; |
---|
| 303 | try { |
---|
| 304 | File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX |
---|
| 305 | + simulationIdentifier + "_" |
---|
| 306 | + TEMPERATURE_STATISTICS_OUTPUT_FILE_NAME); |
---|
| 307 | temperatureStatsFile = new PrintStream(new FileOutputStream(file)); |
---|
| 308 | } catch (IOException e) { |
---|
| 309 | temperatureStatsFile = null; |
---|
| 310 | } |
---|
[495] | 311 | |
---|
[481] | 312 | basicResStats = gatherPEStats(jr.getExecutableTasks()); |
---|
[477] | 313 | peStatsPostProcessing(basicResStats); |
---|
| 314 | basicResLoad = calculatePELoad( basicResStats); |
---|
| 315 | |
---|
[501] | 316 | if (configuration.creatediagrams_gantt) { |
---|
[477] | 317 | createPEGanttDiagram(basicResStats); |
---|
| 318 | } |
---|
| 319 | |
---|
[490] | 320 | for(String resourceName: resourceController.getComputingResourceLayers()){ |
---|
[477] | 321 | List<ComputingResource> resources = null; |
---|
[495] | 322 | |
---|
| 323 | resources = new ArrayList<ComputingResource>(); |
---|
| 324 | for(ComputingResource compRes: resourceController.getComputingResources() ){ |
---|
| 325 | resources.addAll(compRes.getDescendantsByType(new UserResourceType(resourceName))); |
---|
[477] | 326 | } |
---|
[495] | 327 | if(resourceController.getComputingResources().get(0).getType().getName().equals(resourceName)) |
---|
| 328 | resources.addAll(resourceController.getComputingResources()); |
---|
| 329 | |
---|
[490] | 330 | if(type_stats.containsKey(resourceName)){ |
---|
[477] | 331 | for(ComputingResource resource: resources){ |
---|
| 332 | ResourceUsageStats resourceUsage = null; |
---|
[496] | 333 | ResourcePowerStats energyUsage = null; |
---|
[495] | 334 | ResourceAirFlowStats airFlow = null; |
---|
[821] | 335 | ResourceTemperatureStats temperature = null; |
---|
[490] | 336 | if(type_stats.get(resourceName).contains(Stats.textLoad)){ |
---|
[477] | 337 | resourceUsage = gatherResourceLoadStats(resource, basicResStats); |
---|
[497] | 338 | resourceUsage.setMeanValue(calculateMeanValue(resourceUsage)); |
---|
[477] | 339 | if (resourceLoadStatsFile != null) { |
---|
| 340 | Object txt = resourceUsage.serialize(serializer); |
---|
| 341 | resourceLoadStatsFile.println(txt); |
---|
| 342 | } |
---|
| 343 | } |
---|
[490] | 344 | if(type_stats.get(resourceName).contains(Stats.chartLoad)){ |
---|
[501] | 345 | if (configuration.creatediagrams_resutilization) { |
---|
[477] | 346 | createResourceLoadDiagram(resourceUsage); |
---|
| 347 | } |
---|
| 348 | } |
---|
[490] | 349 | if(type_stats.get(resourceName).contains(Stats.textEnergy)){ |
---|
[496] | 350 | energyUsage = gatherResourcePowerConsumptionStats(resource); |
---|
| 351 | energyUsage.setMeanValue(calculateMeanValue(energyUsage)); |
---|
| 352 | energyUsage.setSumValue(energyUsage.getMeanValue() * (endSimulationTime - startSimulationTime) / (3600 * MILLI_SEC)); |
---|
[477] | 353 | |
---|
[512] | 354 | EnergyExtension een = (EnergyExtension)(resource.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); |
---|
[477] | 355 | if(resourceController.getComputingResources().contains(resource)) { |
---|
[521] | 356 | if( een != null && een.getPowerProfile() != null && een.getPowerProfile().getEnergyEstimationPlugin() != null){ |
---|
[544] | 357 | accStats.meanEnergyUsage.add(energyUsage.getSumValue()); |
---|
[477] | 358 | } |
---|
| 359 | |
---|
[521] | 360 | } else if( een != null && een.getPowerProfile() != null && een.getPowerProfile().getEnergyEstimationPlugin() != null){ |
---|
[477] | 361 | ComputingResource parent = resource.getParent(); |
---|
| 362 | boolean top = true; |
---|
| 363 | while(parent != null){ |
---|
[520] | 364 | een = (EnergyExtension)(parent.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); |
---|
[521] | 365 | if(een != null && een.getPowerProfile() != null && een.getPowerProfile().getEnergyEstimationPlugin() != null) { |
---|
[477] | 366 | top = false; |
---|
| 367 | break; |
---|
| 368 | } |
---|
| 369 | parent = parent.getParent(); |
---|
| 370 | } |
---|
| 371 | if(top == true){ |
---|
[544] | 372 | accStats.meanEnergyUsage.add(energyUsage.getSumValue()); |
---|
[477] | 373 | } |
---|
| 374 | } |
---|
| 375 | if (energyStatsFile != null) { |
---|
| 376 | Object txt = energyUsage.serialize(serializer); |
---|
| 377 | energyStatsFile.println(txt); |
---|
| 378 | } |
---|
| 379 | } |
---|
[490] | 380 | if(type_stats.get(resourceName).contains(Stats.chartEnergy)){ |
---|
[477] | 381 | |
---|
[501] | 382 | if (configuration.creatediagrams_respowerusage) { |
---|
[496] | 383 | createResourceEnergyDiagramData(energyUsage); |
---|
[477] | 384 | } |
---|
| 385 | } |
---|
| 386 | |
---|
[495] | 387 | if(type_stats.get(resourceName).contains(Stats.textAirFlow)){ |
---|
| 388 | airFlow = gatherResourceAirFlowStats(resource); |
---|
[496] | 389 | airFlow.setMeanValue(calculateMeanValue(airFlow)); |
---|
[762] | 390 | airFlow.setSumValue(airFlow.getMeanValue() * (endSimulationTime - startSimulationTime) / (60 * MILLI_SEC)); |
---|
[477] | 391 | |
---|
[495] | 392 | EnergyExtension een = (EnergyExtension)(resource.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); |
---|
| 393 | if(resourceController.getComputingResources().contains(resource)) { |
---|
| 394 | if( een != null /*&& een.getPp() != null*/ ){ |
---|
[544] | 395 | accStats.meanAirFlow.add(airFlow.getSumValue()); |
---|
[495] | 396 | } |
---|
| 397 | |
---|
| 398 | } else if( een != null && een.getAirFlowProfile() != null ){ |
---|
| 399 | ComputingResource parent = resource.getParent(); |
---|
| 400 | een = (EnergyExtension)(parent.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); |
---|
| 401 | boolean top = true; |
---|
| 402 | while(parent != null){ |
---|
| 403 | if(een != null && een.getAirFlowProfile() != null) { |
---|
| 404 | top = false; |
---|
| 405 | break; |
---|
| 406 | } |
---|
| 407 | parent = parent.getParent(); |
---|
| 408 | } |
---|
| 409 | if(top == true){ |
---|
[544] | 410 | accStats.meanAirFlow.add(airFlow.getSumValue()); |
---|
[495] | 411 | } |
---|
[477] | 412 | } |
---|
[495] | 413 | if (airFlowStatsFile != null) { |
---|
| 414 | Object txt = airFlow.serialize(serializer); |
---|
| 415 | airFlowStatsFile.println(txt); |
---|
[477] | 416 | } |
---|
[495] | 417 | } |
---|
| 418 | if(type_stats.get(resourceName).contains(Stats.chartAirFlow)){ |
---|
| 419 | |
---|
[501] | 420 | if (configuration.creatediagrams_resairflow) { |
---|
[496] | 421 | createResourceAirFlowDiagramData(airFlow); |
---|
[477] | 422 | } |
---|
| 423 | } |
---|
[821] | 424 | |
---|
| 425 | if(type_stats.get(resourceName).contains(Stats.textTemperature)){ |
---|
| 426 | temperature = gatherResourceTemperatureStats(resource); |
---|
| 427 | temperature.setMeanValue(calculateMeanValue(temperature)); |
---|
| 428 | temperature.setSumValue(temperature.getMeanValue() * (endSimulationTime - startSimulationTime) / (3600 * MILLI_SEC)); |
---|
| 429 | |
---|
| 430 | EnergyExtension een = (EnergyExtension)(resource.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); |
---|
| 431 | if(resourceController.getComputingResources().contains(resource)) { |
---|
| 432 | if( een != null /*&& een.getPp() != null*/ ){ |
---|
| 433 | accStats.meanTemperature.add(temperature.getSumValue()); |
---|
| 434 | } |
---|
| 435 | |
---|
| 436 | } else if( een != null && een.getThermalProfile() != null ){ |
---|
| 437 | ComputingResource parent = resource.getParent(); |
---|
| 438 | een = (EnergyExtension)(parent.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); |
---|
| 439 | boolean top = true; |
---|
| 440 | while(parent != null){ |
---|
| 441 | if(een != null && een.getThermalProfile() != null) { |
---|
| 442 | top = false; |
---|
| 443 | break; |
---|
| 444 | } |
---|
| 445 | parent = parent.getParent(); |
---|
| 446 | } |
---|
| 447 | if(top == true){ |
---|
| 448 | accStats.meanTemperature.add(temperature.getSumValue()); |
---|
| 449 | } |
---|
| 450 | } |
---|
| 451 | if (temperatureStatsFile != null) { |
---|
| 452 | Object txt = temperature.serialize(serializer); |
---|
| 453 | temperatureStatsFile.println(txt); |
---|
| 454 | } |
---|
| 455 | } |
---|
| 456 | if(type_stats.get(resourceName).contains(Stats.chartTemperature)){ |
---|
| 457 | |
---|
| 458 | if (configuration.creatediagrams_restemperature) { |
---|
| 459 | createResourceTemperatureDiagramData(temperature); |
---|
| 460 | } |
---|
| 461 | } |
---|
[477] | 462 | } |
---|
| 463 | } |
---|
| 464 | } |
---|
| 465 | |
---|
| 466 | saveResourceGanttDiagrams(); |
---|
| 467 | createAccumulatedResourceSimulationStatistic(); |
---|
[496] | 468 | |
---|
[821] | 469 | if (temperatureStatsFile != null) { |
---|
| 470 | temperatureStatsFile.close(); |
---|
| 471 | } |
---|
[495] | 472 | if (airFlowStatsFile != null) { |
---|
| 473 | airFlowStatsFile.close(); |
---|
| 474 | } |
---|
[477] | 475 | if (energyStatsFile != null) { |
---|
| 476 | energyStatsFile.close(); |
---|
| 477 | } |
---|
| 478 | if (resourceLoadStatsFile != null) { |
---|
| 479 | resourceLoadStatsFile.close(); |
---|
| 480 | } |
---|
| 481 | } |
---|
| 482 | |
---|
| 483 | |
---|
| 484 | private void peStatsPostProcessing(Map<String, List<ResStat>> basicResStats){ |
---|
| 485 | ResourceType resType = null; |
---|
| 486 | |
---|
| 487 | for(String key: basicResStats.keySet()){ |
---|
| 488 | List<ResStat> resStats = basicResStats.get(key); |
---|
| 489 | resType = resStats.get(0).getResType(); |
---|
| 490 | break; |
---|
| 491 | } |
---|
| 492 | List<ComputingResource> resources = null; |
---|
| 493 | try { |
---|
| 494 | resources = new ArrayList<ComputingResource>(); |
---|
| 495 | for(ComputingResource compRes: resourceController.getComputingResources() ){ |
---|
| 496 | resources.addAll(compRes.getDescendantsByType(resType)); |
---|
| 497 | } |
---|
| 498 | } catch (Exception e) { |
---|
| 499 | return; |
---|
| 500 | } |
---|
| 501 | for(ComputingResource resource: resources){ |
---|
| 502 | if(!basicResStats.containsKey(resource.getName())){ |
---|
| 503 | basicResStats.put(resource.getName(), new ArrayList<ResStat>()); |
---|
| 504 | } |
---|
| 505 | } |
---|
| 506 | } |
---|
[495] | 507 | |
---|
[481] | 508 | private Map<String, List<ResStat>> gatherPEStats( ExecutablesList executables) { |
---|
| 509 | |
---|
[477] | 510 | Map<String, List<ResStat>> basicResStats = new TreeMap<String, List<ResStat>>(new MapPEIdComparator()); |
---|
[495] | 511 | |
---|
[481] | 512 | for (ExecTask execTask:executables) { |
---|
| 513 | Executable exec = (Executable) execTask; |
---|
[477] | 514 | |
---|
[481] | 515 | List<ResourceHistoryItem> resHistItemList = exec.getUsedResources(); |
---|
[497] | 516 | if(resHistItemList.size() == 0) |
---|
| 517 | return basicResStats; |
---|
[477] | 518 | Map<ResourceUnitName, ResourceUnit> res = resHistItemList.get(resHistItemList.size() - 1).getResourceUnits(); |
---|
| 519 | ResourceUnit resUnit = res.get(StandardResourceUnitName.PE); |
---|
| 520 | //ProcessingElements pes = (ProcessingElements) resUnit ; |
---|
[495] | 521 | if(resUnit instanceof ProcessingElements){ |
---|
[477] | 522 | ProcessingElements pes = (ProcessingElements) resUnit; |
---|
| 523 | for(ComputingResource pe: pes){ |
---|
| 524 | String peName = pe.getName(); |
---|
[481] | 525 | long startDate = Double.valueOf(exec.getExecStartTime()).longValue() * MILLI_SEC; |
---|
| 526 | long endDate = Double.valueOf(exec.getFinishTime()).longValue() * MILLI_SEC; |
---|
| 527 | |
---|
[740] | 528 | String uniqueTaskID = getUniqueTaskId(execTask); |
---|
[477] | 529 | |
---|
| 530 | ResStat resStat = new ResStat(peName, pe.getType(), startDate, endDate, uniqueTaskID); |
---|
| 531 | |
---|
| 532 | List<ResStat> resStats = basicResStats.get(peName); |
---|
| 533 | if (resStats == null) { |
---|
| 534 | resStats = new ArrayList<ResStat>(); |
---|
| 535 | resStats.add(resStat); |
---|
| 536 | basicResStats.put(peName, resStats); |
---|
| 537 | } else { |
---|
| 538 | resStats.add(resStat); |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | List<String> peNames = task_processorsMap.get(uniqueTaskID); |
---|
| 542 | if (peNames == null) { |
---|
| 543 | peNames = new ArrayList<String>(); |
---|
| 544 | peNames.add(peName); |
---|
| 545 | task_processorsMap.put(uniqueTaskID, peNames); |
---|
| 546 | } else { |
---|
| 547 | peNames.add(peName); |
---|
| 548 | } |
---|
| 549 | } |
---|
| 550 | } else if (resUnit instanceof PEUnit){ |
---|
| 551 | PEUnit peUnit = (PEUnit) resUnit ; |
---|
| 552 | } |
---|
| 553 | |
---|
| 554 | } |
---|
| 555 | return basicResStats; |
---|
| 556 | } |
---|
| 557 | |
---|
[740] | 558 | //change this method to adjust the colors of gantt chart |
---|
| 559 | private String getUniqueTaskId(ExecTask execTask){ |
---|
| 560 | return execTask.getJobId() + "_" + execTask.getId(); |
---|
| 561 | } |
---|
| 562 | |
---|
[497] | 563 | private ResourceUsageStats gatherResourceLoadStats(ComputingResource resource, Map<String, List<ResStat>> basicStats) { |
---|
[477] | 564 | ResourceUsageStats usageStats = new ResourceUsageStats(resource.getName(), resource.getType(), "resourceLoadStats"); |
---|
[497] | 565 | int cnt = 0; |
---|
[477] | 566 | for(String resName: basicStats.keySet()){ |
---|
| 567 | try { |
---|
| 568 | if(resource.getDescendantByName(resName) != null || resource.getName().compareTo(resName) == 0){ |
---|
[497] | 569 | createResourceLoadData(usageStats, basicStats.get(resName)); |
---|
[495] | 570 | cnt++; |
---|
[477] | 571 | } |
---|
| 572 | } catch (ResourceException e) { |
---|
| 573 | // TODO Auto-generated catch block |
---|
| 574 | e.printStackTrace(); |
---|
| 575 | } |
---|
| 576 | } |
---|
[496] | 577 | for(Long key: usageStats.getHistory().keySet()){ |
---|
| 578 | Double value = usageStats.getHistory().get(key)/cnt; |
---|
[497] | 579 | usageStats.getHistory().put(key, value); |
---|
[495] | 580 | } |
---|
| 581 | |
---|
[477] | 582 | return usageStats; |
---|
| 583 | } |
---|
| 584 | |
---|
[496] | 585 | private Map<Long, Double> createResourceLoadData(ResourceUsageStats usageStats, List<ResStat> resStats) { |
---|
[477] | 586 | |
---|
[496] | 587 | TreeMap<Long, Double> ganttData = (TreeMap<Long, Double>)usageStats.getHistory(); |
---|
[477] | 588 | for (ResStat resStat : resStats) { |
---|
| 589 | |
---|
| 590 | long start_time = resStat.getStartDate(); |
---|
| 591 | long end_time = resStat.getEndDate(); |
---|
| 592 | if (end_time > start_time) { |
---|
[495] | 593 | Double end = ganttData.get(end_time); |
---|
[477] | 594 | if (end == null) { |
---|
[495] | 595 | ganttData.put(end_time, 0.0); |
---|
[477] | 596 | Long left = getLeftKey(ganttData, end_time); |
---|
| 597 | if (left != null) { |
---|
[495] | 598 | Double leftValue = ganttData.get(left); |
---|
[477] | 599 | ganttData.put(end_time, leftValue); |
---|
| 600 | } |
---|
| 601 | } |
---|
| 602 | |
---|
[495] | 603 | Double start = ganttData.get(start_time); |
---|
[477] | 604 | if (start == null) { |
---|
[495] | 605 | ganttData.put(start_time, 0.0); |
---|
[477] | 606 | Long left = getLeftKey(ganttData, start_time); |
---|
| 607 | if (left != null) { |
---|
[495] | 608 | Double leftValue = ganttData.get(left); |
---|
[477] | 609 | ganttData.put(start_time, leftValue); |
---|
| 610 | } |
---|
| 611 | } |
---|
| 612 | |
---|
[495] | 613 | SortedMap<Long, Double> sm = ganttData.subMap(start_time, |
---|
[477] | 614 | end_time); |
---|
| 615 | for (Long key : sm.keySet()) { |
---|
[495] | 616 | Double keyVal = ganttData.get(key); |
---|
[477] | 617 | ganttData.put(key, keyVal + 1); |
---|
| 618 | } |
---|
| 619 | } |
---|
| 620 | } |
---|
[495] | 621 | |
---|
[477] | 622 | return ganttData; |
---|
| 623 | } |
---|
| 624 | |
---|
[495] | 625 | private Long getLeftKey(TreeMap<Long, Double> ganttData, Long toKey) { |
---|
[477] | 626 | |
---|
[495] | 627 | SortedMap<Long, Double> sm = ganttData.headMap(toKey); |
---|
[477] | 628 | if (sm.isEmpty()) { |
---|
| 629 | return null; |
---|
| 630 | } |
---|
| 631 | return sm.lastKey(); |
---|
| 632 | } |
---|
| 633 | |
---|
| 634 | |
---|
[496] | 635 | private ResourcePowerStats gatherResourcePowerConsumptionStats(ComputingResource resource) { |
---|
[477] | 636 | double power = 0; |
---|
[496] | 637 | ResourcePowerStats resEnergyUsage = new ResourcePowerStats(resource.getName(), resource.getType(), "resourcePowerConsumptionStats"); |
---|
| 638 | Map<Long, Double> usage = resEnergyUsage.getHistory(); |
---|
[477] | 639 | |
---|
| 640 | ExtensionList extensionList = resource.getExtensionList(); |
---|
| 641 | if(extensionList != null){ |
---|
| 642 | for (Extension extension : extensionList) { |
---|
| 643 | if (extension.getType() == ExtensionType.ENERGY_EXTENSION) { |
---|
| 644 | EnergyExtension ee = (EnergyExtension)extension; |
---|
| 645 | if(ee.getPowerProfile() == null) |
---|
| 646 | break; |
---|
| 647 | List<PowerUsage> powerUsage = ee.getPowerProfile().getPowerUsageHistory(); |
---|
| 648 | if(powerUsage.size() == 0) |
---|
| 649 | break; |
---|
| 650 | long lastTime = DateTimeUtilsExt.getOffsetTime().getTimeInMillis(); |
---|
| 651 | long endSimulationTime = DateTimeUtilsExt.currentTimeMillis(); |
---|
| 652 | double lastPower = 0; |
---|
| 653 | powerUsage.add(new PowerUsage(endSimulationTime, ee.getPowerProfile().getPowerUsageHistory().get(ee.getPowerProfile().getPowerUsageHistory().size()-1).getValue())); |
---|
| 654 | for(PowerUsage pu:powerUsage){ |
---|
| 655 | usage.put(pu.getTimestamp(), pu.getValue()); |
---|
| 656 | |
---|
| 657 | /// System.out.println(resource.getName() + ":"+new DateTime(pu.getTimestamp())+";"+pu.getValue()); |
---|
[481] | 658 | power = power + (pu.getTimestamp() - lastTime) * lastPower/ (3600 * MILLI_SEC); |
---|
[477] | 659 | lastPower = pu.getValue(); |
---|
| 660 | lastTime = pu.getTimestamp(); |
---|
| 661 | } |
---|
| 662 | } |
---|
| 663 | } |
---|
| 664 | } |
---|
| 665 | //System.out.println(power); |
---|
| 666 | return resEnergyUsage; |
---|
| 667 | } |
---|
| 668 | |
---|
[495] | 669 | |
---|
| 670 | private ResourceAirFlowStats gatherResourceAirFlowStats(ComputingResource resource) { |
---|
[477] | 671 | |
---|
[495] | 672 | ResourceAirFlowStats resAirFlow = new ResourceAirFlowStats(resource.getName(), resource.getType(), "resourceAirFlowStats"); |
---|
[496] | 673 | Map<Long, Double> airFlow = resAirFlow.getHistory(); |
---|
[495] | 674 | |
---|
| 675 | ExtensionList extensionList = resource.getExtensionList(); |
---|
| 676 | if(extensionList != null){ |
---|
| 677 | for (Extension extension : extensionList) { |
---|
| 678 | if (extension.getType() == ExtensionType.ENERGY_EXTENSION) { |
---|
| 679 | EnergyExtension ee = (EnergyExtension)extension; |
---|
| 680 | if(ee.getAirFlowProfile() == null) |
---|
| 681 | break; |
---|
| 682 | List<AirFlowValue> airFlowHistory = ee.getAirFlowProfile().getAirThroughputHistory(); |
---|
| 683 | if(airFlowHistory.size() == 0) |
---|
| 684 | break; |
---|
| 685 | long endSimulationTime = DateTimeUtilsExt.currentTimeMillis(); |
---|
| 686 | airFlowHistory.add(new AirFlowValue(endSimulationTime, ee.getAirFlowProfile().getAirThroughputHistory().get(ee.getAirFlowProfile().getAirThroughputHistory().size()-1).getValue())); |
---|
| 687 | for(AirFlowValue af:airFlowHistory){ |
---|
| 688 | airFlow.put(af.getTimestamp(), af.getValue()); |
---|
| 689 | } |
---|
| 690 | } |
---|
| 691 | } |
---|
| 692 | } |
---|
| 693 | return resAirFlow; |
---|
| 694 | } |
---|
| 695 | |
---|
[821] | 696 | private ResourceTemperatureStats gatherResourceTemperatureStats(ComputingResource resource) { |
---|
| 697 | |
---|
| 698 | ResourceTemperatureStats resTemperature = new ResourceTemperatureStats(resource.getName(), resource.getType(), "resourceTemperatureStats"); |
---|
| 699 | Map<Long, Double> temperature = resTemperature.getHistory(); |
---|
| 700 | |
---|
| 701 | ExtensionList extensionList = resource.getExtensionList(); |
---|
| 702 | if(extensionList != null){ |
---|
| 703 | for (Extension extension : extensionList) { |
---|
| 704 | if (extension.getType() == ExtensionType.ENERGY_EXTENSION) { |
---|
| 705 | EnergyExtension ee = (EnergyExtension)extension; |
---|
| 706 | if(ee.getThermalProfile() == null) |
---|
| 707 | break; |
---|
| 708 | |
---|
| 709 | List<TemperatureValue> temperatureHistory = ee.getThermalProfile().getTemperatureHistory(); |
---|
| 710 | if(temperatureHistory.size() == 0) |
---|
| 711 | break; |
---|
| 712 | long endSimulationTime = DateTimeUtilsExt.currentTimeMillis(); |
---|
| 713 | temperatureHistory.add(new TemperatureValue(endSimulationTime, ee.getThermalProfile().getTemperatureHistory().get(ee.getThermalProfile().getTemperatureHistory().size()-1).getValue())); |
---|
| 714 | for(TemperatureValue af: temperatureHistory){ |
---|
| 715 | temperature.put(af.getTimestamp(), af.getValue()); |
---|
| 716 | } |
---|
| 717 | } |
---|
| 718 | } |
---|
| 719 | } |
---|
| 720 | return resTemperature; |
---|
| 721 | } |
---|
| 722 | |
---|
[496] | 723 | private void createResourceLoadDiagram(ResourceUsageStats resLoadStats) { |
---|
[495] | 724 | |
---|
[497] | 725 | for(Long key: resLoadStats.getHistory().keySet()){ |
---|
| 726 | Double value = resLoadStats.getHistory().get(key) * 100; |
---|
| 727 | resLoadStats.getHistory().put(key, value); |
---|
| 728 | } |
---|
| 729 | |
---|
[496] | 730 | XYDataset dataset = createResourceChartDataSet(resLoadStats, |
---|
[477] | 731 | startSimulationTime, endSimulationTime); |
---|
[496] | 732 | |
---|
| 733 | List<XYDataset> loadDiagram = resourceLoadDiagrams.get(resLoadStats.getResourceType()); |
---|
| 734 | if(loadDiagram == null){ |
---|
| 735 | loadDiagram = new ArrayList<XYDataset>(); |
---|
| 736 | loadDiagram.add(dataset); |
---|
| 737 | resourceLoadDiagrams.put(resLoadStats.getResourceType(), loadDiagram); |
---|
[477] | 738 | } else { |
---|
[496] | 739 | loadDiagram.add(dataset); |
---|
[477] | 740 | } |
---|
| 741 | } |
---|
[496] | 742 | |
---|
| 743 | private void createResourceEnergyDiagramData(ResourceDynamicStats powerConsumptionStats) { |
---|
[477] | 744 | |
---|
[496] | 745 | XYDataset dataset = createResourceChartDataSet(powerConsumptionStats, |
---|
[495] | 746 | startSimulationTime, endSimulationTime); |
---|
| 747 | |
---|
[496] | 748 | List<XYDataset> energyDiagramData = resourcePowerUsageDiagrams.get(powerConsumptionStats.getResourceType()); |
---|
| 749 | if(energyDiagramData == null){ |
---|
| 750 | energyDiagramData = new ArrayList<XYDataset>(); |
---|
| 751 | energyDiagramData.add(dataset); |
---|
| 752 | resourcePowerUsageDiagrams.put(powerConsumptionStats.getResourceType(), energyDiagramData); |
---|
[495] | 753 | } else { |
---|
[496] | 754 | energyDiagramData.add(dataset); |
---|
[495] | 755 | } |
---|
| 756 | } |
---|
[821] | 757 | |
---|
| 758 | private void createResourceTemperatureDiagramData(ResourceDynamicStats temperatureStats) { |
---|
| 759 | |
---|
| 760 | XYDataset dataset = createResourceChartDataSet(temperatureStats, |
---|
| 761 | startSimulationTime, endSimulationTime); |
---|
| 762 | |
---|
| 763 | List<XYDataset> temperatureDiagramData = resourceTemperatureDiagrams.get(temperatureStats.getResourceType()); |
---|
| 764 | if(temperatureDiagramData == null){ |
---|
| 765 | temperatureDiagramData = new ArrayList<XYDataset>(); |
---|
| 766 | temperatureDiagramData.add(dataset); |
---|
| 767 | resourceTemperatureDiagrams.put(temperatureStats.getResourceType(), temperatureDiagramData); |
---|
| 768 | } else { |
---|
| 769 | temperatureDiagramData.add(dataset); |
---|
| 770 | } |
---|
| 771 | } |
---|
[477] | 772 | |
---|
[496] | 773 | private void createResourceAirFlowDiagramData(ResourceDynamicStats airFlowStats) { |
---|
[477] | 774 | |
---|
[496] | 775 | XYDataset dataset = createResourceChartDataSet(airFlowStats, |
---|
| 776 | startSimulationTime, endSimulationTime); |
---|
| 777 | |
---|
| 778 | List<XYDataset> airFlowDiagramData = resourceAirFlowDiagrams.get(airFlowStats.getResourceType()); |
---|
| 779 | if(airFlowDiagramData == null){ |
---|
| 780 | airFlowDiagramData = new ArrayList<XYDataset>(); |
---|
| 781 | airFlowDiagramData.add(dataset); |
---|
| 782 | resourceAirFlowDiagrams.put(airFlowStats.getResourceType(), airFlowDiagramData); |
---|
| 783 | } else { |
---|
| 784 | airFlowDiagramData.add(dataset); |
---|
[477] | 785 | } |
---|
| 786 | } |
---|
| 787 | |
---|
[496] | 788 | private XYDataset createResourceChartDataSet( |
---|
| 789 | ResourceDynamicStats dynamicStats, long start, long end) { |
---|
[477] | 790 | |
---|
[496] | 791 | Map<Long, Double> chartData = getResourceChartRawData(dynamicStats); |
---|
[495] | 792 | XYSeriesCollection dataset = new XYSeriesCollection(); |
---|
[496] | 793 | XYSeries data = new XYSeries(dynamicStats.getResourceName(), false, true); |
---|
[687] | 794 | data.add(start, 0); |
---|
[496] | 795 | for (Long key : chartData.keySet()) { |
---|
| 796 | Double val = chartData.get(key); |
---|
[687] | 797 | if(key >= startSimulationTime) |
---|
| 798 | data.add(key, val); |
---|
[495] | 799 | } |
---|
| 800 | data.add(end, 0); |
---|
| 801 | dataset.addSeries(data); |
---|
| 802 | return dataset; |
---|
| 803 | } |
---|
| 804 | |
---|
[496] | 805 | private Map<Long, Double> getResourceChartRawData( |
---|
| 806 | ResourceDynamicStats dynamicStats) { |
---|
[495] | 807 | |
---|
[496] | 808 | Map<Long, Double> history = dynamicStats.getHistory(); |
---|
| 809 | Map<Long, Double> chartData = new TreeMap<Long, Double>(); |
---|
| 810 | for (Long key : history.keySet()) { |
---|
| 811 | chartData.put(key, history.get(key)); |
---|
[495] | 812 | } |
---|
[496] | 813 | return chartData; |
---|
[495] | 814 | } |
---|
| 815 | |
---|
[477] | 816 | private boolean saveResourceGanttDiagrams() { |
---|
[496] | 817 | |
---|
[477] | 818 | if (!generateDiagrams) |
---|
| 819 | return false; |
---|
| 820 | |
---|
| 821 | String fileName = new File(outputFolderName, DIAGRAMS_FILE_NAME_PREFIX |
---|
| 822 | + simulationIdentifier + "_").getAbsolutePath(); |
---|
| 823 | |
---|
| 824 | String chartName = "Gantt diagram for " |
---|
| 825 | + DataCenterWorkloadSimulator.SIMULATOR_NAME; |
---|
| 826 | String simulationTime = "Simulation time"; |
---|
| 827 | Title subtitle = new TextTitle("created for \"" + simulationIdentifier |
---|
| 828 | + "\" at " + Calendar.getInstance().getTime().toString()); |
---|
| 829 | |
---|
[496] | 830 | JFreeChart peDiagram = null; |
---|
[501] | 831 | if (configuration.creatediagrams_gantt) { |
---|
[496] | 832 | peDiagram = getPEGanttDiagram(chartName, subtitle, |
---|
[477] | 833 | simulationTime); |
---|
| 834 | if (!saveCategoryChart(peDiagram, fileName + "Gantt", |
---|
| 835 | "{0}")) |
---|
| 836 | return false; |
---|
| 837 | } |
---|
[687] | 838 | chartName = "Load diagram for " |
---|
| 839 | + DataCenterWorkloadSimulator.SIMULATOR_NAME; |
---|
[496] | 840 | JFreeChart resourceLoadDiagram = null; |
---|
[501] | 841 | if (configuration.creatediagrams_resutilization) { |
---|
[496] | 842 | String axisName = "UTILIZATION [%]"; |
---|
[477] | 843 | for(ResourceType resType: resourceLoadDiagrams.keySet()){ |
---|
[496] | 844 | resourceLoadDiagram = getResourceDynamicDiagram(resourceLoadDiagrams.get(resType), simulationTime, chartName, |
---|
| 845 | subtitle, axisName); |
---|
[794] | 846 | if (!saveXYPlotChart(resourceLoadDiagram, fileName + "Resources Load - "+resType.getName())) |
---|
[477] | 847 | return false; |
---|
| 848 | } |
---|
| 849 | } |
---|
[496] | 850 | |
---|
[687] | 851 | chartName = "Energy usage diagram for " |
---|
| 852 | + DataCenterWorkloadSimulator.SIMULATOR_NAME; |
---|
[496] | 853 | JFreeChart resourceEnergyDiagram = null; |
---|
[501] | 854 | if (configuration.creatediagrams_respowerusage) { |
---|
[496] | 855 | String axisName = "POWER [W]"; |
---|
[495] | 856 | for(ResourceType resType: resourcePowerUsageDiagrams.keySet()){ |
---|
[496] | 857 | resourceEnergyDiagram = getResourceDynamicDiagram(resourcePowerUsageDiagrams.get(resType), simulationTime, chartName, |
---|
| 858 | subtitle, axisName); |
---|
[794] | 859 | if (!saveXYPlotChart(resourceEnergyDiagram, fileName + "Energy - "+resType.getName())) |
---|
[477] | 860 | return false; |
---|
| 861 | } |
---|
| 862 | } |
---|
[495] | 863 | |
---|
[687] | 864 | chartName = "Air flow diagram for " |
---|
| 865 | + DataCenterWorkloadSimulator.SIMULATOR_NAME; |
---|
[496] | 866 | JFreeChart resourceAirFlowDiagram = null; |
---|
[501] | 867 | if (configuration.creatediagrams_resairflow) { |
---|
[496] | 868 | String axisName = "AIR FLOW [m^3/min]"; |
---|
[495] | 869 | for(ResourceType resType: resourceAirFlowDiagrams.keySet()){ |
---|
[496] | 870 | resourceAirFlowDiagram = getResourceDynamicDiagram(resourceAirFlowDiagrams.get(resType), simulationTime, chartName, |
---|
| 871 | subtitle, axisName); |
---|
[794] | 872 | if (!saveXYPlotChart(resourceAirFlowDiagram, fileName + "AirThroughput - "+resType.getName())) |
---|
[495] | 873 | return false; |
---|
| 874 | } |
---|
| 875 | } |
---|
[821] | 876 | |
---|
| 877 | chartName = "Temperature diagram for " |
---|
| 878 | + DataCenterWorkloadSimulator.SIMULATOR_NAME; |
---|
| 879 | JFreeChart resourceTemperatureDiagram = null; |
---|
| 880 | if (configuration.creatediagrams_restemperature) { |
---|
| 881 | String axisName = "TEMPERATURE [C]"; |
---|
| 882 | for(ResourceType resType: resourceTemperatureDiagrams.keySet()){ |
---|
| 883 | resourceTemperatureDiagram = getResourceDynamicDiagram(resourceTemperatureDiagrams.get(resType), simulationTime, chartName, |
---|
| 884 | subtitle, axisName); |
---|
| 885 | if (!saveXYPlotChart(resourceTemperatureDiagram, fileName + "Temperature - "+resType.getName())) |
---|
| 886 | return false; |
---|
| 887 | } |
---|
| 888 | } |
---|
[477] | 889 | return true; |
---|
| 890 | } |
---|
| 891 | |
---|
[496] | 892 | private JFreeChart getPEGanttDiagram(String chartName, Title subtitle, |
---|
[477] | 893 | String simulationTime) { |
---|
[496] | 894 | String processors = "Processing Elements"; |
---|
[477] | 895 | boolean tooltip = true; |
---|
| 896 | boolean legend = true; |
---|
[496] | 897 | JFreeChart chart = TimetableChartFactory.createTimetableChart( |
---|
| 898 | chartName, processors, simulationTime, |
---|
| 899 | ganttDiagramTimetable, legend, tooltip); |
---|
[477] | 900 | chart.addSubtitle(subtitle); |
---|
[496] | 901 | TimetableRenderer rend = (TimetableRenderer) chart.getCategoryPlot() |
---|
| 902 | .getRenderer(); |
---|
| 903 | rend.setBackgroundBarPaint(null); |
---|
[477] | 904 | return chart; |
---|
| 905 | } |
---|
| 906 | |
---|
[496] | 907 | private JFreeChart getResourceDynamicDiagram(List<XYDataset> diagramData, String simulationTime, String chartName, Title subtitle, |
---|
| 908 | String axisName) { |
---|
[495] | 909 | boolean urls = false; |
---|
| 910 | boolean tooltip = true; |
---|
| 911 | boolean legend = true; |
---|
| 912 | CombinedDomainXYPlot cPlot = new CombinedDomainXYPlot(); |
---|
| 913 | DateAxis xAxis = new DateAxis(simulationTime); |
---|
[496] | 914 | JFreeChart chart = null; |
---|
[495] | 915 | |
---|
[496] | 916 | for (XYDataset dataset : diagramData) { |
---|
[495] | 917 | JFreeChart tChart = ChartFactory.createXYStepAreaChart("", "", |
---|
[496] | 918 | null, dataset, PlotOrientation.VERTICAL, legend, tooltip, urls); |
---|
[495] | 919 | XYPlot tPlot = tChart.getXYPlot(); |
---|
[496] | 920 | NumberAxis yAxis = new NumberAxis(axisName); |
---|
[495] | 921 | yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); |
---|
| 922 | tPlot.setRangeAxis(yAxis); |
---|
| 923 | XYStepAreaRenderer rend = (XYStepAreaRenderer) tPlot.getRenderer(); |
---|
| 924 | rend.setShapesVisible(false); |
---|
| 925 | cPlot.add(tPlot); |
---|
| 926 | } |
---|
| 927 | cPlot.setDomainAxis(xAxis); |
---|
| 928 | cPlot.setDomainAxisLocation(AxisLocation.TOP_OR_LEFT); |
---|
[496] | 929 | chart = new JFreeChart(chartName, cPlot); |
---|
[495] | 930 | chart.addSubtitle(subtitle); |
---|
| 931 | return chart; |
---|
| 932 | } |
---|
[477] | 933 | |
---|
| 934 | private boolean saveXYPlotChart(JFreeChart c, String fileName) { |
---|
| 935 | c.setNotify(false); |
---|
| 936 | c.setAntiAlias(true); |
---|
| 937 | c.setTextAntiAlias(true); |
---|
| 938 | c.setBorderVisible(false); |
---|
| 939 | |
---|
| 940 | int height = 900; |
---|
| 941 | |
---|
| 942 | CombinedDomainXYPlot cPlot = (CombinedDomainXYPlot) c.getPlot(); |
---|
| 943 | int nPlots = cPlot.getSubplots().size(); |
---|
| 944 | |
---|
| 945 | if (nPlots > 3) { |
---|
| 946 | height = nPlots * 300; |
---|
| 947 | } |
---|
| 948 | int width = GANTT_WIDTH; |
---|
| 949 | |
---|
| 950 | if (configuration.creatediagrams_resources_scale != -1) |
---|
| 951 | width = (int) ((endSimulationTime - startSimulationTime) * configuration.creatediagrams_resources_scale); |
---|
| 952 | ChartRenderingInfo info = new ChartRenderingInfo(); |
---|
| 953 | File f = new File(fileName + "." + ImageFormat.PNG); |
---|
[494] | 954 | final String dcwormsSubtitle = "Created by " |
---|
[477] | 955 | + DataCenterWorkloadSimulator.SIMULATOR_NAME |
---|
| 956 | + " http://www.gssim.org/"; |
---|
[494] | 957 | c.addSubtitle(new TextTitle(dcwormsSubtitle)); |
---|
[477] | 958 | boolean encodeAlpha = false; |
---|
| 959 | int compression = 9;// values 0-9 |
---|
| 960 | try { |
---|
| 961 | ChartUtilities.saveChartAsPNG(f, c, width, height, info, |
---|
| 962 | encodeAlpha, compression); |
---|
| 963 | } catch (IOException e) { |
---|
| 964 | e.printStackTrace(); |
---|
| 965 | return false; |
---|
| 966 | } |
---|
| 967 | return true; |
---|
| 968 | } |
---|
| 969 | |
---|
| 970 | private void createPEGanttDiagram(Map<String,List<ResStat>> basicResStats) { |
---|
| 971 | for(String peName: basicResStats.keySet()){ |
---|
| 972 | TimetableEventSource pe = new TimetableEventSource(peName); |
---|
[496] | 973 | ganttDiagramTimetable.addEventSource(pe); |
---|
[477] | 974 | peGanttMap.put(peName, pe); |
---|
| 975 | for(ResStat resStat: basicResStats.get(peName)){ |
---|
| 976 | |
---|
| 977 | pe = peGanttMap.get(resStat.getPeName()); |
---|
| 978 | if(pe == null){ |
---|
| 979 | //pe = new TimetableEventSource(resStat.getPeName()); |
---|
| 980 | // ganttDiagramPeTimetable.addEventSource(pe); |
---|
| 981 | // peGanttMap.put(resStat.getPeName(), pe); |
---|
| 982 | } |
---|
| 983 | TimetableEventGroup task = taskGanttMap.get(resStat.getTaskID()); |
---|
| 984 | long startDate = resStat.getStartDate(); |
---|
| 985 | long endDate = resStat.getEndDate(); |
---|
| 986 | if (task == null) { |
---|
| 987 | task = new TimetableEventGroup(resStat.getTaskID()); |
---|
| 988 | taskGanttMap.put(resStat.getTaskID(), task); |
---|
[496] | 989 | ganttDiagramTimetable.addEventGroup(task); |
---|
[477] | 990 | } |
---|
[496] | 991 | ganttDiagramTimetable.addEvent(pe, task, |
---|
[477] | 992 | new FixedMillisecond(startDate), new FixedMillisecond(endDate)); |
---|
| 993 | } |
---|
| 994 | } |
---|
| 995 | } |
---|
| 996 | |
---|
| 997 | |
---|
[497] | 998 | //TO DO |
---|
[477] | 999 | private void createAccumulatedResourceSimulationStatistic() { |
---|
| 1000 | |
---|
| 1001 | List<ComputingResource> resources = resourceController.getComputingResources(); |
---|
| 1002 | for(ComputingResource compRes: resources){ |
---|
| 1003 | //for(ComputingResource child :compRes.getChildren()){ |
---|
[497] | 1004 | |
---|
| 1005 | //ResourceUsageStats resourceUsage = gatherResourceLoadStats(compRes, basicResStats); |
---|
| 1006 | //double load = calculateMeanValue(resourceUsage); |
---|
[477] | 1007 | double load = calculateResourceLoad(compRes, basicResLoad); |
---|
| 1008 | accStats.meanTotalLoad.add(load); |
---|
| 1009 | /*ResourceEnergyStats energyUsage = gatherResourceEnergyStats(compRes); |
---|
| 1010 | energyUsage.setMeanUsage(calculateEnergyLoad(energyUsage)); |
---|
| 1011 | accStats.meanEnergyUsage.add(energyUsage.meanUsage);*/ |
---|
| 1012 | //} |
---|
| 1013 | } |
---|
| 1014 | } |
---|
| 1015 | |
---|
[497] | 1016 | private Map<String, Double> calculatePELoad(Map<String, List<ResStat>> basicResStats){ |
---|
| 1017 | Map<String, Double> peLoad = new HashMap<String, Double>(); |
---|
[477] | 1018 | for(String resName: basicResStats.keySet()){ |
---|
| 1019 | List<ResStat> resStats = basicResStats.get(resName); |
---|
| 1020 | double sum = 0; |
---|
| 1021 | for(ResStat resStat:resStats){ |
---|
| 1022 | sum += (resStat.endDate - resStat.startDate); |
---|
| 1023 | } |
---|
| 1024 | double load = sum / (endSimulationTime - startSimulationTime); |
---|
| 1025 | peLoad.put(resName, load); |
---|
| 1026 | } |
---|
| 1027 | return peLoad; |
---|
| 1028 | } |
---|
| 1029 | |
---|
[496] | 1030 | private Double calculateResourceLoad(ComputingResource resource, Map<String, Double> peLoad ){ |
---|
[477] | 1031 | int peCnt = 0; |
---|
| 1032 | double sum = 0; |
---|
| 1033 | for(String resName: peLoad.keySet()){ |
---|
| 1034 | |
---|
| 1035 | try { |
---|
| 1036 | if(resource.getDescendantByName(resName) != null || resource.getName().compareTo(resName) == 0){ |
---|
| 1037 | Double load = peLoad.get(resName); |
---|
| 1038 | sum += load; |
---|
| 1039 | peCnt++; |
---|
| 1040 | } |
---|
| 1041 | } catch (ResourceException e) { |
---|
| 1042 | // TODO Auto-generated catch block |
---|
| 1043 | e.printStackTrace(); |
---|
| 1044 | } |
---|
| 1045 | } |
---|
| 1046 | |
---|
| 1047 | return sum/peCnt; |
---|
| 1048 | } |
---|
[496] | 1049 | |
---|
[477] | 1050 | |
---|
[496] | 1051 | private double calculateMeanValue(ResourceDynamicStats resDynamicStats ){ |
---|
| 1052 | double meanValue = 0; |
---|
[687] | 1053 | long time = -1; |
---|
[496] | 1054 | double value = 0; |
---|
| 1055 | |
---|
| 1056 | Map<Long, Double> history = resDynamicStats.getHistory(); |
---|
| 1057 | for (Long key : history.keySet()) { |
---|
[477] | 1058 | |
---|
[687] | 1059 | if(key >= startSimulationTime){ |
---|
| 1060 | if (time != -1) { |
---|
| 1061 | meanValue += (value * (key - time)) / (endSimulationTime - startSimulationTime); |
---|
| 1062 | time = key; |
---|
| 1063 | } else { |
---|
| 1064 | time = key; |
---|
| 1065 | } |
---|
[477] | 1066 | } |
---|
[496] | 1067 | value = history.get(key); |
---|
[477] | 1068 | } |
---|
[496] | 1069 | return meanValue; |
---|
[477] | 1070 | } |
---|
| 1071 | |
---|
[496] | 1072 | |
---|
[495] | 1073 | |
---|
| 1074 | |
---|
| 1075 | |
---|
[477] | 1076 | |
---|
[496] | 1077 | |
---|
[477] | 1078 | |
---|
| 1079 | |
---|
| 1080 | /************* TASK STATISTICS SECTION **************/ |
---|
| 1081 | public void gatherTaskStatistics() { |
---|
| 1082 | |
---|
| 1083 | List<JobInterface<?>> jobs = users.getAllReceivedJobs(); |
---|
| 1084 | Collections.sort(jobs, new JobIdComparator()); |
---|
| 1085 | |
---|
| 1086 | ganttDiagramTaskSeriesCollection = new TaskSeriesCollection(); |
---|
| 1087 | ganttDiagramWaitingTimeSeriesCollection = new TaskSeriesCollection(); |
---|
| 1088 | |
---|
| 1089 | PrintStream taskStatsFile = null; |
---|
| 1090 | try { |
---|
| 1091 | File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_" |
---|
| 1092 | + RAW_TASKS_STATISTICS_OUTPUT_FILE_NAME); |
---|
| 1093 | taskStatsFile = new PrintStream(new FileOutputStream(file)); |
---|
| 1094 | } catch (IOException e) { |
---|
| 1095 | taskStatsFile = null; |
---|
| 1096 | } |
---|
| 1097 | |
---|
| 1098 | PrintStream jobStatsFile = null; |
---|
| 1099 | if (configuration.createjobsstatistics) { |
---|
| 1100 | try { |
---|
| 1101 | File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX + simulationIdentifier + "_" |
---|
| 1102 | + JOBS_STATISTICS_OUTPUT_FILE_NAME); |
---|
| 1103 | jobStatsFile = new PrintStream(new FileOutputStream(file)); |
---|
| 1104 | } catch (IOException e) { |
---|
| 1105 | jobStatsFile = null; |
---|
| 1106 | } |
---|
| 1107 | } |
---|
| 1108 | |
---|
| 1109 | for (int i = 0; i < jobs.size(); i++) { |
---|
| 1110 | Job job = (Job) jobs.get(i); |
---|
| 1111 | |
---|
[481] | 1112 | List<Executable> execList = jr.getExecutableTasks().getJobExecutables(job.getId()); |
---|
[477] | 1113 | List<TaskStats> taskStatsList = new ArrayList<TaskStats>(); |
---|
| 1114 | |
---|
| 1115 | this.serializer.setFieldSeparator(TASK_SEPARATOR); |
---|
| 1116 | |
---|
| 1117 | for (int j = 0; j < execList.size(); j++) { |
---|
| 1118 | |
---|
| 1119 | Executable task = (Executable) execList.get(j); |
---|
| 1120 | |
---|
| 1121 | TaskStats taskStats = createTaskStats(task); |
---|
| 1122 | if (taskStats != null && taskStatsFile != null) { |
---|
| 1123 | Object txt = taskStats.serialize(serializer); |
---|
| 1124 | taskStatsFile.println(txt); |
---|
| 1125 | } |
---|
| 1126 | if (taskStats != null && taskStats.getExecFinishDate() != -1) { |
---|
| 1127 | if (configuration.createsimulationstatistics) { |
---|
| 1128 | createAccumulatedTaskSimulationStatistic(taskStats); |
---|
| 1129 | } |
---|
| 1130 | allTasksFinished &= task.isFinished(); |
---|
| 1131 | if (generateDiagrams) { |
---|
| 1132 | if (configuration.creatediagrams_tasks) |
---|
| 1133 | createTaskDiagramData(task); |
---|
| 1134 | if (configuration.creatediagrams_taskswaitingtime) |
---|
| 1135 | createTaskWaitingTimeDiagramData(task); |
---|
| 1136 | } |
---|
| 1137 | taskStatsList.add(taskStats); |
---|
| 1138 | } |
---|
| 1139 | } |
---|
| 1140 | if (configuration.createjobsstatistics && taskStatsList.size() > 0) { |
---|
| 1141 | |
---|
| 1142 | this.serializer.setFieldSeparator(JOB_SEPARATOR); |
---|
| 1143 | JobStats jobStats = createJobStats(taskStatsList); |
---|
| 1144 | if (jobStatsFile != null) { |
---|
| 1145 | Object txt = jobStats.serialize(serializer); |
---|
| 1146 | jobStatsFile.println(txt); |
---|
| 1147 | } |
---|
| 1148 | } |
---|
| 1149 | } |
---|
| 1150 | |
---|
| 1151 | if (configuration.createsimulationstatistics) { |
---|
| 1152 | accStats.makespan.add(maxCj); |
---|
| 1153 | accStats.delayedTasks.add(numOfdelayedTasks); |
---|
| 1154 | accStats.failedRequests.add(users.getAllSentTasks().size() - users.getFinishedTasksCount()); |
---|
| 1155 | if(resourceController.getScheduler().getType().getName().equals("GS")){ |
---|
| 1156 | for(Scheduler sched: resourceController.getScheduler().getChildren()){ |
---|
| 1157 | accStats.meanQueueLength.add(getSchedulerQueueStats(sched)); |
---|
| 1158 | } |
---|
| 1159 | } |
---|
| 1160 | else { |
---|
| 1161 | accStats.meanQueueLength.add(getSchedulerQueueStats(resourceController.getScheduler())); |
---|
| 1162 | } |
---|
| 1163 | } |
---|
| 1164 | |
---|
| 1165 | saveTaskGanttDiagrams(); |
---|
| 1166 | |
---|
| 1167 | if (taskStatsFile != null) { |
---|
| 1168 | taskStatsFile.close(); |
---|
| 1169 | } |
---|
| 1170 | if (jobStatsFile != null) { |
---|
| 1171 | jobStatsFile.close(); |
---|
| 1172 | } |
---|
| 1173 | } |
---|
| 1174 | |
---|
[496] | 1175 | private double getSchedulerQueueStats(Scheduler scheduler) { |
---|
| 1176 | |
---|
| 1177 | Sim_stat stats = scheduler.get_stat(); |
---|
| 1178 | List<Object[]> measures = stats.get_measures(); |
---|
| 1179 | for (Object[] info : measures) { |
---|
| 1180 | String measure = (String) info[0]; |
---|
| 1181 | if (measure |
---|
| 1182 | .startsWith(DCWormsConstants.TASKS_QUEUE_LENGTH_MEASURE_NAME)) { |
---|
| 1183 | return stats.average(measure); |
---|
| 1184 | } |
---|
| 1185 | } |
---|
| 1186 | return 0; |
---|
| 1187 | } |
---|
| 1188 | |
---|
[477] | 1189 | private TaskStats createTaskStats(Executable task) { |
---|
| 1190 | TaskStats taskStats = new TaskStats(task, startSimulationTime); |
---|
| 1191 | String uniqueTaskID = taskStats.getJobID() + "_" + taskStats.getTaskID(); |
---|
| 1192 | taskStats.setProcessorsName(task_processorsMap.get(uniqueTaskID)); |
---|
| 1193 | return taskStats; |
---|
| 1194 | } |
---|
| 1195 | |
---|
| 1196 | private JobStats createJobStats(List<TaskStats> tasksStats) { |
---|
| 1197 | |
---|
| 1198 | String jobID = ((TaskStats) tasksStats.get(0)).getJobID(); |
---|
| 1199 | JobStats jobStats = new JobStats(jobID); |
---|
| 1200 | double maxCj = 0; |
---|
| 1201 | |
---|
| 1202 | for (int i = 0; i < tasksStats.size(); i++) { |
---|
| 1203 | |
---|
| 1204 | TaskStats task = (TaskStats) tasksStats.get(i); |
---|
| 1205 | jobStats.meanTaskStartTime.add(task.getStartTime()); |
---|
| 1206 | jobStats.meanTaskCompletionTime.add(task.getCompletionTime()); |
---|
| 1207 | maxCj = Math.max(maxCj, task.getCompletionTime()); |
---|
| 1208 | jobStats.meanTaskExecutionTime.add(task.getExecutionTime()); |
---|
| 1209 | jobStats.meanTaskWaitingTime.add(task.getWaitingTime()); |
---|
| 1210 | jobStats.meanTaskFlowTime.add(task.getFlowTime()); |
---|
| 1211 | jobStats.meanTaskGQ_WaitingTime.add(task.getGQ_WaitingTime()); |
---|
| 1212 | jobStats.lateness.add(task.getLateness()); |
---|
| 1213 | jobStats.tardiness.add(task.getTardiness()); |
---|
| 1214 | } |
---|
| 1215 | jobStats.makespan.add(maxCj); |
---|
| 1216 | |
---|
| 1217 | return jobStats; |
---|
| 1218 | } |
---|
| 1219 | |
---|
| 1220 | private void createAccumulatedTaskSimulationStatistic(TaskStats taskStats) { |
---|
| 1221 | accStats.meanTaskFlowTime.add(taskStats.getFlowTime()); |
---|
| 1222 | accStats.meanTaskExecutionTime.add(taskStats.getExecutionTime()); |
---|
| 1223 | accStats.meanTaskCompletionTime.add(taskStats.getCompletionTime()); |
---|
| 1224 | accStats.meanTaskWaitingTime.add(taskStats.getWaitingTime()); |
---|
| 1225 | accStats.meanTaskStartTime.add(taskStats.getStartTime()); |
---|
| 1226 | |
---|
| 1227 | accStats.lateness.add(taskStats.getLateness()); |
---|
| 1228 | accStats.tardiness.add(taskStats.getTardiness()); |
---|
| 1229 | |
---|
| 1230 | if (taskStats.getExecFinishDate() == -1) { |
---|
| 1231 | numOfNotExecutedTasks++; |
---|
| 1232 | } |
---|
| 1233 | if (taskStats.getTardiness() > 0.0) { |
---|
| 1234 | numOfdelayedTasks++; |
---|
| 1235 | } |
---|
| 1236 | |
---|
| 1237 | maxCj = Math.max(maxCj, taskStats.getCompletionTime()); |
---|
| 1238 | } |
---|
| 1239 | |
---|
| 1240 | private void createTaskDiagramData(Executable task) { |
---|
| 1241 | String uniqueTaskID = task.getJobId() + "_" + task.getId(); |
---|
| 1242 | |
---|
[481] | 1243 | String resID = task.getSchedulerName(); |
---|
[477] | 1244 | |
---|
[481] | 1245 | long execStartTime = Double.valueOf(task.getExecStartTime()).longValue() * MILLI_SEC; |
---|
| 1246 | long execEndTime = Double.valueOf(task.getFinishTime()).longValue() * MILLI_SEC; |
---|
[477] | 1247 | |
---|
| 1248 | TaskSeries taskRes = ganttDiagramTaskSeriesCollection.getSeries(resID); |
---|
| 1249 | if (taskRes == null) { |
---|
| 1250 | taskRes = new TaskSeries(resID); |
---|
| 1251 | ganttDiagramTaskSeriesCollection.add(taskRes); |
---|
| 1252 | } |
---|
| 1253 | org.jfree.data.gantt.Task ganttTask = new org.jfree.data.gantt.Task(uniqueTaskID, new Date(execStartTime), |
---|
| 1254 | new Date(execEndTime)); |
---|
| 1255 | if (!task.isFinished()) { |
---|
| 1256 | ganttTask.setPercentComplete(1.0); |
---|
| 1257 | } |
---|
| 1258 | taskRes.add(ganttTask); |
---|
| 1259 | } |
---|
| 1260 | |
---|
| 1261 | private void createTaskWaitingTimeDiagramData(Executable task) { |
---|
| 1262 | String uniqueTaskID = task.getJobId() + "_" + task.getId(); |
---|
| 1263 | |
---|
[481] | 1264 | String resID = task.getSchedulerName(); |
---|
[477] | 1265 | |
---|
[481] | 1266 | long execStartTime = Double.valueOf(task.getExecStartTime()).longValue() * MILLI_SEC; |
---|
| 1267 | long execEndTime = Double.valueOf(task.getFinishTime()).longValue() * MILLI_SEC; |
---|
[477] | 1268 | |
---|
| 1269 | TaskSeries waitRes = ganttDiagramWaitingTimeSeriesCollection.getSeries(resID); |
---|
| 1270 | if (waitRes == null) { |
---|
| 1271 | waitRes = new TaskSeries(resID); |
---|
| 1272 | ganttDiagramWaitingTimeSeriesCollection.add(waitRes); |
---|
| 1273 | } |
---|
| 1274 | |
---|
[481] | 1275 | long sub = Double.valueOf(task.getSubmissionTime()).longValue() * MILLI_SEC; |
---|
[477] | 1276 | org.jfree.data.gantt.Task wait_exec = new org.jfree.data.gantt.Task(uniqueTaskID, new Date(sub), new Date( |
---|
| 1277 | execEndTime)); |
---|
| 1278 | org.jfree.data.gantt.Task exec = new org.jfree.data.gantt.Task(uniqueTaskID, new Date(execStartTime), new Date( |
---|
| 1279 | execEndTime)); |
---|
| 1280 | if (!task.isFinished()) { |
---|
| 1281 | exec.setPercentComplete(1.0); |
---|
| 1282 | } |
---|
| 1283 | wait_exec.addSubtask(wait_exec); |
---|
| 1284 | wait_exec.addSubtask(exec); |
---|
| 1285 | waitRes.add(wait_exec); |
---|
| 1286 | } |
---|
| 1287 | |
---|
| 1288 | private boolean saveTaskGanttDiagrams() { |
---|
| 1289 | |
---|
| 1290 | JFreeChart taskDiagram = null; |
---|
| 1291 | JFreeChart waitingTimeDiagram = null; |
---|
| 1292 | |
---|
| 1293 | if (!generateDiagrams) |
---|
| 1294 | return false; |
---|
| 1295 | |
---|
| 1296 | String fileName = new File(outputFolderName, DIAGRAMS_FILE_NAME_PREFIX + simulationIdentifier + "_") |
---|
| 1297 | .getAbsolutePath(); |
---|
| 1298 | |
---|
[687] | 1299 | String chartName = "Task diagram for " + DataCenterWorkloadSimulator.SIMULATOR_NAME; |
---|
[477] | 1300 | String simulationTime = "Simulation time"; |
---|
| 1301 | Title subtitle = new TextTitle("created for \"" + simulationIdentifier + "\" at " |
---|
| 1302 | + Calendar.getInstance().getTime().toString()); |
---|
| 1303 | |
---|
| 1304 | if (configuration.creatediagrams_tasks) { |
---|
| 1305 | taskDiagram = getTaskDiagram(chartName, subtitle, simulationTime); |
---|
| 1306 | if (!saveCategoryChart(taskDiagram, fileName + "Tasks", null /* "{0}" */)) |
---|
| 1307 | return false; |
---|
| 1308 | } |
---|
| 1309 | |
---|
[687] | 1310 | chartName = "Task waiting times diagram for " + DataCenterWorkloadSimulator.SIMULATOR_NAME; |
---|
[477] | 1311 | if (configuration.creatediagrams_taskswaitingtime) { |
---|
| 1312 | waitingTimeDiagram = getWaitingTimeDiagram(chartName, subtitle, simulationTime); |
---|
| 1313 | if (!saveCategoryChart(waitingTimeDiagram, fileName + "Waiting_Time", null /* "Task {1} at {0}" */)) |
---|
| 1314 | return false; |
---|
| 1315 | } |
---|
| 1316 | |
---|
| 1317 | return true; |
---|
| 1318 | } |
---|
| 1319 | |
---|
| 1320 | private JFreeChart getTaskDiagram(String chartName, Title subtitle, String simulationTime) { |
---|
| 1321 | String tasks = "Tasks"; |
---|
| 1322 | boolean urls = false; |
---|
| 1323 | boolean tooltip = true; |
---|
| 1324 | boolean legend = true; |
---|
| 1325 | JFreeChart chart = ChartFactory.createGanttChart(chartName, tasks, simulationTime, |
---|
| 1326 | ganttDiagramTaskSeriesCollection, legend, tooltip, urls); |
---|
| 1327 | chart.addSubtitle(subtitle); |
---|
| 1328 | GanttRenderer re = (GanttRenderer) chart.getCategoryPlot().getRenderer(); |
---|
| 1329 | re.setCompletePaint(Color.black); |
---|
| 1330 | return chart; |
---|
| 1331 | } |
---|
| 1332 | |
---|
| 1333 | private JFreeChart getWaitingTimeDiagram(String chartName, Title subtitle, String simulationTime) { |
---|
| 1334 | String tasks = "Tasks"; |
---|
| 1335 | boolean urls = false; |
---|
| 1336 | boolean tooltip = true; |
---|
| 1337 | boolean legend = true; |
---|
| 1338 | JFreeChart chart = ChartFactory.createGanttChart(chartName, tasks, simulationTime, |
---|
| 1339 | ganttDiagramWaitingTimeSeriesCollection, legend, tooltip, urls); |
---|
| 1340 | chart.addSubtitle(subtitle); |
---|
| 1341 | chart.getPlot().setForegroundAlpha(ALPHA); |
---|
| 1342 | GanttRenderer re = (GanttRenderer) chart.getCategoryPlot().getRenderer(); |
---|
| 1343 | re.setCompletePaint(Color.black); |
---|
| 1344 | return chart; |
---|
| 1345 | } |
---|
| 1346 | |
---|
| 1347 | private boolean saveCategoryChart(JFreeChart c, String fileName, String labelFormat) { |
---|
| 1348 | c.setNotify(false); |
---|
| 1349 | c.setAntiAlias(true); |
---|
| 1350 | c.setTextAntiAlias(true); |
---|
| 1351 | c.setBorderVisible(false); |
---|
| 1352 | |
---|
| 1353 | CategoryPlot categoryplot = (CategoryPlot) c.getPlot(); |
---|
| 1354 | categoryplot.setDomainGridlinesVisible(true); |
---|
| 1355 | |
---|
| 1356 | if (labelFormat != null) { |
---|
| 1357 | CategoryItemRenderer rend = categoryplot.getRenderer(); |
---|
| 1358 | rend.setBaseItemLabelsVisible(true); |
---|
| 1359 | ItemLabelPosition position = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER); |
---|
| 1360 | rend.setBasePositiveItemLabelPosition(position); |
---|
| 1361 | NumberFormat nf = NumberFormat.getInstance(); |
---|
| 1362 | CategoryItemLabelGenerator gen = new StandardCategoryItemLabelGenerator(labelFormat, nf); |
---|
| 1363 | rend.setBaseItemLabelGenerator(gen); |
---|
| 1364 | } |
---|
| 1365 | |
---|
| 1366 | int rows = c.getCategoryPlot().getDataset().getColumnKeys().size(); |
---|
| 1367 | |
---|
| 1368 | int height = 900; |
---|
| 1369 | if (rows > 45) { |
---|
| 1370 | height = rows * 20; |
---|
| 1371 | } |
---|
| 1372 | int width = calculateChartWidth(c); |
---|
| 1373 | CategoryItemRenderer rend = c.getCategoryPlot().getRenderer(); |
---|
| 1374 | |
---|
| 1375 | for (int i = 0; i < c.getCategoryPlot().getDataset().getRowKeys().size(); i++) { |
---|
| 1376 | Paint collor = c.getCategoryPlot().getDrawingSupplier().getNextPaint(); |
---|
| 1377 | rend.setSeriesOutlinePaint(i, collor); |
---|
| 1378 | rend.setSeriesPaint(i, collor); |
---|
| 1379 | } |
---|
| 1380 | |
---|
| 1381 | ChartRenderingInfo info = new ChartRenderingInfo(); |
---|
| 1382 | // info.setEntityCollection(null); |
---|
| 1383 | File f = new File(fileName + "." + ImageFormat.PNG); |
---|
[494] | 1384 | final String dcwormsSubtitle = "Created by " + DataCenterWorkloadSimulator.SIMULATOR_NAME + " http://www.gssim.org/"; |
---|
| 1385 | c.addSubtitle(new TextTitle(dcwormsSubtitle)); |
---|
[477] | 1386 | boolean encodeAlpha = false; |
---|
| 1387 | int compression = 9; |
---|
| 1388 | try { |
---|
| 1389 | ChartUtilities.saveChartAsPNG(f, c, width, height, info, encodeAlpha, compression); |
---|
| 1390 | |
---|
| 1391 | } catch (IOException e) { |
---|
| 1392 | e.printStackTrace(); |
---|
| 1393 | return false; |
---|
| 1394 | } catch (Exception e) { |
---|
| 1395 | if (log.isErrorEnabled()) |
---|
| 1396 | log.error("The png file (" + fileName |
---|
| 1397 | + ")\nwill not be generated (It can be too large data size problem)", e); |
---|
| 1398 | } catch (Throwable t) { |
---|
| 1399 | log.error("The png file (" + fileName + ")\nwill not be generated (It can be too large data size problem)", |
---|
| 1400 | t); |
---|
| 1401 | } |
---|
| 1402 | |
---|
| 1403 | return true; |
---|
| 1404 | } |
---|
| 1405 | |
---|
| 1406 | private int calculateChartWidth(JFreeChart c) { |
---|
| 1407 | |
---|
| 1408 | int ganttWidth = GANTT_WIDTH; |
---|
| 1409 | int rows = c.getCategoryPlot().getDataset().getColumnKeys().size(); |
---|
| 1410 | |
---|
| 1411 | if (rows > 45) { |
---|
| 1412 | int height = rows * 20; |
---|
| 1413 | ganttWidth = Math.max((int) (height * 1.5), GANTT_WIDTH); |
---|
| 1414 | } |
---|
| 1415 | return ganttWidth; |
---|
| 1416 | } |
---|
| 1417 | |
---|
| 1418 | private static class JobIdComparator implements Comparator<JobInterface<?>> { |
---|
| 1419 | |
---|
| 1420 | public int compare(JobInterface<?> o1, JobInterface<?> o2) { |
---|
| 1421 | Integer o1int; |
---|
| 1422 | Integer o2int; |
---|
| 1423 | try{ |
---|
| 1424 | o1int = Integer.parseInt(o1.getId()); |
---|
| 1425 | o2int = Integer.parseInt(o2.getId()); |
---|
| 1426 | return o1int.compareTo(o2int); |
---|
| 1427 | } catch(NumberFormatException e){ |
---|
| 1428 | return o1.getId().compareTo(o2.getId()); |
---|
| 1429 | } |
---|
| 1430 | } |
---|
| 1431 | } |
---|
| 1432 | |
---|
| 1433 | private static class MapPEIdComparator implements Comparator<String> { |
---|
| 1434 | |
---|
| 1435 | public int compare(String o1, String o2) { |
---|
| 1436 | Integer o1int; |
---|
| 1437 | Integer o2int; |
---|
[821] | 1438 | String o1string; |
---|
| 1439 | String o2string; |
---|
| 1440 | o1string = o1.substring(0, o1.indexOf("_")); |
---|
| 1441 | o2string = o2.substring(0, o2.indexOf("_")); |
---|
[477] | 1442 | o1int = Integer.parseInt(o1.substring(o1.indexOf("_")+1)); |
---|
| 1443 | o2int = Integer.parseInt(o2.substring(o2.indexOf("_")+1)); |
---|
[821] | 1444 | if(o1string.compareTo(o2string) != 0) |
---|
| 1445 | return o1string.compareTo(o2string); |
---|
| 1446 | else |
---|
| 1447 | return o1int.compareTo(o2int); |
---|
[477] | 1448 | } |
---|
| 1449 | } |
---|
| 1450 | |
---|
| 1451 | public GSSAccumulator getStats(String name) { |
---|
| 1452 | return statsData.get(name); |
---|
| 1453 | } |
---|
| 1454 | |
---|
| 1455 | public boolean accumulatedStats() { |
---|
| 1456 | return configuration.createsimulationstatistics; |
---|
| 1457 | } |
---|
| 1458 | |
---|
| 1459 | } |
---|
| 1460 | |
---|
| 1461 | class ResStat{ |
---|
| 1462 | |
---|
| 1463 | public long getStartDate() { |
---|
| 1464 | return startDate; |
---|
| 1465 | } |
---|
| 1466 | public void setStartDate(long startDate) { |
---|
| 1467 | this.startDate = startDate; |
---|
| 1468 | } |
---|
| 1469 | public long getEndDate() { |
---|
| 1470 | return endDate; |
---|
| 1471 | } |
---|
| 1472 | public void setEndDate(long endDate) { |
---|
| 1473 | this.endDate = endDate; |
---|
| 1474 | } |
---|
| 1475 | public String getTaskID() { |
---|
| 1476 | return taskID; |
---|
| 1477 | } |
---|
| 1478 | public void setTaskID(String taskID) { |
---|
| 1479 | this.taskID = taskID; |
---|
| 1480 | } |
---|
| 1481 | |
---|
| 1482 | public ResStat( String peName, long startDate, long endDate, String taskID) { |
---|
| 1483 | super(); |
---|
| 1484 | this.startDate = startDate; |
---|
| 1485 | this.endDate = endDate; |
---|
| 1486 | this.taskID = taskID; |
---|
| 1487 | this.peName = peName; |
---|
| 1488 | } |
---|
| 1489 | public String getPeName() { |
---|
| 1490 | return peName; |
---|
| 1491 | } |
---|
| 1492 | public void setPeName(String peName) { |
---|
| 1493 | this.peName = peName; |
---|
| 1494 | } |
---|
| 1495 | public ResStat(String peName, ResourceType resType, long startDate, long endDate, String taskID) { |
---|
| 1496 | super(); |
---|
| 1497 | this.peName = peName; |
---|
| 1498 | this.resType = resType; |
---|
| 1499 | this.startDate = startDate; |
---|
| 1500 | this.endDate = endDate; |
---|
| 1501 | this.taskID = taskID; |
---|
| 1502 | } |
---|
| 1503 | String peName; |
---|
| 1504 | ResourceType resType; |
---|
| 1505 | long startDate; |
---|
| 1506 | long endDate; |
---|
| 1507 | String taskID; |
---|
| 1508 | |
---|
| 1509 | public ResourceType getResType() { |
---|
| 1510 | return resType; |
---|
| 1511 | } |
---|
| 1512 | public void setResType(ResourceType resType) { |
---|
| 1513 | this.resType = resType; |
---|
| 1514 | } |
---|
| 1515 | } |
---|
| 1516 | |
---|
| 1517 | enum Stats{ |
---|
| 1518 | textLoad, |
---|
| 1519 | chartLoad, |
---|
| 1520 | textEnergy, |
---|
[495] | 1521 | chartEnergy, |
---|
| 1522 | textAirFlow, |
---|
[821] | 1523 | chartAirFlow, |
---|
| 1524 | textTemperature, |
---|
| 1525 | chartTemperature; |
---|
[477] | 1526 | } |
---|