[5] | 1 | package simulator.stats.implementation; |
---|
| 2 | |
---|
| 3 | import eduni.simjava.Sim_stat; |
---|
| 4 | import gridsim.gssim.GssimConstants; |
---|
| 5 | import gridsim.gssim.ResourceHistoryItem; |
---|
| 6 | import gridsim.gssim.ResourceUnitsManagerImpl; |
---|
| 7 | import gridsim.gssim.SubmittedTask; |
---|
| 8 | import gridsim.gssim.network.ExtendedGridSimTags; |
---|
| 9 | import gridsim.gssim.network.flow.reservation.GSSIMFlowLink; |
---|
| 10 | import gridsim.gssim.network.sim.NetworkGridBroker; |
---|
| 11 | import gridsim.gssim.policy.ARAllocationPolicy; |
---|
| 12 | import gridsim.gssim.policy.AbstractAllocationPolicy; |
---|
| 13 | import gridsim.gssim.resource.AbstractComputingResource; |
---|
| 14 | import gridsim.gssim.resource.ResourceProcessors; |
---|
| 15 | import gssim.schedframe.scheduling.AbstractExecutable; |
---|
| 16 | import gssim.schedframe.scheduling.plugin.grid.network.manager.NetworkData; |
---|
| 17 | import gssim.schedframe.scheduling.plugin.grid.network.manager.NetworkReservationObject; |
---|
| 18 | import gssim.schedframe.scheduling.plugin.grid.network.manager.TaskInputFile; |
---|
| 19 | import gssim.schedframe.scheduling.plugin.grid.network.manager.Topology; |
---|
| 20 | |
---|
| 21 | import java.awt.Color; |
---|
| 22 | import java.awt.Paint; |
---|
| 23 | import java.io.File; |
---|
| 24 | import java.io.FileOutputStream; |
---|
| 25 | import java.io.IOException; |
---|
| 26 | import java.io.PrintStream; |
---|
| 27 | import java.text.NumberFormat; |
---|
| 28 | import java.util.ArrayList; |
---|
| 29 | import java.util.Calendar; |
---|
| 30 | import java.util.Collections; |
---|
| 31 | import java.util.Comparator; |
---|
| 32 | import java.util.Date; |
---|
| 33 | import java.util.HashMap; |
---|
| 34 | import java.util.Iterator; |
---|
| 35 | import java.util.List; |
---|
| 36 | import java.util.Map; |
---|
| 37 | import java.util.SortedMap; |
---|
| 38 | import java.util.TreeMap; |
---|
| 39 | |
---|
| 40 | import org.apache.commons.logging.Log; |
---|
| 41 | import org.apache.commons.logging.LogFactory; |
---|
| 42 | import org.jfree.chart.ChartFactory; |
---|
| 43 | import org.jfree.chart.ChartRenderingInfo; |
---|
| 44 | import org.jfree.chart.ChartUtilities; |
---|
| 45 | import org.jfree.chart.JFreeChart; |
---|
| 46 | import org.jfree.chart.axis.AxisLocation; |
---|
| 47 | import org.jfree.chart.axis.DateAxis; |
---|
| 48 | import org.jfree.chart.axis.NumberAxis; |
---|
| 49 | import org.jfree.chart.encoders.ImageFormat; |
---|
| 50 | import org.jfree.chart.labels.CategoryItemLabelGenerator; |
---|
| 51 | import org.jfree.chart.labels.ItemLabelAnchor; |
---|
| 52 | import org.jfree.chart.labels.ItemLabelPosition; |
---|
| 53 | import org.jfree.chart.labels.StandardCategoryItemLabelGenerator; |
---|
| 54 | import org.jfree.chart.plot.CategoryPlot; |
---|
| 55 | import org.jfree.chart.plot.CombinedDomainXYPlot; |
---|
| 56 | import org.jfree.chart.plot.PlotOrientation; |
---|
| 57 | import org.jfree.chart.plot.XYPlot; |
---|
| 58 | import org.jfree.chart.renderer.category.CategoryItemRenderer; |
---|
| 59 | import org.jfree.chart.renderer.category.GanttRenderer; |
---|
| 60 | import org.jfree.chart.renderer.xy.XYStepAreaRenderer; |
---|
| 61 | import org.jfree.chart.title.TextTitle; |
---|
| 62 | import org.jfree.chart.title.Title; |
---|
| 63 | import org.jfree.data.gantt.TaskSeries; |
---|
| 64 | import org.jfree.data.gantt.TaskSeriesCollection; |
---|
| 65 | import org.jfree.data.time.FixedMillisecond; |
---|
| 66 | import org.jfree.data.xy.XYDataset; |
---|
| 67 | import org.jfree.data.xy.XYSeries; |
---|
| 68 | import org.jfree.data.xy.XYSeriesCollection; |
---|
| 69 | import org.jfree.ui.TextAnchor; |
---|
| 70 | import org.joda.time.DateTime; |
---|
| 71 | import org.joda.time.DateTimeUtilsExt; |
---|
| 72 | |
---|
| 73 | import schedframe.resources.profile.PowerUsage; |
---|
| 74 | import schedframe.resources.units.Processor; |
---|
| 75 | import schedframe.resources.units.Processors; |
---|
| 76 | import schedframe.resources.units.ResourceUnit; |
---|
| 77 | import schedframe.scheduling.Job; |
---|
| 78 | import schedframe.scheduling.JobInterface; |
---|
| 79 | import schedframe.scheduling.Reservation; |
---|
| 80 | import schedframe.scheduling.TimeResourceAllocation; |
---|
| 81 | import schedframe.scheduling.utils.ResourceParameterName; |
---|
| 82 | import simulator.AbstractGridBroker; |
---|
| 83 | import simulator.ConfigurationOptions; |
---|
| 84 | import simulator.GenericUser; |
---|
| 85 | import simulator.GridSchedulingSimulator; |
---|
| 86 | import simulator.stats.GSSAccumulator; |
---|
| 87 | import simulator.stats.SimulationStatistics; |
---|
| 88 | import simulator.stats.implementation.out.AbstractStringSerializer; |
---|
| 89 | import simulator.stats.implementation.out.FormatedStringSerializer; |
---|
| 90 | import simulator.stats.implementation.out.StringSerializer; |
---|
| 91 | import csiro.mit.utils.jfreechart.timetablechart.TimetableChartFactory; |
---|
| 92 | import csiro.mit.utils.jfreechart.timetablechart.data.Timetable; |
---|
| 93 | import csiro.mit.utils.jfreechart.timetablechart.data.TimetableEventGroup; |
---|
| 94 | import csiro.mit.utils.jfreechart.timetablechart.data.TimetableEventSource; |
---|
| 95 | import csiro.mit.utils.jfreechart.timetablechart.renderer.TimetableRenderer; |
---|
| 96 | |
---|
| 97 | public class GSSimStatistics implements SimulationStatistics { |
---|
| 98 | |
---|
| 99 | private Log log = LogFactory.getLog(GSSimStatistics.class); |
---|
| 100 | |
---|
| 101 | protected static float ALPHA = 0.5f; |
---|
| 102 | protected static int GANTT_WIDTH = 1200; |
---|
| 103 | |
---|
| 104 | protected static final int BITS = 8; |
---|
| 105 | protected static final int MILLI_SEC = 1000; |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | protected static final String RAW_RESOURCE_STATISTICS_OUTPUT_FILE_NAME = "Raw_Resources.txt"; |
---|
| 109 | protected static final String RAW_TASKS_STATISTICS_OUTPUT_FILE_NAME = "Raw_Tasks.txt"; |
---|
| 110 | protected static final String ACCUMULATED_RESOURCES_STATISTICS_OUTPUT_FILE_NAME = "Accumulated_Resources.txt"; |
---|
| 111 | protected static final String JOBS_STATISTICS_OUTPUT_FILE_NAME = "Jobs.txt"; |
---|
| 112 | protected static final String GRIDLETS_STATISTICS_OUTPUT_FILE_NAME = "Gridlets.txt"; |
---|
| 113 | protected static final String SIMULATION_STATISTICS_OUTPUT_FILE_NAME = "Simulation.txt"; |
---|
| 114 | protected static final String NETWORK_SIMULATION_STATISTICS_OUTPUT_FILE_NAME = "Network.txt"; |
---|
| 115 | protected static final String RESOURCE_LOAD_STATISTICS_OUTPUT_FILE_NAME = "Resource_Load.txt"; |
---|
| 116 | protected static final String ENERGYUSAGE_STATISTICS_OUTPUT_FILE_NAME = "Energy.txt"; |
---|
| 117 | |
---|
| 118 | protected static final String DIAGRAMS_FILE_NAME_PREFIX = "Gantt_"; |
---|
| 119 | protected static final String STATS_FILE_NAME_PREFIX = "Stats_"; |
---|
| 120 | |
---|
| 121 | protected static final String TASK_SEPARATOR = ";"; |
---|
| 122 | protected static final String JOB_HEADER_SEPARATOR = ";"; |
---|
| 123 | protected static final String JOB_SEPARATOR = ";"; |
---|
| 124 | protected static final String RESOURCE_SEPARATOR = ";"; |
---|
| 125 | protected static final String NETWORK_SEPARATOR = ";"; |
---|
| 126 | |
---|
| 127 | protected String outputFolderName; |
---|
| 128 | |
---|
| 129 | protected String simulationIdentifier; |
---|
| 130 | protected ConfigurationOptions configuration; |
---|
| 131 | protected GenericUser users; |
---|
| 132 | protected AbstractGridBroker brokerInterface; |
---|
| 133 | protected AbstractComputingResource gridResources[]; |
---|
| 134 | protected List<Reservation> reservations; |
---|
| 135 | protected HashMap<String, Reservation> reservationsMap; |
---|
| 136 | // protected HashMap<String, String> task_processorMap; |
---|
| 137 | protected HashMap<String, List<String>> task_processorsMap; |
---|
| 138 | protected List<NetworkData> receivedNetData; |
---|
| 139 | protected Topology topology; |
---|
| 140 | |
---|
| 141 | protected long startSimulationTime; |
---|
| 142 | protected long endSimulationTime; |
---|
| 143 | |
---|
| 144 | /* protected GSSAccumulator meanTotalLoad; |
---|
| 145 | protected GSSAccumulator meanReservationLoad; |
---|
| 146 | protected GSSAccumulator meanQueueLength; |
---|
| 147 | protected GSSAccumulator meanEnergyUsage; |
---|
| 148 | |
---|
| 149 | protected GSSAccumulator meanTaskStartTime; |
---|
| 150 | protected GSSAccumulator meanTaskCompletionTime; |
---|
| 151 | protected GSSAccumulator meanTaskExecutionTime; |
---|
| 152 | protected GSSAccumulator meanTaskWaitingTime; |
---|
| 153 | protected GSSAccumulator meanTaskFlowTime; |
---|
| 154 | protected GSSAccumulator lateness; |
---|
| 155 | protected GSSAccumulator tardiness; |
---|
| 156 | protected GSSAccumulator delayedTasks; |
---|
| 157 | protected GSSAccumulator failedRequests; |
---|
| 158 | protected GSSAccumulator makespan; |
---|
| 159 | */ |
---|
| 160 | protected GSSAccumulatorsStats accStats; |
---|
| 161 | |
---|
| 162 | protected Map<String, GSSAccumulator> statsData; |
---|
| 163 | |
---|
| 164 | protected int numOfdelayedTasks = 0; |
---|
| 165 | protected int numOfNotExecutedTasks = 0; |
---|
| 166 | protected double maxCj = 0; |
---|
| 167 | |
---|
| 168 | protected boolean allTasksFinished; |
---|
| 169 | |
---|
| 170 | protected boolean generateDiagrams = true; |
---|
| 171 | |
---|
| 172 | protected List<XYDataset> ganttDiagramResources; |
---|
| 173 | protected Timetable ganttDiagramProcessorsTimetable; |
---|
| 174 | protected TaskSeriesCollection ganttDiagramTaskSeriesCollection; |
---|
| 175 | protected TaskSeriesCollection ganttDiagramWaitingTimeSeriesCollection; |
---|
| 176 | protected TaskSeriesCollection ganttDiagramReservationSeriesCollection; |
---|
| 177 | protected List<XYDataset> ganttDiagramResourcesEnergy; |
---|
| 178 | |
---|
| 179 | protected Map<String, TimetableEventSource> processorsGanttMap; |
---|
| 180 | protected Map<String, TimetableEventGroup> taskGanttMap; |
---|
| 181 | |
---|
| 182 | protected AbstractStringSerializer serializer; |
---|
| 183 | |
---|
| 184 | public GSSimStatistics(String simulationIdentifier, |
---|
| 185 | ConfigurationOptions co, GenericUser users, |
---|
| 186 | AbstractGridBroker brokerInterface, |
---|
| 187 | AbstractComputingResource gridResources[], Topology topology) { |
---|
| 188 | this.simulationIdentifier = simulationIdentifier; |
---|
| 189 | this.configuration = co; |
---|
| 190 | this.users = users; |
---|
| 191 | this.brokerInterface = brokerInterface; |
---|
| 192 | this.gridResources = gridResources; |
---|
| 193 | this.topology = topology; |
---|
| 194 | |
---|
| 195 | if (this.configuration.formatstatisticsoutput) |
---|
| 196 | this.serializer = new FormatedStringSerializer(); |
---|
| 197 | else |
---|
| 198 | this.serializer = new StringSerializer(); |
---|
| 199 | |
---|
| 200 | this.serializer.setFieldSeparator(TASK_SEPARATOR); |
---|
| 201 | |
---|
| 202 | init(); |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | public GSSimStatistics(String simulationIdentifier, |
---|
| 206 | ConfigurationOptions co, GenericUser users, |
---|
| 207 | AbstractGridBroker brokerInterface, |
---|
| 208 | AbstractComputingResource gridResources[], Topology topology, |
---|
| 209 | String outputFolderName) { |
---|
| 210 | this.simulationIdentifier = simulationIdentifier; |
---|
| 211 | this.configuration = co; |
---|
| 212 | this.users = users; |
---|
| 213 | this.brokerInterface = brokerInterface; |
---|
| 214 | this.gridResources = gridResources; |
---|
| 215 | this.topology = topology; |
---|
| 216 | this.outputFolderName = outputFolderName; |
---|
| 217 | |
---|
| 218 | if (this.configuration.formatstatisticsoutput) |
---|
| 219 | this.serializer = new FormatedStringSerializer(); |
---|
| 220 | else |
---|
| 221 | this.serializer = new StringSerializer(); |
---|
| 222 | |
---|
| 223 | this.serializer |
---|
| 224 | .setDefaultNumberFormat(GridSchedulingSimulator.DFAULT_NUMBER_FORMAT); |
---|
| 225 | |
---|
| 226 | init(); |
---|
| 227 | } |
---|
| 228 | |
---|
| 229 | public void generateStatistics() { |
---|
| 230 | |
---|
| 231 | this.startSimulationTime = DateTimeUtilsExt.getOffsetTime() |
---|
| 232 | .getTimeInMillis(); |
---|
| 233 | |
---|
| 234 | this.endSimulationTime = DateTimeUtilsExt.currentTimeMillis(); |
---|
| 235 | |
---|
| 236 | long s = 0; |
---|
| 237 | long e = 0; |
---|
| 238 | // prepareStatisticsDirectory(); |
---|
| 239 | log.info("gatherResourceStatistics"); |
---|
| 240 | s = System.currentTimeMillis(); |
---|
| 241 | gatherResourceStatistics(); |
---|
| 242 | e = System.currentTimeMillis(); |
---|
| 243 | log.info("time in sec: " + ((e - s) / 1000)); |
---|
| 244 | |
---|
| 245 | log.info("gatherNetworkStatistics"); |
---|
| 246 | s = System.currentTimeMillis(); |
---|
| 247 | gatherNetworkStatistics(); |
---|
| 248 | e = System.currentTimeMillis(); |
---|
| 249 | log.info("time in sec: " + ((e - s) / 1000)); |
---|
| 250 | |
---|
| 251 | log.info("gatherTaskStatistics"); |
---|
| 252 | s = System.currentTimeMillis(); |
---|
| 253 | gatherTaskStatistics(); |
---|
| 254 | e = System.currentTimeMillis(); |
---|
| 255 | log.info("time in sec: " + ((e - s) / 1000)); |
---|
| 256 | |
---|
| 257 | log.info("saveSimulationStatistics"); |
---|
| 258 | s = System.currentTimeMillis(); |
---|
| 259 | saveSimulationStatistics(); |
---|
| 260 | e = System.currentTimeMillis(); |
---|
| 261 | log.info("time in sec: " + ((e - s) / 1000)); |
---|
| 262 | } |
---|
| 263 | |
---|
| 264 | /* |
---|
| 265 | * public void prepareStatisticsDirectory(){ |
---|
| 266 | * |
---|
| 267 | * String dirName = null; if (configuration.createScenario) { dirName = |
---|
| 268 | * configuration.outputFolder + configuration.statsOutputSubfolderNameCreate |
---|
| 269 | * + File.separator; } else { if(configuration.inputFolder != null){ dirName |
---|
| 270 | * = configuration.inputFolder; }else if(configuration.inputWorkloadFileName |
---|
| 271 | * != null){ dirName = new |
---|
| 272 | * File(configuration.inputWorkloadFileName).getParent(); }else{ dirName = |
---|
| 273 | * System.getProperty("user.dir"); } dirName += "/" + |
---|
| 274 | * configuration.statsOutputSubfolderNameRerad + File.separator; } |
---|
| 275 | * outputFolderName = dirName; |
---|
| 276 | * |
---|
| 277 | * File folder = new File(dirName); File fileList[] = folder.listFiles(); |
---|
| 278 | * for(int i = 0; i < fileList.length; i++){ File tmpFile = fileList[i]; |
---|
| 279 | * String name = tmpFile.getName(); |
---|
| 280 | * if(name.startsWith(simulationIdentifier)) tmpFile.delete(); |
---|
| 281 | * if(name.length() > 4){ String subName = name.substring(0, 5); |
---|
| 282 | * if(subName.compareTo("Gantt") == 0 || subName.compareTo("Stats") == 0){ |
---|
| 283 | * tmpFile.delete(); } } } } |
---|
| 284 | */ |
---|
| 285 | |
---|
| 286 | public String getOutputFolderName() { |
---|
| 287 | return outputFolderName; |
---|
| 288 | } |
---|
| 289 | |
---|
| 290 | private void init() { |
---|
| 291 | |
---|
| 292 | reservations = new ArrayList<Reservation>(); |
---|
| 293 | reservationsMap = new HashMap<String, Reservation>(); |
---|
| 294 | // task_processorMap = new HashMap<String, String>(); |
---|
| 295 | task_processorsMap = new HashMap<String, List<String>>(); |
---|
| 296 | receivedNetData = new ArrayList<NetworkData>(); |
---|
| 297 | /* meanTotalLoad = new GSSAccumulator(); |
---|
| 298 | meanReservationLoad = new GSSAccumulator(); |
---|
| 299 | meanQueueLength = new GSSAccumulator(); |
---|
| 300 | meanEnergyUsage = new GSSAccumulator(); |
---|
| 301 | |
---|
| 302 | meanTaskStartTime = new GSSAccumulator(); |
---|
| 303 | meanTaskCompletionTime = new GSSAccumulator(); |
---|
| 304 | meanTaskExecutionTime = new GSSAccumulator(); |
---|
| 305 | meanTaskWaitingTime = new GSSAccumulator(); |
---|
| 306 | meanTaskFlowTime = new GSSAccumulator(); |
---|
| 307 | lateness = new GSSAccumulator(); |
---|
| 308 | tardiness = new GSSAccumulator(); |
---|
| 309 | delayedTasks = new GSSAccumulator(); |
---|
| 310 | failedRequests = new GSSAccumulator(); |
---|
| 311 | makespan = new GSSAccumulator(); |
---|
| 312 | */ |
---|
| 313 | accStats = new GSSAccumulatorsStats(); |
---|
| 314 | statsData = new HashMap<String, GSSAccumulator>(); |
---|
| 315 | |
---|
| 316 | processorsGanttMap = new HashMap<String, TimetableEventSource>(); |
---|
| 317 | taskGanttMap = new HashMap<String, TimetableEventGroup>(); |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | public void saveSimulationStatistics() { |
---|
| 321 | PrintStream simulationStatsFile = null; |
---|
| 322 | if (configuration.createsimulationstatistics) { |
---|
| 323 | try { |
---|
| 324 | File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX |
---|
| 325 | + simulationIdentifier + "_" |
---|
| 326 | + SIMULATION_STATISTICS_OUTPUT_FILE_NAME); |
---|
| 327 | simulationStatsFile = new PrintStream( |
---|
| 328 | new FileOutputStream(file)); |
---|
| 329 | } catch (IOException e) { |
---|
| 330 | e.printStackTrace(); |
---|
| 331 | } |
---|
| 332 | } |
---|
| 333 | if (simulationStatsFile != null) { |
---|
| 334 | |
---|
| 335 | Object txt = accStats.serialize(this.serializer); |
---|
| 336 | simulationStatsFile.println(txt); |
---|
| 337 | |
---|
| 338 | } |
---|
| 339 | |
---|
| 340 | if (simulationStatsFile != null) { |
---|
| 341 | simulationStatsFile.close(); |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | } |
---|
| 345 | |
---|
| 346 | |
---|
| 347 | /************* RESOURCE STATISTICS SECTION **************/ |
---|
| 348 | public void gatherResourceStatistics() { |
---|
| 349 | |
---|
| 350 | PrintStream resourceStatsFile = null; |
---|
| 351 | try { |
---|
| 352 | File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX |
---|
| 353 | + simulationIdentifier + "_" |
---|
| 354 | + RAW_RESOURCE_STATISTICS_OUTPUT_FILE_NAME); |
---|
| 355 | resourceStatsFile = new PrintStream(new FileOutputStream(file)); |
---|
| 356 | } catch (IOException e) { |
---|
| 357 | resourceStatsFile = null; |
---|
| 358 | } |
---|
| 359 | PrintStream resourceLoadStatsFile = null; |
---|
| 360 | try { |
---|
| 361 | File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX |
---|
| 362 | + simulationIdentifier + "_" |
---|
| 363 | + RESOURCE_LOAD_STATISTICS_OUTPUT_FILE_NAME); |
---|
| 364 | resourceLoadStatsFile = new PrintStream(new FileOutputStream(file)); |
---|
| 365 | } catch (IOException e) { |
---|
| 366 | resourceLoadStatsFile = null; |
---|
| 367 | } |
---|
| 368 | PrintStream energyStatsFile = null; |
---|
| 369 | try { |
---|
| 370 | File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX |
---|
| 371 | + simulationIdentifier + "_" |
---|
| 372 | + ENERGYUSAGE_STATISTICS_OUTPUT_FILE_NAME); |
---|
| 373 | energyStatsFile = new PrintStream(new FileOutputStream(file)); |
---|
| 374 | } catch (IOException e) { |
---|
| 375 | energyStatsFile = null; |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | PrintStream resourceAccumulatedStatsFile = null; |
---|
| 379 | if (configuration.createaccumulatedresourcesstatistics) { |
---|
| 380 | try { |
---|
| 381 | File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX |
---|
| 382 | + simulationIdentifier + "_" |
---|
| 383 | + ACCUMULATED_RESOURCES_STATISTICS_OUTPUT_FILE_NAME); |
---|
| 384 | resourceAccumulatedStatsFile = new PrintStream( |
---|
| 385 | new FileOutputStream(file)); |
---|
| 386 | |
---|
| 387 | } catch (IOException e) { |
---|
| 388 | resourceAccumulatedStatsFile = null; |
---|
| 389 | } |
---|
| 390 | } |
---|
| 391 | ganttDiagramResources = new ArrayList<XYDataset>(); |
---|
| 392 | ganttDiagramProcessorsTimetable = new Timetable(new FixedMillisecond( |
---|
| 393 | startSimulationTime), new FixedMillisecond(endSimulationTime)); |
---|
| 394 | ganttDiagramResourcesEnergy = new ArrayList<XYDataset>(); |
---|
| 395 | |
---|
| 396 | for (int i = 0; i < gridResources.length; i++) { |
---|
| 397 | |
---|
| 398 | ResourceStats resourceStats = new ResourceStats(gridResources[i]); |
---|
| 399 | |
---|
| 400 | gatherResourceCharacteristic(resourceStats, gridResources[i]); |
---|
| 401 | |
---|
| 402 | gatherResourceQueueStats(resourceStats, gridResources[i]); |
---|
| 403 | |
---|
| 404 | ResourceUsageStats resourceUsage = gatherResourceLoadStats(resourceStats, gridResources[i]); |
---|
| 405 | |
---|
| 406 | ResourceUsageStats energyUsage = gatherResourceEnergyStats(resourceStats, gridResources[i]); |
---|
| 407 | |
---|
| 408 | if (configuration.creatediagrams_resources) { |
---|
| 409 | // createResourceGanttDiagram(gridResources[i]); |
---|
| 410 | createResourceGanttDiagram(resourceUsage); |
---|
| 411 | } |
---|
| 412 | if (configuration.creatediagrams_processors) { |
---|
| 413 | prepareProcessorsGanttData(gridResources[i]); |
---|
| 414 | } |
---|
| 415 | if (configuration.creatediagrams_energyusage) { |
---|
| 416 | createResourceEnergyGanttDiagram(energyUsage); |
---|
| 417 | } |
---|
| 418 | |
---|
| 419 | AbstractAllocationPolicy ap = gridResources[i] |
---|
| 420 | .getAllocationPolicy(); |
---|
| 421 | for (Integer gridletID : ap.getAllocationHistory().keySet()) { |
---|
| 422 | |
---|
| 423 | Map<String, Object> historyItem = (Map<String, Object>) ap |
---|
| 424 | .getAllocationHistory().get(gridletID); |
---|
| 425 | List<ResourceHistoryItem> resHistItemList = (List<ResourceHistoryItem>) historyItem |
---|
| 426 | .get(GssimConstants.RESOURCES); |
---|
| 427 | Map<ResourceParameterName, ResourceUnit> res = resHistItemList.get(resHistItemList.size() - 1).getResourceUnits(); |
---|
| 428 | |
---|
| 429 | ResourceUnit unit = res.get(ResourceParameterName.CPUCOUNT); |
---|
| 430 | if (unit instanceof ResourceProcessors) { |
---|
| 431 | ResourceProcessors processors = (ResourceProcessors) unit; |
---|
| 432 | |
---|
| 433 | for (int proc = 0; proc < processors.getAmount(); proc++) { |
---|
| 434 | String processorName = proc |
---|
| 435 | + "@" |
---|
| 436 | + gridResources[i].getResourceCharacteristics() |
---|
| 437 | .getResourceName(); |
---|
| 438 | if (processors.get(proc).getStatus() == Processor.Status.FREE) |
---|
| 439 | continue; |
---|
| 440 | SubmittedTask st = ap.getSubmittedTask(gridletID); |
---|
| 441 | gatherProcessorsLoadStats(resourceStats, processorName, |
---|
| 442 | historyItem); |
---|
| 443 | gatherProcessorsReservationLoadStats(resourceStats, |
---|
| 444 | gridResources[i], processorName, st.getJobId(), |
---|
| 445 | st.getId()); |
---|
| 446 | String uniqueTaskID = st.getJobId() + "_" + st.getId(); |
---|
| 447 | // task_processorMap.put(uniqueTaskID, processorName); |
---|
| 448 | List<String> procNames = task_processorsMap |
---|
| 449 | .get(uniqueTaskID); |
---|
| 450 | if (procNames == null) { |
---|
| 451 | procNames = new ArrayList<String>(); |
---|
| 452 | procNames.add(processorName); |
---|
| 453 | task_processorsMap.put(uniqueTaskID, procNames); |
---|
| 454 | } else { |
---|
| 455 | procNames.add(processorName); |
---|
| 456 | // task_processorsMap.put(uniqueTaskID, procNames); |
---|
| 457 | } |
---|
| 458 | if (configuration.creatediagrams_processors) { |
---|
| 459 | createProcessorsGanttDiagram(processorName, |
---|
| 460 | uniqueTaskID, historyItem); |
---|
| 461 | } |
---|
| 462 | } |
---|
| 463 | } |
---|
| 464 | } |
---|
| 465 | |
---|
| 466 | collectReservations(gridResources[i]); |
---|
| 467 | collectReservationsAsMap(gridResources[i]); |
---|
| 468 | collectReceivedNetworkData(gridResources[i]); |
---|
| 469 | |
---|
| 470 | this.serializer.setFieldSeparator(RESOURCE_SEPARATOR); |
---|
| 471 | if (resourceStatsFile != null) { |
---|
| 472 | Object txt = resourceStats.serialize(this.serializer); |
---|
| 473 | resourceStatsFile.println(txt); |
---|
| 474 | } |
---|
| 475 | |
---|
| 476 | if (configuration.createaccumulatedresourcesstatistics) { |
---|
| 477 | AccumulatedResourceStats accResStats = createAccumulatedResourceStatistic(resourceStats); |
---|
| 478 | if (resourceAccumulatedStatsFile != null) { |
---|
| 479 | Object txt = accResStats.serialize(this.serializer); |
---|
| 480 | resourceAccumulatedStatsFile.println(txt); |
---|
| 481 | } |
---|
| 482 | } |
---|
| 483 | |
---|
| 484 | if (resourceLoadStatsFile != null) { |
---|
| 485 | Object txt = resourceUsage.serialize(this.serializer); |
---|
| 486 | resourceLoadStatsFile.println(txt); |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | if (energyStatsFile != null) { |
---|
| 490 | Object txt = energyUsage.serialize(this.serializer); |
---|
| 491 | energyStatsFile.println(txt); |
---|
| 492 | } |
---|
| 493 | |
---|
| 494 | if (configuration.createsimulationstatistics) { |
---|
| 495 | createAccumulatedResourceSimulationStatistic(resourceStats, energyUsage); |
---|
| 496 | } |
---|
| 497 | } |
---|
| 498 | saveResourceGanttDiagrams(); |
---|
| 499 | if (resourceStatsFile != null) { |
---|
| 500 | resourceStatsFile.close(); |
---|
| 501 | } |
---|
| 502 | if (resourceAccumulatedStatsFile != null) { |
---|
| 503 | resourceAccumulatedStatsFile.close(); |
---|
| 504 | } |
---|
| 505 | if (energyStatsFile != null) { |
---|
| 506 | energyStatsFile.close(); |
---|
| 507 | } |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | private void gatherResourceCharacteristic(ResourceStats resourceStats, |
---|
| 511 | AbstractComputingResource gridResource) { |
---|
| 512 | |
---|
| 513 | ResourceUnitsManagerImpl rum = (ResourceUnitsManagerImpl) gridResource |
---|
| 514 | .getResourceCharacteristics(); |
---|
| 515 | Map<ResourceParameterName, ResourceUnit> resources = rum |
---|
| 516 | .getResourceParameters(); |
---|
| 517 | |
---|
| 518 | // resourceStats.resourceName = |
---|
| 519 | // gridResource.getResourceCharacteristics().getResourceName(); |
---|
| 520 | ResourceUnit unit = resources.get(ResourceParameterName.MEMORY); |
---|
| 521 | resourceStats.memory = (unit == null ? 0 : unit.getAmount()); |
---|
| 522 | resourceStats.cpucnt = rum.getNumPE(); |
---|
| 523 | |
---|
| 524 | unit = resources.get(ResourceParameterName.CPUCOUNT); |
---|
| 525 | if (unit instanceof Processors) { |
---|
| 526 | Processors peUnit = (Processors) unit; |
---|
| 527 | resourceStats.cpuspeed = peUnit.getProcessorSpeed(); |
---|
| 528 | } |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | private void gatherResourceQueueStats(ResourceStats resourceStats, |
---|
| 532 | AbstractComputingResource gridResource) { |
---|
| 533 | |
---|
| 534 | Sim_stat stats = gridResource.getAllocationPolicy().get_stat(); |
---|
| 535 | List<Object[]> measures = stats.get_measures(); |
---|
| 536 | for (Object[] info : measures) { |
---|
| 537 | String measure = (String) info[0]; |
---|
| 538 | if (measure |
---|
| 539 | .startsWith(GssimConstants.TASKS_QUEUE_LENGTH_MEASURE_NAME)) { |
---|
| 540 | resourceStats.setQueueLength(stats.average(measure)); |
---|
| 541 | } |
---|
| 542 | } |
---|
| 543 | } |
---|
| 544 | |
---|
| 545 | private ResourceUsageStats gatherResourceLoadStats(ResourceStats resourceStats, |
---|
| 546 | AbstractComputingResource gridResource) { |
---|
| 547 | |
---|
| 548 | ResourceUsageStats usageStats = new ResourceUsageStats(resourceStats.getResourceName(), "resourceLoadStats"); |
---|
| 549 | |
---|
| 550 | // int nCPU = gridResource.getResourceCharacteristics().getNumPE(); |
---|
| 551 | AbstractAllocationPolicy ap = gridResource.getAllocationPolicy(); |
---|
| 552 | |
---|
| 553 | TreeMap<Long, Integer> resourceLoadData = createResourceLoadData( |
---|
| 554 | usageStats, ap.getAllocationHistory()); |
---|
| 555 | if (!resourceLoadData.containsKey(startSimulationTime)) |
---|
| 556 | resourceLoadData.put(startSimulationTime, 0); |
---|
| 557 | // ganttdata.put(endSimulationTime, nCPU); |
---|
| 558 | |
---|
| 559 | return usageStats; |
---|
| 560 | } |
---|
| 561 | |
---|
| 562 | private TreeMap<Long, Integer> createResourceLoadData(ResourceUsageStats usageStats, |
---|
| 563 | Map<Integer, Map<String, Object>> history) { |
---|
| 564 | |
---|
| 565 | TreeMap<Long, Integer> ganttData = (TreeMap) usageStats.getUsage(); |
---|
| 566 | for (Map<String, Object> historyItem : history.values()) { |
---|
| 567 | |
---|
| 568 | List<ResourceHistoryItem> resHistItemList = (List<ResourceHistoryItem>) historyItem |
---|
| 569 | .get(GssimConstants.RESOURCES); |
---|
| 570 | Map<ResourceParameterName, ResourceUnit> res = resHistItemList.get(resHistItemList.size() - 1).getResourceUnits(); |
---|
| 571 | |
---|
| 572 | ResourceUnit unit = res.get(ResourceParameterName.CPUCOUNT); |
---|
| 573 | int nCPU = Float.valueOf(unit.getUsedAmount()).intValue(); |
---|
| 574 | long start_time = ((DateTime) historyItem |
---|
| 575 | .get(GssimConstants.START_TIME)).getMillis(); |
---|
| 576 | long end_time = ((DateTime) historyItem |
---|
| 577 | .get(GssimConstants.END_TIME)).getMillis(); |
---|
| 578 | if (end_time > start_time) { |
---|
| 579 | Integer end = ganttData.get(end_time); |
---|
| 580 | if (end == null) { |
---|
| 581 | ganttData.put(end_time, 0); |
---|
| 582 | Long left = getLeftKey(ganttData, end_time); |
---|
| 583 | if (left != null) { |
---|
| 584 | Integer leftValue = ganttData.get(left); |
---|
| 585 | ganttData.put(end_time, leftValue); |
---|
| 586 | } |
---|
| 587 | } |
---|
| 588 | |
---|
| 589 | Integer start = ganttData.get(start_time); |
---|
| 590 | if (start == null) { |
---|
| 591 | ganttData.put(start_time, 0); |
---|
| 592 | Long left = getLeftKey(ganttData, start_time); |
---|
| 593 | if (left != null) { |
---|
| 594 | Integer leftValue = ganttData.get(left); |
---|
| 595 | ganttData.put(start_time, leftValue); |
---|
| 596 | } |
---|
| 597 | } |
---|
| 598 | |
---|
| 599 | SortedMap<Long, Integer> sm = ganttData.subMap(start_time, |
---|
| 600 | end_time); |
---|
| 601 | for (Long key : sm.keySet()) { |
---|
| 602 | Integer keyVal = ganttData.get(key); |
---|
| 603 | ganttData.put(key, keyVal + nCPU); |
---|
| 604 | } |
---|
| 605 | } |
---|
| 606 | } |
---|
| 607 | return ganttData; |
---|
| 608 | } |
---|
| 609 | |
---|
| 610 | private Long getLeftKey(TreeMap<Long, Integer> ganttData, Long toKey) { |
---|
| 611 | |
---|
| 612 | SortedMap<Long, Integer> sm = ganttData.headMap(toKey); |
---|
| 613 | if (sm.isEmpty()) { |
---|
| 614 | return null; |
---|
| 615 | } |
---|
| 616 | return sm.lastKey(); |
---|
| 617 | } |
---|
| 618 | |
---|
| 619 | private ResourceUsageStats gatherResourceEnergyStats(ResourceStats resourceStats, |
---|
| 620 | AbstractComputingResource gridResource) { |
---|
| 621 | |
---|
| 622 | ResourceUsageStats resEnergyUsage = new ResourceUsageStats(resourceStats.getResourceName(), "resourceEnergyStats"); |
---|
| 623 | Map<Long, Integer> usage = resEnergyUsage.getUsage(); |
---|
| 624 | |
---|
| 625 | AbstractAllocationPolicy ap = gridResource.getAllocationPolicy(); |
---|
| 626 | for (Object o : ap.getPowerUsage()) { |
---|
| 627 | PowerUsage energyUsage = (PowerUsage) o; |
---|
| 628 | usage.put(energyUsage.getTimestamp(), |
---|
| 629 | energyUsage.getValue()); |
---|
| 630 | } |
---|
| 631 | |
---|
| 632 | return resEnergyUsage; |
---|
| 633 | } |
---|
| 634 | |
---|
| 635 | private void gatherProcessorsLoadStats(ResourceStats resourceStats, |
---|
| 636 | String processorName, Map<String, Object> historyItem) { |
---|
| 637 | |
---|
| 638 | Map<String, Double> processorsLoad = resourceStats.getProcessorsLoad(); |
---|
| 639 | Double load = processorsLoad.get(processorName); |
---|
| 640 | long startDate = ((DateTime) historyItem.get(GssimConstants.START_TIME)) |
---|
| 641 | .getMillis(); |
---|
| 642 | long endDate = ((DateTime) historyItem.get(GssimConstants.END_TIME)) |
---|
| 643 | .getMillis(); |
---|
| 644 | double newLoad = ((double) (endDate - startDate) / (double) (endSimulationTime - startSimulationTime)); |
---|
| 645 | load += newLoad; |
---|
| 646 | processorsLoad.put(processorName, load); |
---|
| 647 | |
---|
| 648 | } |
---|
| 649 | |
---|
| 650 | private void gatherProcessorsReservationLoadStats( |
---|
| 651 | ResourceStats resourceStats, |
---|
| 652 | AbstractComputingResource gridResource, String processorName, |
---|
| 653 | String jobID, String taskID) { |
---|
| 654 | Map<String, Double> reservationLoad = resourceStats |
---|
| 655 | .getProcessorsReservationLoad(); |
---|
| 656 | AbstractAllocationPolicy ap = gridResource.getAllocationPolicy(); |
---|
| 657 | if (ap instanceof ARAllocationPolicy) { |
---|
| 658 | ARAllocationPolicy arap = (ARAllocationPolicy) ap; |
---|
| 659 | for (Reservation reservation : arap.getReservations()) { |
---|
| 660 | if (reservation.getStatus() != Reservation.Status.CANCELED |
---|
| 661 | && reservation.getJobId().equals(jobID) |
---|
| 662 | && reservation.getTaskId().equals(taskID)) { |
---|
| 663 | TimeResourceAllocation tra = reservation; |
---|
| 664 | Double load = reservationLoad.get(processorName); |
---|
| 665 | double newLoad = ((double) (tra.getEndMillis() - tra |
---|
| 666 | .getStartMillis()) / (double) (endSimulationTime - startSimulationTime)); |
---|
| 667 | load += newLoad; |
---|
| 668 | reservationLoad.put(processorName, load); |
---|
| 669 | } |
---|
| 670 | } |
---|
| 671 | } |
---|
| 672 | } |
---|
| 673 | |
---|
| 674 | private void collectReservations(AbstractComputingResource gridResource) { |
---|
| 675 | |
---|
| 676 | AbstractAllocationPolicy ap = gridResource.getAllocationPolicy(); |
---|
| 677 | |
---|
| 678 | if (ap instanceof ARAllocationPolicy) { |
---|
| 679 | ARAllocationPolicy arap = (ARAllocationPolicy) ap; |
---|
| 680 | reservations.addAll(arap.getReservations()); |
---|
| 681 | } |
---|
| 682 | } |
---|
| 683 | |
---|
| 684 | private void collectReceivedNetworkData( |
---|
| 685 | AbstractComputingResource gridResource) { |
---|
| 686 | |
---|
| 687 | receivedNetData.addAll(gridResource.getReceivedNetData()); |
---|
| 688 | } |
---|
| 689 | |
---|
| 690 | private void collectReservationsAsMap(AbstractComputingResource gridResource) { |
---|
| 691 | |
---|
| 692 | AbstractAllocationPolicy ap = gridResource.getAllocationPolicy(); |
---|
| 693 | |
---|
| 694 | if (ap instanceof ARAllocationPolicy) { |
---|
| 695 | ARAllocationPolicy arap = (ARAllocationPolicy) ap; |
---|
| 696 | for (Reservation reservation : arap.getReservations()) { |
---|
| 697 | reservationsMap.put((reservation.getJobId() + "_" + reservation |
---|
| 698 | .getTaskId()), reservation); |
---|
| 699 | } |
---|
| 700 | } |
---|
| 701 | } |
---|
| 702 | |
---|
| 703 | private AccumulatedResourceStats createAccumulatedResourceStatistic(ResourceStats resourceStats) { |
---|
| 704 | |
---|
| 705 | AccumulatedResourceStats accResStats = new AccumulatedResourceStats(resourceStats.getResourceName()); |
---|
| 706 | |
---|
| 707 | for (String key : resourceStats.processorsLoad.keySet()) { |
---|
| 708 | double load = (double) resourceStats.processorsLoad.get(key); |
---|
| 709 | accResStats.addResourceLoad(load); |
---|
| 710 | } |
---|
| 711 | for (String key : resourceStats.processorsReservationLoad.keySet()) { |
---|
| 712 | double load = (double) resourceStats.processorsReservationLoad |
---|
| 713 | .get(key); |
---|
| 714 | accResStats.addReservationLoad(load); |
---|
| 715 | } |
---|
| 716 | |
---|
| 717 | return accResStats; |
---|
| 718 | } |
---|
| 719 | |
---|
| 720 | private void createAccumulatedResourceSimulationStatistic( |
---|
| 721 | ResourceStats resourceStats, ResourceUsageStats energyUsage) { |
---|
| 722 | |
---|
| 723 | accStats.meanQueueLength.add(resourceStats.getQueueLength()); |
---|
| 724 | |
---|
| 725 | GSSAccumulator tempMeanLoad = new GSSAccumulator(); |
---|
| 726 | for (String key : resourceStats.getProcessorsLoad().keySet()) { |
---|
| 727 | double load = (double) resourceStats.getProcessorsLoad().get(key); |
---|
| 728 | tempMeanLoad.add(load); |
---|
| 729 | } |
---|
| 730 | |
---|
| 731 | GSSAccumulator tempReservationLoad = new GSSAccumulator(); |
---|
| 732 | for (String key : resourceStats.getProcessorsReservationLoad().keySet()) { |
---|
| 733 | double load = (double) resourceStats.getProcessorsReservationLoad() |
---|
| 734 | .get(key); |
---|
| 735 | tempReservationLoad.add(load); |
---|
| 736 | } |
---|
| 737 | long time = 0; |
---|
| 738 | double tempLoad = 0; |
---|
| 739 | GSSAccumulator tempMeanEnergyUsage = new GSSAccumulator(); |
---|
| 740 | Map<Long, Integer> usage = energyUsage.getUsage(); |
---|
| 741 | for (Long key : usage.keySet()) { |
---|
| 742 | double load = (double) usage.get(key); |
---|
| 743 | if (time != 0) { |
---|
| 744 | tempLoad += (load * (key - time)) |
---|
| 745 | / (endSimulationTime - startSimulationTime); |
---|
| 746 | time = key; |
---|
| 747 | } else { |
---|
| 748 | time = key; |
---|
| 749 | } |
---|
| 750 | |
---|
| 751 | } |
---|
| 752 | tempMeanEnergyUsage.add(tempLoad); |
---|
| 753 | for (int cpu = 0; cpu < resourceStats.cpucnt; cpu++) { |
---|
| 754 | accStats.meanTotalLoad.add(tempMeanLoad.getMean()); |
---|
| 755 | accStats.meanReservationLoad.add(tempReservationLoad.getMean()); |
---|
| 756 | accStats.meanEnergyUsage.add(tempMeanEnergyUsage.getMean()); |
---|
| 757 | } |
---|
| 758 | } |
---|
| 759 | |
---|
| 760 | /* |
---|
| 761 | * private void createResourceGanttDiagram( AbstractComputingResource |
---|
| 762 | * gridResource) { |
---|
| 763 | * |
---|
| 764 | * String resourceName = gridResource.getResourceCharacteristics() |
---|
| 765 | * .getResourceName(); int numPE = |
---|
| 766 | * gridResource.getResourceCharacteristics().getNumPE(); |
---|
| 767 | * AbstractAllocationPolicy ap = gridResource.getAllocationPolicy(); |
---|
| 768 | * |
---|
| 769 | * XYDataset dataset = createResourceGanttDataSet(resourceName, numPE, ap |
---|
| 770 | * .getAllocationHistory(), startSimulationTime, endSimulationTime); |
---|
| 771 | * ganttDiagramResources.add(dataset); |
---|
| 772 | * |
---|
| 773 | * } |
---|
| 774 | * |
---|
| 775 | * private XYDataset createResourceGanttDataSet(String resourceName, int |
---|
| 776 | * nCPU, Map<Integer, Map<String, Object>> history, long start, long end) { |
---|
| 777 | * |
---|
| 778 | * TreeMap<Long, Integer> ganttdata = createResourceGanttData(history); |
---|
| 779 | * XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries data = |
---|
| 780 | * new XYSeries(resourceName, false, true); data.add(start, 0); for (Long |
---|
| 781 | * key : ganttdata.keySet()) { Integer val = ganttdata.get(key); |
---|
| 782 | * data.add(key, val); } data.add(end, nCPU); dataset.addSeries(data); |
---|
| 783 | * return dataset; } |
---|
| 784 | */ |
---|
| 785 | |
---|
| 786 | private void createResourceGanttDiagram(ResourceUsageStats resStats) { |
---|
| 787 | |
---|
| 788 | XYDataset dataset = createResourceGanttDataSet(resStats); |
---|
| 789 | ganttDiagramResources.add(dataset); |
---|
| 790 | |
---|
| 791 | } |
---|
| 792 | |
---|
| 793 | private XYDataset createResourceGanttDataSet(ResourceUsageStats resStats) { |
---|
| 794 | |
---|
| 795 | XYSeriesCollection dataset = new XYSeriesCollection(); |
---|
| 796 | XYSeries data = new XYSeries(resStats.resourceName, false, true); |
---|
| 797 | Map<Long, Integer> usage = resStats.getUsage(); |
---|
| 798 | |
---|
| 799 | for (Long key : usage.keySet()) { |
---|
| 800 | Integer val = usage.get(key); |
---|
| 801 | data.add(key, val); |
---|
| 802 | } |
---|
| 803 | dataset.addSeries(data); |
---|
| 804 | return dataset; |
---|
| 805 | } |
---|
| 806 | |
---|
| 807 | private void prepareProcessorsGanttData( |
---|
| 808 | AbstractComputingResource gridResource) { |
---|
| 809 | |
---|
| 810 | String resourceName = gridResource.getResourceCharacteristics() |
---|
| 811 | .getResourceName(); |
---|
| 812 | int numPE = gridResource.getResourceCharacteristics().getNumPE(); |
---|
| 813 | |
---|
| 814 | for (int cpu = 0; cpu < numPE; cpu++) { |
---|
| 815 | String processorName = cpu + "@" + resourceName; |
---|
| 816 | |
---|
| 817 | TimetableEventSource proc = new TimetableEventSource(processorName); |
---|
| 818 | ganttDiagramProcessorsTimetable.addEventSource(proc); |
---|
| 819 | |
---|
| 820 | processorsGanttMap.put(processorName, proc); |
---|
| 821 | } |
---|
| 822 | } |
---|
| 823 | |
---|
| 824 | private void createProcessorsGanttDiagram(String processorName, |
---|
| 825 | String uniqueTaskID, Map<String, Object> historyItem) { |
---|
| 826 | TimetableEventSource proc = processorsGanttMap.get(processorName); |
---|
| 827 | TimetableEventGroup task = taskGanttMap.get(uniqueTaskID); |
---|
| 828 | long startDate = ((DateTime) historyItem.get(GssimConstants.START_TIME)) |
---|
| 829 | .getMillis(); |
---|
| 830 | long endDate = ((DateTime) historyItem.get(GssimConstants.END_TIME)) |
---|
| 831 | .getMillis(); |
---|
| 832 | if (task == null) { |
---|
| 833 | task = new TimetableEventGroup(uniqueTaskID); |
---|
| 834 | taskGanttMap.put(uniqueTaskID, task); |
---|
| 835 | ganttDiagramProcessorsTimetable.addEventGroup(task); |
---|
| 836 | } |
---|
| 837 | ganttDiagramProcessorsTimetable.addEvent(proc, task, |
---|
| 838 | new FixedMillisecond(startDate), new FixedMillisecond(endDate)); |
---|
| 839 | } |
---|
| 840 | |
---|
| 841 | private void createResourceEnergyGanttDiagram(ResourceUsageStats energyUsage) { |
---|
| 842 | |
---|
| 843 | XYDataset dataset = createResourceEnergyGanttDataSet(energyUsage, |
---|
| 844 | startSimulationTime, endSimulationTime); |
---|
| 845 | ganttDiagramResourcesEnergy.add(dataset); |
---|
| 846 | |
---|
| 847 | } |
---|
| 848 | |
---|
| 849 | private XYDataset createResourceEnergyGanttDataSet( |
---|
| 850 | ResourceUsageStats energyUsage, long start, long end) { |
---|
| 851 | |
---|
| 852 | TreeMap<Long, Integer> ganttdata = createResourceEnergyGanttData(energyUsage); |
---|
| 853 | XYSeriesCollection dataset = new XYSeriesCollection(); |
---|
| 854 | XYSeries data = new XYSeries(energyUsage.getResourceName(), false, true); |
---|
| 855 | data.add(start, 0); |
---|
| 856 | for (Long key : ganttdata.keySet()) { |
---|
| 857 | Integer val = ganttdata.get(key); |
---|
| 858 | data.add(key, val); |
---|
| 859 | } |
---|
| 860 | data.add(end, 0); |
---|
| 861 | dataset.addSeries(data); |
---|
| 862 | return dataset; |
---|
| 863 | } |
---|
| 864 | |
---|
| 865 | private TreeMap<Long, Integer> createResourceEnergyGanttData( |
---|
| 866 | ResourceUsageStats energyUsage) { |
---|
| 867 | |
---|
| 868 | Map<Long, Integer> usage = energyUsage.getUsage(); |
---|
| 869 | TreeMap<Long, Integer> ganttData = new TreeMap<Long, Integer>(); |
---|
| 870 | for (Long euKey : usage.keySet()) { |
---|
| 871 | |
---|
| 872 | ganttData.put(euKey, usage.get(euKey)); |
---|
| 873 | } |
---|
| 874 | return ganttData; |
---|
| 875 | } |
---|
| 876 | |
---|
| 877 | private boolean saveResourceGanttDiagrams() { |
---|
| 878 | |
---|
| 879 | JFreeChart processorsDiagram = null; |
---|
| 880 | JFreeChart resourceDiagram = null; |
---|
| 881 | JFreeChart resourceEnergyDiagram = null; |
---|
| 882 | if (!generateDiagrams) |
---|
| 883 | return false; |
---|
| 884 | |
---|
| 885 | String fileName = new File(outputFolderName, DIAGRAMS_FILE_NAME_PREFIX |
---|
| 886 | + simulationIdentifier + "_").getAbsolutePath(); |
---|
| 887 | |
---|
| 888 | String chartName = "Gantt diagram for " |
---|
| 889 | + GridSchedulingSimulator.SIMULATOR_NAME; |
---|
| 890 | String simulationTime = "Simulation time"; |
---|
| 891 | Title subtitle = new TextTitle("created for \"" + simulationIdentifier |
---|
| 892 | + "\" at " + Calendar.getInstance().getTime().toString()); |
---|
| 893 | |
---|
| 894 | if (configuration.creatediagrams_processors) { |
---|
| 895 | processorsDiagram = getProcessorsDiagram(chartName, subtitle, |
---|
| 896 | simulationTime); |
---|
| 897 | if (!saveCategoryChart(processorsDiagram, fileName + "Processors", |
---|
| 898 | "{0}")) |
---|
| 899 | return false; |
---|
| 900 | } |
---|
| 901 | |
---|
| 902 | if (configuration.creatediagrams_resources) { |
---|
| 903 | resourceDiagram = getResourcesDiagram(chartName, subtitle, |
---|
| 904 | simulationTime); |
---|
| 905 | if (!saveXYPlotChart(resourceDiagram, fileName + "Resources")) |
---|
| 906 | return false; |
---|
| 907 | } |
---|
| 908 | |
---|
| 909 | if (configuration.creatediagrams_energyusage) { |
---|
| 910 | resourceEnergyDiagram = getResourcesEnergyDiagram(chartName, |
---|
| 911 | subtitle, simulationTime); |
---|
| 912 | if (!saveXYPlotChart(resourceEnergyDiagram, fileName + "Energy")) |
---|
| 913 | return false; |
---|
| 914 | } |
---|
| 915 | return true; |
---|
| 916 | } |
---|
| 917 | |
---|
| 918 | private JFreeChart getProcessorsDiagram(String chartName, Title subtitle, |
---|
| 919 | String simulationTime) { |
---|
| 920 | String processors = "Processors"; |
---|
| 921 | boolean tooltip = true; |
---|
| 922 | boolean legend = true; |
---|
| 923 | JFreeChart chart = TimetableChartFactory.createTimetableChart( |
---|
| 924 | chartName, processors, simulationTime, |
---|
| 925 | ganttDiagramProcessorsTimetable, legend, tooltip); |
---|
| 926 | chart.addSubtitle(subtitle); |
---|
| 927 | TimetableRenderer rend = (TimetableRenderer) chart.getCategoryPlot() |
---|
| 928 | .getRenderer(); |
---|
| 929 | rend.setBackgroundBarPaint(null); |
---|
| 930 | return chart; |
---|
| 931 | } |
---|
| 932 | |
---|
| 933 | private JFreeChart getResourcesDiagram(String chartName, Title subtitle, |
---|
| 934 | String simulationTime) { |
---|
| 935 | String cpu = "CPU"; |
---|
| 936 | boolean urls = false; |
---|
| 937 | boolean tooltip = true; |
---|
| 938 | boolean legend = true; |
---|
| 939 | CombinedDomainXYPlot cPlot = new CombinedDomainXYPlot(); |
---|
| 940 | DateAxis xAxis = new DateAxis(simulationTime); |
---|
| 941 | |
---|
| 942 | for (XYDataset dataset : ganttDiagramResources) { |
---|
| 943 | |
---|
| 944 | JFreeChart tChart = ChartFactory.createXYStepAreaChart("", "", |
---|
| 945 | null, dataset, PlotOrientation.VERTICAL, legend, tooltip, |
---|
| 946 | urls); |
---|
| 947 | |
---|
| 948 | XYPlot tPlot = tChart.getXYPlot(); |
---|
| 949 | NumberAxis yAxis = new NumberAxis(cpu); |
---|
| 950 | yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); |
---|
| 951 | tPlot.setRangeAxis(yAxis); |
---|
| 952 | XYStepAreaRenderer rend = (XYStepAreaRenderer) tPlot.getRenderer(); |
---|
| 953 | rend.setShapesVisible(false); |
---|
| 954 | cPlot.add(tPlot); |
---|
| 955 | } |
---|
| 956 | cPlot.setDomainAxis(xAxis); |
---|
| 957 | cPlot.setDomainAxisLocation(AxisLocation.TOP_OR_LEFT); |
---|
| 958 | JFreeChart chart = new JFreeChart(chartName, cPlot); |
---|
| 959 | chart.addSubtitle(subtitle); |
---|
| 960 | return chart; |
---|
| 961 | } |
---|
| 962 | |
---|
| 963 | private JFreeChart getResourcesEnergyDiagram(String chartName, |
---|
| 964 | Title subtitle, String simulationTime) { |
---|
| 965 | String energy = "ENERGY [W]"; |
---|
| 966 | boolean urls = false; |
---|
| 967 | boolean tooltip = true; |
---|
| 968 | boolean legend = true; |
---|
| 969 | CombinedDomainXYPlot cPlot = new CombinedDomainXYPlot(); |
---|
| 970 | DateAxis xAxis = new DateAxis(simulationTime); |
---|
| 971 | |
---|
| 972 | for (XYDataset dataset : ganttDiagramResourcesEnergy) { |
---|
| 973 | |
---|
| 974 | JFreeChart tChart = ChartFactory.createXYStepAreaChart("", "", |
---|
| 975 | null, dataset, PlotOrientation.VERTICAL, legend, tooltip, |
---|
| 976 | urls); |
---|
| 977 | |
---|
| 978 | XYPlot tPlot = tChart.getXYPlot(); |
---|
| 979 | NumberAxis yAxis = new NumberAxis(energy); |
---|
| 980 | yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); |
---|
| 981 | tPlot.setRangeAxis(yAxis); |
---|
| 982 | XYStepAreaRenderer rend = (XYStepAreaRenderer) tPlot.getRenderer(); |
---|
| 983 | rend.setShapesVisible(false); |
---|
| 984 | cPlot.add(tPlot); |
---|
| 985 | } |
---|
| 986 | cPlot.setDomainAxis(xAxis); |
---|
| 987 | cPlot.setDomainAxisLocation(AxisLocation.TOP_OR_LEFT); |
---|
| 988 | JFreeChart chart = new JFreeChart(chartName, cPlot); |
---|
| 989 | chart.addSubtitle(subtitle); |
---|
| 990 | return chart; |
---|
| 991 | } |
---|
| 992 | |
---|
| 993 | /************* TASK STATISTICS SECTION **************/ |
---|
| 994 | public void gatherTaskStatistics() { |
---|
| 995 | |
---|
| 996 | List<JobInterface<?>> jobs = users.getAllReceivedJobs(); |
---|
| 997 | Collections.sort(jobs, new JobIdComparator()); |
---|
| 998 | |
---|
| 999 | ganttDiagramTaskSeriesCollection = new TaskSeriesCollection(); |
---|
| 1000 | ganttDiagramWaitingTimeSeriesCollection = new TaskSeriesCollection(); |
---|
| 1001 | ganttDiagramReservationSeriesCollection = new TaskSeriesCollection(); |
---|
| 1002 | |
---|
| 1003 | PrintStream taskStatsFile = null; |
---|
| 1004 | try { |
---|
| 1005 | File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX |
---|
| 1006 | + simulationIdentifier + "_" |
---|
| 1007 | + RAW_TASKS_STATISTICS_OUTPUT_FILE_NAME); |
---|
| 1008 | taskStatsFile = new PrintStream(new FileOutputStream(file)); |
---|
| 1009 | } catch (IOException e) { |
---|
| 1010 | taskStatsFile = null; |
---|
| 1011 | } |
---|
| 1012 | |
---|
| 1013 | PrintStream jobStatsFile = null; |
---|
| 1014 | if (configuration.createjobsstatistics) { |
---|
| 1015 | try { |
---|
| 1016 | File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX |
---|
| 1017 | + simulationIdentifier + "_" |
---|
| 1018 | + JOBS_STATISTICS_OUTPUT_FILE_NAME); |
---|
| 1019 | jobStatsFile = new PrintStream(new FileOutputStream(file)); |
---|
| 1020 | } catch (IOException e) { |
---|
| 1021 | jobStatsFile = null; |
---|
| 1022 | } |
---|
| 1023 | } |
---|
| 1024 | |
---|
| 1025 | if (configuration.creatediagrams_reservations) |
---|
| 1026 | prepareTaskReservationDiagramData(); |
---|
| 1027 | |
---|
| 1028 | for (int i = 0; i < jobs.size(); i++) { |
---|
| 1029 | Job job = (Job) jobs.get(i); |
---|
| 1030 | |
---|
| 1031 | List<AbstractExecutable> execList = this.brokerInterface |
---|
| 1032 | .getExecutables().getJobExecutables(job.getId()); |
---|
| 1033 | List<TaskStats> taskStatsList = new ArrayList<TaskStats>(); |
---|
| 1034 | |
---|
| 1035 | this.serializer.setFieldSeparator(TASK_SEPARATOR); |
---|
| 1036 | |
---|
| 1037 | for (int j = 0; j < execList.size(); j++) { |
---|
| 1038 | |
---|
| 1039 | AbstractExecutable task = execList.get(j); |
---|
| 1040 | |
---|
| 1041 | TaskStats taskStats = createTaskStats(task); |
---|
| 1042 | if (taskStats != null && taskStatsFile != null) { |
---|
| 1043 | Object txt = taskStats.serialize(serializer); |
---|
| 1044 | taskStatsFile.println(txt); |
---|
| 1045 | } |
---|
| 1046 | if (taskStats != null && taskStats.getExecFinishDate() != -1) { |
---|
| 1047 | if (configuration.createsimulationstatistics) { |
---|
| 1048 | createAccumulatedTaskSimulationStatistic(taskStats); |
---|
| 1049 | } |
---|
| 1050 | allTasksFinished &= task.isFinished(); |
---|
| 1051 | if (generateDiagrams) { |
---|
| 1052 | if (configuration.creatediagrams_tasks) |
---|
| 1053 | createTaskDiagramData(task); |
---|
| 1054 | if (configuration.creatediagrams_taskswaitingtime) |
---|
| 1055 | createTaskWaitingTimeDiagramData(task); |
---|
| 1056 | if (configuration.creatediagrams_reservations) |
---|
| 1057 | createTaskReservationDiagramData(task); |
---|
| 1058 | } |
---|
| 1059 | taskStatsList.add(taskStats); |
---|
| 1060 | } |
---|
| 1061 | } |
---|
| 1062 | if (configuration.createjobsstatistics && taskStatsList.size() > 0) { |
---|
| 1063 | |
---|
| 1064 | this.serializer.setFieldSeparator(JOB_SEPARATOR); |
---|
| 1065 | |
---|
| 1066 | JobStats jobStats = createJobStats(taskStatsList); |
---|
| 1067 | if (jobStatsFile != null) { |
---|
| 1068 | Object txt = jobStats.serialize(serializer); |
---|
| 1069 | jobStatsFile.println(txt); |
---|
| 1070 | } |
---|
| 1071 | } |
---|
| 1072 | } |
---|
| 1073 | |
---|
| 1074 | if (configuration.createsimulationstatistics) { |
---|
| 1075 | accStats.makespan.add(maxCj); |
---|
| 1076 | accStats.delayedTasks.add(numOfdelayedTasks); |
---|
| 1077 | accStats.failedRequests.add(users.getAllSentTasks().size() |
---|
| 1078 | - users.getFinishedTasksCount()); |
---|
| 1079 | createStatsData(); |
---|
| 1080 | } |
---|
| 1081 | |
---|
| 1082 | saveTaskGanttDiagrams(); |
---|
| 1083 | saveGridletStatistics(); |
---|
| 1084 | |
---|
| 1085 | if (taskStatsFile != null) { |
---|
| 1086 | taskStatsFile.close(); |
---|
| 1087 | } |
---|
| 1088 | if (jobStatsFile != null) { |
---|
| 1089 | jobStatsFile.close(); |
---|
| 1090 | } |
---|
| 1091 | } |
---|
| 1092 | |
---|
| 1093 | private TaskStats createTaskStats(AbstractExecutable task) { |
---|
| 1094 | TaskStats taskStats = new TaskStats(task, startSimulationTime); |
---|
| 1095 | |
---|
| 1096 | String uniqueTaskID = taskStats.getJobID() + "_" |
---|
| 1097 | + taskStats.getTaskID(); |
---|
| 1098 | |
---|
| 1099 | if (reservationsMap.containsKey(uniqueTaskID)) { |
---|
| 1100 | taskStats.setReservationStartDate(((Reservation) reservationsMap |
---|
| 1101 | .get(uniqueTaskID)).getStartMillis() / 1000); |
---|
| 1102 | |
---|
| 1103 | taskStats.setReservationFinishDate(((Reservation) reservationsMap |
---|
| 1104 | .get(uniqueTaskID)).getEndMillis() / 1000); |
---|
| 1105 | } |
---|
| 1106 | |
---|
| 1107 | taskStats.setProcessorsName(task_processorsMap.get(uniqueTaskID)); |
---|
| 1108 | |
---|
| 1109 | return taskStats; |
---|
| 1110 | } |
---|
| 1111 | |
---|
| 1112 | /* |
---|
| 1113 | * private TaskStats createTaskStats(AbstractExecutable task) { |
---|
| 1114 | * |
---|
| 1115 | * TaskStats taskStats = new TaskStats(task.getJobId(), task.getId()); |
---|
| 1116 | * taskStats.userDN = task.getUserDn(); String resNames[] = |
---|
| 1117 | * task.getAllResourceName(); if (resNames == null) return null; for (int i |
---|
| 1118 | * = 0; i < resNames.length; i++) { taskStats.resName += resNames[i]; if |
---|
| 1119 | * (resNames.length > 1) taskStats.resName += " "; } taskStats.execStartDate |
---|
| 1120 | * = task.getExecStartTime(); taskStats.execFinishDate = |
---|
| 1121 | * task.getFinishTime(); taskStats.gB_SubDate = |
---|
| 1122 | * task.getSubmissionTimeToBroker().getMillis() / 1000; taskStats.lB_SubDate |
---|
| 1123 | * = task.getSubmissionTime(); |
---|
| 1124 | * |
---|
| 1125 | * try { taskStats.execEndDate = task.getExecutionEndTime().getMillis() / |
---|
| 1126 | * 1000; } catch (NoSuchFieldException e) { taskStats.execEndDate = |
---|
| 1127 | * task.getFinishTime(); } |
---|
| 1128 | * |
---|
| 1129 | * try { taskStats.cpuCnt = Double.valueOf(task.getCpuCntRequest()) |
---|
| 1130 | * .longValue(); } catch (NoSuchFieldException e) { } |
---|
| 1131 | * |
---|
| 1132 | * taskStats.completionTime = task.getFinishTime() - startSimulationTime / |
---|
| 1133 | * 1000; taskStats.executionTime = task.getFinishTime() - |
---|
| 1134 | * task.getExecStartTime(); taskStats.execStartTime = |
---|
| 1135 | * task.getExecStartTime() - startSimulationTime / 1000; |
---|
| 1136 | * |
---|
| 1137 | * try { taskStats.readyTime = task.getExecutionStartTime().getMillis() / |
---|
| 1138 | * 1000 - startSimulationTime / 1000; } catch (Exception ex) { |
---|
| 1139 | * taskStats.readyTime = task.getSubmissionTime() - startSimulationTime / |
---|
| 1140 | * 1000; } |
---|
| 1141 | * |
---|
| 1142 | * taskStats.startTime = task.getExecStartTime() - |
---|
| 1143 | * task.getSubmissionTimeToBroker().getMillis() / 1000; taskStats.flowTime = |
---|
| 1144 | * taskStats.completionTime - taskStats.readyTime; taskStats.waitingTime = |
---|
| 1145 | * task.getWaitingTime(); taskStats.gQ_WaitingTime = |
---|
| 1146 | * task.getSubmissionTime() - task.getSubmissionTimeToBroker().getMillis() / |
---|
| 1147 | * 1000; |
---|
| 1148 | * |
---|
| 1149 | * if (taskStats.execEndDate != -1) { taskStats.lateness = |
---|
| 1150 | * task.getFinishTime() - taskStats.execEndDate; } taskStats.tardiness = |
---|
| 1151 | * Math.max(taskStats.lateness, 0.0); String uniqueTaskID = taskStats.jobID |
---|
| 1152 | * + "_" + taskStats.taskID; |
---|
| 1153 | * |
---|
| 1154 | * if (reservationsMap.containsKey(uniqueTaskID)) { |
---|
| 1155 | * taskStats.reservationStartDate = ((Reservation) reservationsMap |
---|
| 1156 | * .get(uniqueTaskID)).getStartMillis() / 1000; |
---|
| 1157 | * taskStats.reservationFinishDate = ((Reservation) reservationsMap |
---|
| 1158 | * .get(uniqueTaskID)).getEndMillis() / 1000; } taskStats.processorsName = |
---|
| 1159 | * task_processorsMap.get(uniqueTaskID); return taskStats; } |
---|
| 1160 | */ |
---|
| 1161 | private JobStats createJobStats(List<TaskStats> tasksStats) { |
---|
| 1162 | |
---|
| 1163 | String jobID = ((TaskStats) tasksStats.get(0)).getJobID(); |
---|
| 1164 | JobStats jobStats = new JobStats(jobID); |
---|
| 1165 | double maxCj = 0; |
---|
| 1166 | |
---|
| 1167 | for (int i = 0; i < tasksStats.size(); i++) { |
---|
| 1168 | |
---|
| 1169 | TaskStats task = (TaskStats) tasksStats.get(i); |
---|
| 1170 | jobStats.meanTaskStartTime.add(task.getStartTime()); |
---|
| 1171 | jobStats.meanTaskCompletionTime.add(task.getCompletionTime()); |
---|
| 1172 | maxCj = Math.max(maxCj, task.getCompletionTime()); |
---|
| 1173 | jobStats.meanTaskExecutionTime.add(task.getExecutionTime()); |
---|
| 1174 | jobStats.meanTaskWaitingTime.add(task.getWaitingTime()); |
---|
| 1175 | jobStats.meanTaskFlowTime.add(task.getFlowTime()); |
---|
| 1176 | jobStats.meanTaskGQ_WaitingTime.add(task.getGQ_WaitingTime()); |
---|
| 1177 | jobStats.lateness.add(task.getLateness()); |
---|
| 1178 | jobStats.tardiness.add(task.getTardiness()); |
---|
| 1179 | } |
---|
| 1180 | jobStats.makespan.add(maxCj); |
---|
| 1181 | |
---|
| 1182 | return jobStats; |
---|
| 1183 | } |
---|
| 1184 | |
---|
| 1185 | private void createAccumulatedTaskSimulationStatistic(TaskStats taskStats) { |
---|
| 1186 | accStats.meanTaskFlowTime.add(taskStats.getFlowTime()); |
---|
| 1187 | accStats.meanTaskExecutionTime.add(taskStats.getExecutionTime()); |
---|
| 1188 | accStats.meanTaskCompletionTime.add(taskStats.getCompletionTime()); |
---|
| 1189 | accStats.meanTaskWaitingTime.add(taskStats.getWaitingTime()); |
---|
| 1190 | accStats.meanTaskStartTime.add(taskStats.getStartTime()); |
---|
| 1191 | |
---|
| 1192 | accStats.lateness.add(taskStats.getLateness()); |
---|
| 1193 | accStats.tardiness.add(taskStats.getTardiness()); |
---|
| 1194 | |
---|
| 1195 | if (taskStats.getExecFinishDate() == -1) { |
---|
| 1196 | numOfNotExecutedTasks++; |
---|
| 1197 | } |
---|
| 1198 | if (taskStats.getTardiness() > 0.0) { |
---|
| 1199 | numOfdelayedTasks++; |
---|
| 1200 | } |
---|
| 1201 | |
---|
| 1202 | maxCj = Math.max(maxCj, taskStats.getCompletionTime()); |
---|
| 1203 | } |
---|
| 1204 | |
---|
| 1205 | private void createTaskDiagramData(AbstractExecutable task) { |
---|
| 1206 | String uniqueTaskID = task.getJobId() + "_" + task.getId(); |
---|
| 1207 | |
---|
| 1208 | String resIDlist[] = task.getAllResourceName(); |
---|
| 1209 | String resID = resIDlist[resIDlist.length - 1]; |
---|
| 1210 | |
---|
| 1211 | long execStartTime = Double.valueOf(task.getExecStartTime()) |
---|
| 1212 | .longValue() * 1000; |
---|
| 1213 | long execEndTime = Double.valueOf(task.getFinishTime()).longValue() * 1000; |
---|
| 1214 | |
---|
| 1215 | TaskSeries taskRes = ganttDiagramTaskSeriesCollection.getSeries(resID); |
---|
| 1216 | if (taskRes == null) { |
---|
| 1217 | taskRes = new TaskSeries(resID); |
---|
| 1218 | ganttDiagramTaskSeriesCollection.add(taskRes); |
---|
| 1219 | } |
---|
| 1220 | org.jfree.data.gantt.Task ganttTask = new org.jfree.data.gantt.Task( |
---|
| 1221 | uniqueTaskID, new Date(execStartTime), new Date(execEndTime)); |
---|
| 1222 | if (!task.isFinished()) { |
---|
| 1223 | ganttTask.setPercentComplete(1.0); |
---|
| 1224 | } |
---|
| 1225 | taskRes.add(ganttTask); |
---|
| 1226 | } |
---|
| 1227 | |
---|
| 1228 | private void createTaskWaitingTimeDiagramData(AbstractExecutable task) { |
---|
| 1229 | String uniqueTaskID = task.getJobId() + "_" + task.getId(); |
---|
| 1230 | |
---|
| 1231 | String resIDlist[] = task.getAllResourceName(); |
---|
| 1232 | String resID = resIDlist[resIDlist.length - 1]; |
---|
| 1233 | |
---|
| 1234 | long execStartTime = Double.valueOf(task.getExecStartTime()) |
---|
| 1235 | .longValue() * 1000; |
---|
| 1236 | long execEndTime = Double.valueOf(task.getFinishTime()).longValue() * 1000; |
---|
| 1237 | |
---|
| 1238 | TaskSeries waitRes = ganttDiagramWaitingTimeSeriesCollection |
---|
| 1239 | .getSeries(resID); |
---|
| 1240 | if (waitRes == null) { |
---|
| 1241 | waitRes = new TaskSeries(resID); |
---|
| 1242 | ganttDiagramWaitingTimeSeriesCollection.add(waitRes); |
---|
| 1243 | } |
---|
| 1244 | |
---|
| 1245 | long sub = Double.valueOf(task.getSubmissionTime()).longValue() * 1000; |
---|
| 1246 | org.jfree.data.gantt.Task wait_exec = new org.jfree.data.gantt.Task( |
---|
| 1247 | uniqueTaskID, new Date(sub), new Date(execEndTime)); |
---|
| 1248 | org.jfree.data.gantt.Task exec = new org.jfree.data.gantt.Task( |
---|
| 1249 | uniqueTaskID, new Date(execStartTime), new Date(execEndTime)); |
---|
| 1250 | if (!task.isFinished()) { |
---|
| 1251 | exec.setPercentComplete(1.0); |
---|
| 1252 | } |
---|
| 1253 | wait_exec.addSubtask(wait_exec); |
---|
| 1254 | wait_exec.addSubtask(exec); |
---|
| 1255 | waitRes.add(wait_exec); |
---|
| 1256 | } |
---|
| 1257 | |
---|
| 1258 | private void prepareTaskReservationDiagramData() { |
---|
| 1259 | |
---|
| 1260 | for (Reservation reservation : reservations) { |
---|
| 1261 | if (reservation.getStatus() != Reservation.Status.CANCELED) { |
---|
| 1262 | String jobID = reservation.getJobId(); |
---|
| 1263 | String taskID = reservation.getTaskId(); |
---|
| 1264 | String uniqueTaskID = jobID + "_" + taskID; |
---|
| 1265 | String resID = reservation.getResourceProvider() |
---|
| 1266 | .getProviderId(); |
---|
| 1267 | |
---|
| 1268 | TaskSeries resRes = ganttDiagramReservationSeriesCollection |
---|
| 1269 | .getSeries(resID); |
---|
| 1270 | if (resRes == null) { |
---|
| 1271 | resRes = new TaskSeries(resID); |
---|
| 1272 | ganttDiagramReservationSeriesCollection.add(resRes); |
---|
| 1273 | } |
---|
| 1274 | |
---|
| 1275 | TimeResourceAllocation tra = reservation; |
---|
| 1276 | org.jfree.data.gantt.Task reserv = new org.jfree.data.gantt.Task( |
---|
| 1277 | uniqueTaskID, tra.getStart().toDate(), tra.getEnd() |
---|
| 1278 | .toDate()); |
---|
| 1279 | reserv.addSubtask(reserv); |
---|
| 1280 | resRes.add(reserv); |
---|
| 1281 | } |
---|
| 1282 | } |
---|
| 1283 | } |
---|
| 1284 | |
---|
| 1285 | private void createTaskReservationDiagramData(AbstractExecutable task) { |
---|
| 1286 | String uniqueTaskID = task.getJobId() + "_" + task.getId(); |
---|
| 1287 | |
---|
| 1288 | String resIDlist[] = task.getAllResourceName(); |
---|
| 1289 | String resID = resIDlist[resIDlist.length - 1]; |
---|
| 1290 | |
---|
| 1291 | long execStartTime = Double.valueOf(task.getExecStartTime()) |
---|
| 1292 | .longValue() * 1000; |
---|
| 1293 | long execEndTime = Double.valueOf(task.getFinishTime()).longValue() * 1000; |
---|
| 1294 | |
---|
| 1295 | if (reservations.size() > 0) { |
---|
| 1296 | TaskSeries resRes = ganttDiagramReservationSeriesCollection |
---|
| 1297 | .getSeries(resID); |
---|
| 1298 | if (resRes == null) { |
---|
| 1299 | resRes = new TaskSeries(resID); |
---|
| 1300 | ganttDiagramReservationSeriesCollection.add(resRes); |
---|
| 1301 | } |
---|
| 1302 | |
---|
| 1303 | org.jfree.data.gantt.Task reserv = resRes.get(uniqueTaskID); |
---|
| 1304 | if (reserv == null) { |
---|
| 1305 | if (log.isErrorEnabled()) |
---|
| 1306 | log.error("TASK: " + uniqueTaskID |
---|
| 1307 | + " is running without reservation!!!"); |
---|
| 1308 | reserv = new org.jfree.data.gantt.Task(uniqueTaskID, new Date( |
---|
| 1309 | execStartTime), new Date(execEndTime)); |
---|
| 1310 | resRes.add(reserv); |
---|
| 1311 | } |
---|
| 1312 | org.jfree.data.gantt.Task reservExec = new org.jfree.data.gantt.Task( |
---|
| 1313 | uniqueTaskID, new Date(execStartTime), |
---|
| 1314 | new Date(execEndTime)); |
---|
| 1315 | if (!task.isFinished()) { |
---|
| 1316 | reservExec.setPercentComplete(1.0f); |
---|
| 1317 | } |
---|
| 1318 | reserv.addSubtask(reservExec); |
---|
| 1319 | } |
---|
| 1320 | } |
---|
| 1321 | |
---|
| 1322 | private void saveGridletStatistics() { |
---|
| 1323 | |
---|
| 1324 | PrintStream gridletStatsFile = null; |
---|
| 1325 | if (configuration.creategridlethistorystatistics) { |
---|
| 1326 | try { |
---|
| 1327 | File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX |
---|
| 1328 | + simulationIdentifier + "_" |
---|
| 1329 | + GRIDLETS_STATISTICS_OUTPUT_FILE_NAME); |
---|
| 1330 | gridletStatsFile = new PrintStream(new FileOutputStream(file)); |
---|
| 1331 | } catch (IOException e) { |
---|
| 1332 | e.printStackTrace(); |
---|
| 1333 | } |
---|
| 1334 | |
---|
| 1335 | List<JobInterface<?>> list = (List<JobInterface<?>>) users |
---|
| 1336 | .getAllReceivedJobs(); |
---|
| 1337 | for (int i = 0; i < list.size(); i++) { |
---|
| 1338 | Job jobGridlet = (Job) list.get(i); |
---|
| 1339 | List<AbstractExecutable> executables = this.brokerInterface |
---|
| 1340 | .getExecutables().getJobExecutables(jobGridlet.getId()); |
---|
| 1341 | for (int j = 0; j < executables.size(); j++) { |
---|
| 1342 | AbstractExecutable exec = executables.get(j); |
---|
| 1343 | gridletStatsFile.print(exec.getGridletHistory()); |
---|
| 1344 | |
---|
| 1345 | gridletStatsFile.print("Job ID: " + jobGridlet.getId() |
---|
| 1346 | + " (Gridlet #" + exec.getGridletID() + ")"); |
---|
| 1347 | gridletStatsFile.println(", length = " |
---|
| 1348 | + exec.getGridletLength() + ", finished so far = " |
---|
| 1349 | + exec.getGridletFinishedSoFar()); |
---|
| 1350 | } |
---|
| 1351 | gridletStatsFile |
---|
| 1352 | .println("========================================="); |
---|
| 1353 | gridletStatsFile.println(); |
---|
| 1354 | gridletStatsFile.flush(); |
---|
| 1355 | } |
---|
| 1356 | } |
---|
| 1357 | if (gridletStatsFile != null) { |
---|
| 1358 | gridletStatsFile.close(); |
---|
| 1359 | } |
---|
| 1360 | } |
---|
| 1361 | |
---|
| 1362 | private boolean saveTaskGanttDiagrams() { |
---|
| 1363 | |
---|
| 1364 | JFreeChart taskDiagram = null; |
---|
| 1365 | JFreeChart waitingTimeDiagram = null; |
---|
| 1366 | JFreeChart reservationsDiagram = null; |
---|
| 1367 | |
---|
| 1368 | if (!generateDiagrams) |
---|
| 1369 | return false; |
---|
| 1370 | |
---|
| 1371 | String fileName = new File(outputFolderName, DIAGRAMS_FILE_NAME_PREFIX |
---|
| 1372 | + simulationIdentifier + "_").getAbsolutePath(); |
---|
| 1373 | |
---|
| 1374 | String chartName = "Gantt diagram for " |
---|
| 1375 | + GridSchedulingSimulator.SIMULATOR_NAME; |
---|
| 1376 | String simulationTime = "Simulation time"; |
---|
| 1377 | Title subtitle = new TextTitle("created for \"" + simulationIdentifier |
---|
| 1378 | + "\" at " + Calendar.getInstance().getTime().toString()); |
---|
| 1379 | |
---|
| 1380 | if (configuration.creatediagrams_tasks) { |
---|
| 1381 | taskDiagram = getTaskDiagram(chartName, subtitle, simulationTime); |
---|
| 1382 | if (!saveCategoryChart(taskDiagram, fileName + "Tasks", null /* "{0}" */)) |
---|
| 1383 | return false; |
---|
| 1384 | } |
---|
| 1385 | |
---|
| 1386 | if (configuration.creatediagrams_taskswaitingtime) { |
---|
| 1387 | waitingTimeDiagram = getWaitingTimeDiagram(chartName, subtitle, |
---|
| 1388 | simulationTime); |
---|
| 1389 | if (!saveCategoryChart(waitingTimeDiagram, fileName |
---|
| 1390 | + "Waiting_Time", null /* "Task {1} at {0}" */)) |
---|
| 1391 | return false; |
---|
| 1392 | } |
---|
| 1393 | |
---|
| 1394 | if (configuration.creatediagrams_reservations |
---|
| 1395 | && reservations.size() > 0) { |
---|
| 1396 | reservationsDiagram = getReservationDiagram(chartName, subtitle, |
---|
| 1397 | simulationTime); |
---|
| 1398 | if (!saveCategoryChart(reservationsDiagram, fileName |
---|
| 1399 | + "Reservations", "Task {1} at {0}")) |
---|
| 1400 | return false; |
---|
| 1401 | } |
---|
| 1402 | |
---|
| 1403 | return true; |
---|
| 1404 | } |
---|
| 1405 | |
---|
| 1406 | private JFreeChart getTaskDiagram(String chartName, Title subtitle, |
---|
| 1407 | String simulationTime) { |
---|
| 1408 | String tasks = "Tasks"; |
---|
| 1409 | boolean urls = false; |
---|
| 1410 | boolean tooltip = true; |
---|
| 1411 | boolean legend = true; |
---|
| 1412 | JFreeChart chart = ChartFactory.createGanttChart(chartName, tasks, |
---|
| 1413 | simulationTime, ganttDiagramTaskSeriesCollection, legend, |
---|
| 1414 | tooltip, urls); |
---|
| 1415 | chart.addSubtitle(subtitle); |
---|
| 1416 | GanttRenderer re = (GanttRenderer) chart.getCategoryPlot() |
---|
| 1417 | .getRenderer(); |
---|
| 1418 | re.setCompletePaint(Color.black); |
---|
| 1419 | return chart; |
---|
| 1420 | } |
---|
| 1421 | |
---|
| 1422 | private JFreeChart getWaitingTimeDiagram(String chartName, Title subtitle, |
---|
| 1423 | String simulationTime) { |
---|
| 1424 | String tasks = "Tasks"; |
---|
| 1425 | boolean urls = false; |
---|
| 1426 | boolean tooltip = true; |
---|
| 1427 | boolean legend = true; |
---|
| 1428 | JFreeChart chart = ChartFactory.createGanttChart(chartName, tasks, |
---|
| 1429 | simulationTime, ganttDiagramWaitingTimeSeriesCollection, |
---|
| 1430 | legend, tooltip, urls); |
---|
| 1431 | chart.addSubtitle(subtitle); |
---|
| 1432 | chart.getPlot().setForegroundAlpha(ALPHA); |
---|
| 1433 | GanttRenderer re = (GanttRenderer) chart.getCategoryPlot() |
---|
| 1434 | .getRenderer(); |
---|
| 1435 | re.setCompletePaint(Color.black); |
---|
| 1436 | return chart; |
---|
| 1437 | } |
---|
| 1438 | |
---|
| 1439 | private JFreeChart getReservationDiagram(String chartName, Title subtitle, |
---|
| 1440 | String simulationTime) { |
---|
| 1441 | String tasks = "Tasks"; |
---|
| 1442 | boolean urls = false; |
---|
| 1443 | boolean tooltip = true; |
---|
| 1444 | boolean legend = true; |
---|
| 1445 | JFreeChart chart = ChartFactory.createGanttChart(chartName, tasks, |
---|
| 1446 | simulationTime, ganttDiagramReservationSeriesCollection, |
---|
| 1447 | legend, tooltip, urls); |
---|
| 1448 | chart.addSubtitle(subtitle); |
---|
| 1449 | chart.getPlot().setForegroundAlpha(ALPHA); |
---|
| 1450 | GanttRenderer re = (GanttRenderer) chart.getCategoryPlot() |
---|
| 1451 | .getRenderer(); |
---|
| 1452 | re.setCompletePaint(Color.black); |
---|
| 1453 | return chart; |
---|
| 1454 | } |
---|
| 1455 | |
---|
| 1456 | /************* NETWORK STATISTICS SECTION **************/ |
---|
| 1457 | public void gatherNetworkStatistics() { |
---|
| 1458 | |
---|
| 1459 | PrintStream netStatsFile = null; |
---|
| 1460 | if (topology != null) { |
---|
| 1461 | try { |
---|
| 1462 | File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX |
---|
| 1463 | + simulationIdentifier + "_" |
---|
| 1464 | + NETWORK_SIMULATION_STATISTICS_OUTPUT_FILE_NAME); |
---|
| 1465 | netStatsFile = new PrintStream(new FileOutputStream(file)); |
---|
| 1466 | } catch (IOException e) { |
---|
| 1467 | netStatsFile = null; |
---|
| 1468 | } |
---|
| 1469 | if (netStatsFile != null) { |
---|
| 1470 | |
---|
| 1471 | for (int i = 0; i < topology.getLinks().size(); i++) { |
---|
| 1472 | |
---|
| 1473 | GSSIMFlowLink link = (GSSIMFlowLink) topology.getLinks() |
---|
| 1474 | .get(i); |
---|
| 1475 | LinkStats linkStats = createLinkStats(link); |
---|
| 1476 | Object txt = linkStats.serialize(this.serializer); |
---|
| 1477 | netStatsFile.println(txt); |
---|
| 1478 | } |
---|
| 1479 | |
---|
| 1480 | { |
---|
| 1481 | List<NetworkReservationObject> networkReservations = ((NetworkGridBroker) brokerInterface) |
---|
| 1482 | .getReservations(); |
---|
| 1483 | for (int i = 0; i < networkReservations.size(); i++) { |
---|
| 1484 | NetworkReservationStats resStats = createNetworkReservationStats(networkReservations |
---|
| 1485 | .get(i)); |
---|
| 1486 | Object txt = resStats.serialize(this.serializer); |
---|
| 1487 | netStatsFile.println(txt); |
---|
| 1488 | } |
---|
| 1489 | |
---|
| 1490 | } |
---|
| 1491 | /* |
---|
| 1492 | * if (configuration.formatstatisticsoutput) |
---|
| 1493 | * printFormatedLinkReservationStatsHeader(netStatsFile); else |
---|
| 1494 | * printLinkReservationStatsHeader(netStatsFile); for (int i = |
---|
| 1495 | * 0; i < topology.getLinks().size(); i++) { |
---|
| 1496 | * |
---|
| 1497 | * GSSIMFlowLink link = (GSSIMFlowLink) topology.getLinks() |
---|
| 1498 | * .get(i); LinkStats linkStats = |
---|
| 1499 | * createLinkReservationStats(link); if |
---|
| 1500 | * (configuration.formatstatisticsoutput) |
---|
| 1501 | * saveFormatedLinkReservationStats(linkStats, netStatsFile); |
---|
| 1502 | * else saveLinkReservationStats(linkStats, netStatsFile); } |
---|
| 1503 | */ |
---|
| 1504 | printNetworkDataStatsHeader(netStatsFile); |
---|
| 1505 | saveNetworkDataStats(netStatsFile); |
---|
| 1506 | netStatsFile.close(); |
---|
| 1507 | } |
---|
| 1508 | } |
---|
| 1509 | } |
---|
| 1510 | |
---|
| 1511 | private LinkStats createLinkStats(GSSIMFlowLink link) { |
---|
| 1512 | |
---|
| 1513 | LinkStats linkStats = new LinkStats(link.get_name()); |
---|
| 1514 | double flowsSize = 0; |
---|
| 1515 | double duration = (this.endSimulationTime - this.startSimulationTime) |
---|
| 1516 | / GSSimStatistics.MILLI_SEC; |
---|
| 1517 | ArrayList fsc = (ArrayList) link.getFlowsSizeCharacteristic(); |
---|
| 1518 | for (int i = 0; i < fsc.size(); i++) { |
---|
| 1519 | flowsSize += (Long) fsc.get(i); |
---|
| 1520 | } |
---|
| 1521 | linkStats.flowsSize = flowsSize; |
---|
| 1522 | double allReservationsSize = 0; |
---|
| 1523 | ArrayList arl = (ArrayList) link.getCompletedReservationsList(); |
---|
| 1524 | for (int i = 0; i < arl.size(); i++) { |
---|
| 1525 | NetworkReservationObject netResObj = (NetworkReservationObject) arl |
---|
| 1526 | .get(i); |
---|
| 1527 | allReservationsSize += (netResObj.getDuration() * netResObj |
---|
| 1528 | .getBandwidth()) |
---|
| 1529 | / GSSimStatistics.MILLI_SEC; |
---|
| 1530 | } |
---|
| 1531 | linkStats.startBaduRate = link.getStartBaduRate(); |
---|
| 1532 | linkStats.delay = link.getDelay(); |
---|
| 1533 | linkStats.load = (GSSimStatistics.BITS * flowsSize + allReservationsSize) |
---|
| 1534 | / (link.getStartBaduRate() * duration); |
---|
| 1535 | linkStats.reservationLoad = allReservationsSize |
---|
| 1536 | / (link.getStartBaduRate() * duration); |
---|
| 1537 | // linkStats.createLinkReservationStatistics(link); |
---|
| 1538 | return linkStats; |
---|
| 1539 | } |
---|
| 1540 | |
---|
| 1541 | private NetworkReservationStats createNetworkReservationStats( |
---|
| 1542 | NetworkReservationObject netResObj) { |
---|
| 1543 | |
---|
| 1544 | NetworkReservationStats resStats = new NetworkReservationStats( |
---|
| 1545 | netResObj.getReservationID()); |
---|
| 1546 | double flowsSize = 0; |
---|
| 1547 | resStats.route = netResObj.getLinksNames(); |
---|
| 1548 | resStats.startTime = netResObj.getStartTime(); |
---|
| 1549 | resStats.endTime = netResObj.getEndTime(); |
---|
| 1550 | resStats.bandwidth = netResObj.getBandwidth(); |
---|
| 1551 | if (netResObj.getStatus() == ExtendedGridSimTags.RESERVATION_CANCELED) |
---|
| 1552 | resStats.status = "CANCELED"; |
---|
| 1553 | else |
---|
| 1554 | resStats.status = "FINISHED"; |
---|
| 1555 | Iterator it = netResObj.getLinks().iterator(); |
---|
| 1556 | while (it.hasNext()) { |
---|
| 1557 | flowsSize = 0; |
---|
| 1558 | GSSIMFlowLink link = (GSSIMFlowLink) it.next(); |
---|
| 1559 | ArrayList fursc = (ArrayList) link |
---|
| 1560 | .getFlowsUsingReservationsCharacteristic().get( |
---|
| 1561 | netResObj.getReservationID()); |
---|
| 1562 | if (fursc == null) |
---|
| 1563 | continue; |
---|
| 1564 | for (int i = 0; i < fursc.size(); i++) { |
---|
| 1565 | flowsSize += (Long) fursc.get(i); |
---|
| 1566 | } |
---|
| 1567 | resStats.flowsSize = flowsSize; |
---|
| 1568 | resStats.load = (GSSimStatistics.BITS * flowsSize) |
---|
| 1569 | / ((netResObj.getBandwidth() * netResObj.getDuration()) / GSSimStatistics.MILLI_SEC); |
---|
| 1570 | break; |
---|
| 1571 | } |
---|
| 1572 | return resStats; |
---|
| 1573 | } |
---|
| 1574 | |
---|
| 1575 | |
---|
| 1576 | /* |
---|
| 1577 | * private LinkStats createLinkReservationStats(GSSIMFlowLink link) { |
---|
| 1578 | * |
---|
| 1579 | * LinkStats linkStats = new LinkStats(link.get_name()); |
---|
| 1580 | * linkStats.createLinkReservationStatistics(link); return linkStats; } |
---|
| 1581 | */ |
---|
| 1582 | |
---|
| 1583 | private void printNetworkDataStatsHeader(PrintStream outStream) { |
---|
| 1584 | |
---|
| 1585 | outStream.print("JobID"); |
---|
| 1586 | outStream.print(TASK_SEPARATOR); |
---|
| 1587 | outStream.print("TaskID"); |
---|
| 1588 | outStream.print(TASK_SEPARATOR); |
---|
| 1589 | outStream.print("file name"); |
---|
| 1590 | outStream.print(TASK_SEPARATOR); |
---|
| 1591 | outStream.print("data route"); |
---|
| 1592 | outStream.print(NETWORK_SEPARATOR); |
---|
| 1593 | outStream.print("start date"); |
---|
| 1594 | outStream.print(NETWORK_SEPARATOR); |
---|
| 1595 | outStream.print("end date"); |
---|
| 1596 | outStream.print(NETWORK_SEPARATOR); |
---|
| 1597 | outStream.print("reservation ID"); |
---|
| 1598 | outStream.println(NETWORK_SEPARATOR); |
---|
| 1599 | } |
---|
| 1600 | |
---|
| 1601 | private void saveNetworkDataStats(PrintStream outStream) { |
---|
| 1602 | |
---|
| 1603 | for (NetworkData netData : receivedNetData) { |
---|
| 1604 | TaskInputFile tif = (TaskInputFile) netData.getData(); |
---|
| 1605 | outStream.print(tif.getJobID()); |
---|
| 1606 | outStream.print(NETWORK_SEPARATOR); |
---|
| 1607 | outStream.print(tif.getTaskID()); |
---|
| 1608 | outStream.print(NETWORK_SEPARATOR); |
---|
| 1609 | outStream.print(tif.getFileName()); |
---|
| 1610 | outStream.print(NETWORK_SEPARATOR); |
---|
| 1611 | outStream.print(netData.getRoute()); |
---|
| 1612 | outStream.print(NETWORK_SEPARATOR); |
---|
| 1613 | outStream.print(netData.getStartTime()); |
---|
| 1614 | outStream.print(NETWORK_SEPARATOR); |
---|
| 1615 | outStream.print(netData.getEndTime()); |
---|
| 1616 | outStream.print(NETWORK_SEPARATOR); |
---|
| 1617 | outStream.print(netData.getReservationID()); |
---|
| 1618 | outStream.println(NETWORK_SEPARATOR); |
---|
| 1619 | } |
---|
| 1620 | } |
---|
| 1621 | |
---|
| 1622 | /* |
---|
| 1623 | * private void saveLinkReservationStats(LinkStats linkStats, PrintStream |
---|
| 1624 | * outStream) { |
---|
| 1625 | * |
---|
| 1626 | * outStream.print(linkStats.linkName); |
---|
| 1627 | * outStream.println(NETWORK_SEPARATOR); for (int i = 0; i < |
---|
| 1628 | * linkStats.reservationStats.size(); i++) { LinkStats.LinkReservationStats |
---|
| 1629 | * resStats = linkStats.reservationStats .get(i); |
---|
| 1630 | * outStream.print(resStats.reservationID); |
---|
| 1631 | * outStream.print(NETWORK_SEPARATOR); outStream.print(resStats.startTime); |
---|
| 1632 | * outStream.print(NETWORK_SEPARATOR); outStream.print(resStats.endTime); |
---|
| 1633 | * outStream.print(NETWORK_SEPARATOR); outStream.print(resStats.bandwidth); |
---|
| 1634 | * outStream.print(NETWORK_SEPARATOR); |
---|
| 1635 | * outStream.print(NETWORK_NUMBER_FORMAT.format(resStats.flowsSize)); |
---|
| 1636 | * outStream.print(NETWORK_SEPARATOR); |
---|
| 1637 | * outStream.print(NETWORK_NUMBER_FORMAT.format(resStats.load)); |
---|
| 1638 | * outStream.println(NETWORK_SEPARATOR); } } |
---|
| 1639 | */ |
---|
| 1640 | |
---|
| 1641 | private boolean saveCategoryChart(JFreeChart c, String fileName, |
---|
| 1642 | String labelFormat) { |
---|
| 1643 | c.setNotify(false); |
---|
| 1644 | c.setAntiAlias(true); |
---|
| 1645 | c.setTextAntiAlias(true); |
---|
| 1646 | c.setBorderVisible(false); |
---|
| 1647 | |
---|
| 1648 | CategoryPlot categoryplot = (CategoryPlot) c.getPlot(); |
---|
| 1649 | categoryplot.setDomainGridlinesVisible(true); |
---|
| 1650 | |
---|
| 1651 | if (labelFormat != null) { |
---|
| 1652 | CategoryItemRenderer rend = categoryplot.getRenderer(); |
---|
| 1653 | rend.setBaseItemLabelsVisible(true); |
---|
| 1654 | ItemLabelPosition position = new ItemLabelPosition( |
---|
| 1655 | ItemLabelAnchor.CENTER, TextAnchor.CENTER); |
---|
| 1656 | rend.setBasePositiveItemLabelPosition(position); |
---|
| 1657 | NumberFormat nf = NumberFormat.getInstance(); |
---|
| 1658 | CategoryItemLabelGenerator gen = new StandardCategoryItemLabelGenerator( |
---|
| 1659 | labelFormat, nf); |
---|
| 1660 | rend.setBaseItemLabelGenerator(gen); |
---|
| 1661 | } |
---|
| 1662 | |
---|
| 1663 | int rows = c.getCategoryPlot().getDataset().getColumnKeys().size(); |
---|
| 1664 | |
---|
| 1665 | int height = 900; |
---|
| 1666 | if (rows > 45) { |
---|
| 1667 | height = rows * 20; |
---|
| 1668 | } |
---|
| 1669 | int width = calculateChartWidth(c); |
---|
| 1670 | CategoryItemRenderer rend = c.getCategoryPlot().getRenderer(); |
---|
| 1671 | |
---|
| 1672 | for (int i = 0; i < c.getCategoryPlot().getDataset().getRowKeys() |
---|
| 1673 | .size(); i++) { |
---|
| 1674 | Paint collor = c.getCategoryPlot().getDrawingSupplier() |
---|
| 1675 | .getNextPaint(); |
---|
| 1676 | rend.setSeriesOutlinePaint(i, collor); |
---|
| 1677 | rend.setSeriesPaint(i, collor); |
---|
| 1678 | } |
---|
| 1679 | |
---|
| 1680 | ChartRenderingInfo info = new ChartRenderingInfo(); |
---|
| 1681 | // info.setEntityCollection(null); |
---|
| 1682 | File f = new File(fileName + "." + ImageFormat.PNG); |
---|
| 1683 | final String gssimSubtitle = "Created by " |
---|
| 1684 | + GridSchedulingSimulator.SIMULATOR_NAME |
---|
| 1685 | + " http://www.gssim.org/"; |
---|
| 1686 | c.addSubtitle(new TextTitle(gssimSubtitle)); |
---|
| 1687 | boolean encodeAlpha = false; |
---|
| 1688 | int compression = 9; |
---|
| 1689 | try { |
---|
| 1690 | ChartUtilities.saveChartAsPNG(f, c, width, height, info, |
---|
| 1691 | encodeAlpha, compression); |
---|
| 1692 | |
---|
| 1693 | } catch (IOException e) { |
---|
| 1694 | e.printStackTrace(); |
---|
| 1695 | return false; |
---|
| 1696 | } catch (Exception e) { |
---|
| 1697 | if (log.isErrorEnabled()) |
---|
| 1698 | log |
---|
| 1699 | .error( |
---|
| 1700 | "The png file (" |
---|
| 1701 | + fileName |
---|
| 1702 | + ")\nwill not be generated (It can be too large data size problem)", |
---|
| 1703 | e); |
---|
| 1704 | } catch (Throwable t) { |
---|
| 1705 | log |
---|
| 1706 | .error( |
---|
| 1707 | "The png file (" |
---|
| 1708 | + fileName |
---|
| 1709 | + ")\nwill not be generated (It can be too large data size problem)", |
---|
| 1710 | t); |
---|
| 1711 | } |
---|
| 1712 | |
---|
| 1713 | return true; |
---|
| 1714 | } |
---|
| 1715 | |
---|
| 1716 | private int calculateChartWidth(JFreeChart c) { |
---|
| 1717 | |
---|
| 1718 | int ganttWidth = GANTT_WIDTH; |
---|
| 1719 | int rows = c.getCategoryPlot().getDataset().getColumnKeys().size(); |
---|
| 1720 | |
---|
| 1721 | if (rows > 45) { |
---|
| 1722 | int height = rows * 20; |
---|
| 1723 | ganttWidth = Math.max((int) (height * 1.5), GANTT_WIDTH); |
---|
| 1724 | } |
---|
| 1725 | return ganttWidth; |
---|
| 1726 | } |
---|
| 1727 | |
---|
| 1728 | private boolean saveXYPlotChart(JFreeChart c, String fileName) { |
---|
| 1729 | c.setNotify(false); |
---|
| 1730 | c.setAntiAlias(true); |
---|
| 1731 | c.setTextAntiAlias(true); |
---|
| 1732 | c.setBorderVisible(false); |
---|
| 1733 | |
---|
| 1734 | int height = 900; |
---|
| 1735 | |
---|
| 1736 | CombinedDomainXYPlot cPlot = (CombinedDomainXYPlot) c.getPlot(); |
---|
| 1737 | int nPlots = cPlot.getSubplots().size(); |
---|
| 1738 | |
---|
| 1739 | if (nPlots > 3) { |
---|
| 1740 | height = nPlots * 300; |
---|
| 1741 | } |
---|
| 1742 | int width = GANTT_WIDTH; |
---|
| 1743 | |
---|
| 1744 | if (configuration.creatediagrams_resources_scale != -1) |
---|
| 1745 | width = (int) ((endSimulationTime - startSimulationTime) * configuration.creatediagrams_resources_scale); |
---|
| 1746 | ChartRenderingInfo info = new ChartRenderingInfo(); |
---|
| 1747 | File f = new File(fileName + "." + ImageFormat.PNG); |
---|
| 1748 | final String gssimSubtitle = "Created by " |
---|
| 1749 | + GridSchedulingSimulator.SIMULATOR_NAME |
---|
| 1750 | + " http://www.gssim.org/"; |
---|
| 1751 | c.addSubtitle(new TextTitle(gssimSubtitle)); |
---|
| 1752 | boolean encodeAlpha = false; |
---|
| 1753 | int compression = 9;// values 0-9 |
---|
| 1754 | try { |
---|
| 1755 | ChartUtilities.saveChartAsPNG(f, c, width, height, info, |
---|
| 1756 | encodeAlpha, compression); |
---|
| 1757 | } catch (IOException e) { |
---|
| 1758 | e.printStackTrace(); |
---|
| 1759 | return false; |
---|
| 1760 | } |
---|
| 1761 | return true; |
---|
| 1762 | } |
---|
| 1763 | |
---|
| 1764 | private void createStatsData() { |
---|
| 1765 | statsData.put(MAKESPAN, accStats.makespan); |
---|
| 1766 | statsData.put(TASK_COMPLETION_TIME, accStats.meanTaskCompletionTime); |
---|
| 1767 | statsData.put(TASK_EXECUTION_TIME, accStats.meanTaskExecutionTime); |
---|
| 1768 | statsData.put(TASK_START_TIME, accStats.meanTaskStartTime); |
---|
| 1769 | statsData.put(TASK_FLOW_TIME, accStats.meanTaskFlowTime); |
---|
| 1770 | statsData.put(TASK_WAITING_TIME, accStats.meanTaskWaitingTime); |
---|
| 1771 | statsData.put(TASK_LATENESS, accStats.lateness); |
---|
| 1772 | statsData.put(TASK_TARDINESS, accStats.tardiness); |
---|
| 1773 | statsData.put(DELAYED_TASKS, accStats.delayedTasks); |
---|
| 1774 | statsData.put(FAILED_REQUESTS, accStats.failedRequests); |
---|
| 1775 | statsData.put(RESOURCES_TOTAL_LOAD, accStats.meanTotalLoad); |
---|
| 1776 | statsData.put(RESOURCES_RESERVATION_LOAD, accStats.meanReservationLoad); |
---|
| 1777 | statsData.put(RESOURCES_RESERVATION_LOAD, accStats.meanEnergyUsage); |
---|
| 1778 | statsData.put(RESOURCES_QUEUE_LENGTH, accStats.meanQueueLength); |
---|
| 1779 | } |
---|
| 1780 | |
---|
| 1781 | public GSSAccumulator getStats(String name) { |
---|
| 1782 | return statsData.get(name); |
---|
| 1783 | } |
---|
| 1784 | |
---|
| 1785 | public boolean accumulatedStats() { |
---|
| 1786 | return configuration.createsimulationstatistics; |
---|
| 1787 | } |
---|
| 1788 | |
---|
| 1789 | public static class JobIdComparator implements Comparator<JobInterface<?>> { |
---|
| 1790 | |
---|
| 1791 | public int compare(JobInterface<?> o1, JobInterface<?> o2) { |
---|
| 1792 | try { |
---|
| 1793 | return o1.getId().compareTo(o2.getId()); |
---|
| 1794 | } catch (NoSuchFieldException e) { |
---|
| 1795 | e.printStackTrace(); |
---|
| 1796 | } |
---|
| 1797 | return -1; |
---|
| 1798 | } |
---|
| 1799 | } |
---|
| 1800 | |
---|
| 1801 | |
---|
| 1802 | /* |
---|
| 1803 | * private void saveFormatedLinkReservationStats(LinkStats linkStats, |
---|
| 1804 | * PrintStream outStream) { outStream.printf("%15s", linkStats.linkName); |
---|
| 1805 | * outStream.println(); for (int i = 0; i < |
---|
| 1806 | * linkStats.reservationStats.size(); i++) { LinkStats.LinkReservationStats |
---|
| 1807 | * resStats = linkStats.reservationStats .get(i); outStream.printf("%15s", |
---|
| 1808 | * resStats.reservationID); outStream.printf("%32s", new |
---|
| 1809 | * DateTime(resStats.startTime)); outStream.printf("%31s", new |
---|
| 1810 | * DateTime(resStats.endTime)); outStream.printf("%16s", |
---|
| 1811 | * NETWORK_NUMBER_FORMAT .format(resStats.bandwidth)); |
---|
| 1812 | * outStream.printf("%35s", NETWORK_NUMBER_FORMAT |
---|
| 1813 | * .format(resStats.flowsSize)); outStream.printf("%10s", |
---|
| 1814 | * NETWORK_NUMBER_FORMAT .format(resStats.load)); outStream.println(); } |
---|
| 1815 | * outStream.println(); } |
---|
| 1816 | */ |
---|
| 1817 | } |
---|