Changeset 1207 for DCWoRMS/branches/coolemall/src/simulator/stats/implementation/DCWormsStatistics.java
- Timestamp:
- 11/26/13 11:56:07 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DCWoRMS/branches/coolemall/src/simulator/stats/implementation/DCWormsStatistics.java
r1199 r1207 7 7 import java.io.IOException; 8 8 import java.io.PrintStream; 9 import java.text.DecimalFormat; 9 10 import java.text.NumberFormat; 10 11 import java.util.ArrayList; … … 14 15 import java.util.Date; 15 16 import java.util.HashMap; 17 import java.util.HashSet; 16 18 import java.util.List; 17 19 import java.util.Map; 20 import java.util.Set; 18 21 import java.util.SortedMap; 19 22 import java.util.TreeMap; … … 54 57 55 58 import schedframe.ExecutablesList; 56 import schedframe. ResourceController;59 import schedframe.SimulatedEnvironment; 57 60 import schedframe.exceptions.ResourceException; 58 61 import schedframe.resources.ResourceType; … … 66 69 import schedframe.resources.computing.profiles.energy.power.PowerUsage; 67 70 import schedframe.resources.computing.profiles.energy.thermal.TemperatureValue; 68 import schedframe.resources.units.PEUnit; 71 import schedframe.resources.devices.Device; 72 import schedframe.resources.devices.PhysicalResource; 69 73 import schedframe.resources.units.ProcessingElements; 70 74 import schedframe.resources.units.ResourceUnit; … … 82 86 import simulator.GenericUser; 83 87 import simulator.stats.GSSAccumulator; 88 import simulator.stats.MetricsCalculator; 84 89 import simulator.stats.SimulationStatistics; 85 90 import simulator.stats.implementation.out.AbstractStringSerializer; 86 91 import simulator.stats.implementation.out.CoolEmAllStringSerializer; 92 import simulator.stats.implementation.out.StringSerializer; 87 93 import csiro.mit.utils.jfreechart.timetablechart.TimetableChartFactory; 88 94 import csiro.mit.utils.jfreechart.timetablechart.data.Timetable; … … 93 99 import dcworms.schedframe.scheduling.Executable; 94 100 import eduni.simjava.Sim_stat; 101 import example.energy.coolemall.CoolEmAllTestbedMeasurements; 95 102 96 103 public class DCWormsStatistics implements SimulationStatistics { … … 111 118 protected static final String AIRFLOW_STATISTICS_OUTPUT_FILE_NAME = "AirThroughput.txt"; 112 119 protected static final String TEMPERATURE_STATISTICS_OUTPUT_FILE_NAME = "Temperature.txt"; 113 120 protected static final String USEFUL_WORK_STATISTICS_OUTPUT_FILE_NAME = "UsefulWork.txt"; 121 protected static final String DEVICE_STATISTICS_OUTPUT_FILE_NAME = "Devices.txt"; 122 protected static final String NODES_AVAILABILITY_STATISTICS_OUTPUT_FILE_NAME = "NodesAvailability.txt"; 123 protected static final String METRICS_STATISTICS_OUTPUT_FILE_NAME = "Metrics.txt"; 124 protected static final String RESOURCE_HISTORY_OUTPUT_FILE_NAME = "ResourceHistyory.txt"; 125 114 126 protected static final String DIAGRAMS_FILE_NAME_PREFIX = "Chart_"; 115 127 protected static final String STATS_FILE_NAME_PREFIX = "Stats_"; … … 127 139 128 140 protected GenericUser users; 129 protected ResourceControllerresourceController;141 protected SimulatedEnvironment resourceController; 130 142 protected boolean generateDiagrams = true; 131 143 protected AbstractStringSerializer serializer; … … 154 166 protected TaskSeriesCollection ganttDiagramTaskSeriesCollection; 155 167 protected TaskSeriesCollection ganttDiagramWaitingTimeSeriesCollection; 156 protected Map<String, List<String>> task_processorsMap;168 protected Map<String, Set<ComputingResource>> task_processorsMap; 157 169 158 170 protected JobRegistry jr; 159 171 protected MetricsCalculator metCalc; 160 172 161 173 public DCWormsStatistics(String simulationIdentifier, ConfigurationOptions co, GenericUser users, 162 String outputFolderName, ResourceControllerresourceController) {174 String outputFolderName, SimulatedEnvironment resourceController) { 163 175 this.simulationIdentifier = simulationIdentifier; 164 176 this.configuration = co; … … 167 179 this.outputFolderName = outputFolderName; 168 180 169 this.serializer = new CoolEmAllStringSerializer(); 181 this.serializer = new StringSerializer(); 182 183 if(DataCenterWorkloadSimulator.MODE.equals("CoolEmAll")){ 184 this.serializer = new CoolEmAllStringSerializer(); 185 } 170 186 this.serializer.setDefaultNumberFormat(DataCenterWorkloadSimulator.DFAULT_NUMBER_FORMAT); 171 187 … … 173 189 this.jr = new JobRegistryImpl(""); 174 190 init(); 191 metCalc = new MetricsCalculator(); 175 192 } 176 193 … … 183 200 this.endSimulationTime = DateTimeUtilsExt.currentTimeMillis(); 184 201 202 metCalc.setStartTime(startSimulationTime); 203 metCalc.setEndTime(endSimulationTime); 204 185 205 long s = 0; 186 206 long e = 0; … … 211 231 212 232 private void init() { 213 task_processorsMap = new HashMap<String, List<String>>();233 task_processorsMap = new HashMap<String, Set<ComputingResource>>(); 214 234 accStats = new GSSAccumulatorsStats(); 215 235 statsData = new HashMap<String, GSSAccumulator>(); … … 229 249 if (simulationStatsFile != null) { 230 250 Object txt = accStats.serialize(this.serializer); 251 252 DecimalFormat df = new DecimalFormat(); 253 df.setMaximumFractionDigits(3); 254 df.setGroupingUsed(false); 255 256 /*log.info("#STATS " + "Performance statistics"); 257 log.info("#STATS " + "Makespan: " + accStats.makespan.getMean() + " [s]"); 258 log.info("#STATS " + "Task completion time - " + "min: " + accStats.meanTaskCompletionTime.getMin() + "; max: " + accStats.meanTaskCompletionTime.getMax() + " [s]"); 259 log.info("#STATS " + "Mean task execution time: " + accStats.meanTaskExecutionTime.getMean() + " [s]"); 260 log.info("#STATS " + "System load: " + accStats.meanTotalLoad.getMean() * 100 + " [%]");*/ 261 262 System.out.println("#STATS " + "===== Performance statistics ====="); 263 System.out.println("#STATS " + "Makespan: " + df.format(accStats.makespan.getMean()) + " [s]"); 264 System.out.println("#STATS " + "Task completion time - " + "min: " + df.format(accStats.meanTaskCompletionTime.getMin()) + " [s]" + "; max: " + df.format(accStats.meanTaskCompletionTime.getMax()) + " [s]"); 265 System.out.println("#STATS " + "Mean task execution time: " + df.format(accStats.meanTaskExecutionTime.getMean()) + " [s]"); 266 System.out.println("#STATS " + "System load: " + df.format(accStats.meanTotalLoad.getMean() * 100) + " [%]"); 267 231 268 simulationStatsFile.println(txt); 232 269 } … … 238 275 239 276 /************* RESOURCE STATISTICS SECTION **************/ 240 p rivatevoid gatherResourceStatistics() {277 public void gatherResourceStatistics() { 241 278 242 279 HashMap<String, List<Stats>> type_stats = new HashMap<String, List<Stats>>(); 243 280 244 for(String resource Name: resourceController.getComputingResourceLayers()){281 for(String resourceTypeName: resourceController.getComputingResourceLayers()){ 245 282 List<Stats> cStats = new ArrayList<Stats>(); 246 283 cStats.add(Stats.textLoad); 247 if(ArrayUtils.contains(configuration.resForUtilizationChart, resource Name))284 if(ArrayUtils.contains(configuration.resForUtilizationChart, resourceTypeName)) 248 285 cStats.add(Stats.chartLoad); 249 286 cStats.add(Stats.textEnergy); 250 if(ArrayUtils.contains(configuration.resForEnergyChart, resource Name))287 if(ArrayUtils.contains(configuration.resForEnergyChart, resourceTypeName)) 251 288 cStats.add(Stats.chartEnergy); 252 289 cStats.add(Stats.textAirFlow); 253 if(ArrayUtils.contains(configuration.resForAirFlowChart, resource Name))290 if(ArrayUtils.contains(configuration.resForAirFlowChart, resourceTypeName)) 254 291 cStats.add(Stats.chartAirFlow); 255 292 cStats.add(Stats.textTemperature); 256 if(ArrayUtils.contains(configuration.resForTemperatureChart, resource Name))293 if(ArrayUtils.contains(configuration.resForTemperatureChart, resourceTypeName)) 257 294 cStats.add(Stats.chartTemperature); 258 type_stats.put(resourceName, cStats); 295 type_stats.put(resourceTypeName, cStats); 296 259 297 } 260 298 … … 269 307 ganttDiagramTimetable = new Timetable(new FixedMillisecond( 270 308 startSimulationTime), new FixedMillisecond(endSimulationTime)); 309 271 310 272 311 PrintStream resourceLoadStatsFile = null; … … 310 349 } 311 350 351 PrintStream deviceStatsFile = null; 352 try { 353 File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX 354 + simulationIdentifier + "_" 355 + DEVICE_STATISTICS_OUTPUT_FILE_NAME); 356 deviceStatsFile = new PrintStream(new FileOutputStream(file)); 357 } catch (IOException e) { 358 deviceStatsFile = null; 359 } 360 361 PrintStream nodesAvailabilityStatsFile = null; 362 try { 363 File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX 364 + simulationIdentifier + "_" 365 + NODES_AVAILABILITY_STATISTICS_OUTPUT_FILE_NAME); 366 nodesAvailabilityStatsFile = new PrintStream(new FileOutputStream(file)); 367 } catch (IOException e) { 368 nodesAvailabilityStatsFile = null; 369 } 370 371 PrintStream metricsStatsFile = null; 372 try { 373 File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX 374 + simulationIdentifier + "_" 375 + METRICS_STATISTICS_OUTPUT_FILE_NAME); 376 metricsStatsFile = new PrintStream(new FileOutputStream(file)); 377 } catch (IOException e) { 378 metricsStatsFile = null; 379 } 380 381 PrintStream usefulWorkStatsFile = null; 382 try { 383 File file = new File(outputFolderName + STATS_FILE_NAME_PREFIX 384 + simulationIdentifier + "_" 385 + USEFUL_WORK_STATISTICS_OUTPUT_FILE_NAME); 386 usefulWorkStatsFile = new PrintStream(new FileOutputStream(file)); 387 } catch (IOException e) { 388 usefulWorkStatsFile = null; 389 } 390 312 391 basicResStats = gatherPEStats(jr.getTasks()); 313 392 peStatsPostProcessing(basicResStats); … … 318 397 } 319 398 320 for(String resourceName: resourceController.getComputingResourceLayers()){ 321 List<ComputingResource> resources = null; 322 323 resources = new ArrayList<ComputingResource>(); 399 List<ComputingResource> compResources = null; 400 for(String resourceTypeName: resourceController.getComputingResourceLayers()){ 401 GSSAccumulator resourceEnergyAccumulator = new GSSAccumulator(); 402 GSSAccumulator maxResourceEnergyAccumulator = new GSSAccumulator(); 403 GSSAccumulator calculationsEnergyAccumulator = new GSSAccumulator(); 404 compResources = new ArrayList<ComputingResource>(); 324 405 for(ComputingResource compRes: resourceController.getComputingResources() ){ 325 resources.addAll(compRes.getDescendantsByType(new UserResourceType(resourceName))); 326 } 327 if(resourceController.getComputingResources().get(0).getType().getName().equals(resourceName)) 328 resources.addAll(resourceController.getComputingResources()); 329 330 if(type_stats.containsKey(resourceName)){ 331 for(ComputingResource resource: resources){ 406 compResources.addAll(compRes.getDescendantsByType(new UserResourceType(resourceTypeName))); 407 } 408 if(resourceController.getComputingResources().get(0).getType().getName().equals(resourceTypeName)) 409 compResources.addAll(resourceController.getComputingResources()); 410 if(type_stats.containsKey(resourceTypeName)){ 411 412 413 for(ComputingResource compResource: compResources){ 332 414 ResourceUsageStats resourceUsage = null; 333 415 ResourcePowerStats energyUsage = null; 334 416 ResourceAirFlowStats airFlow = null; 335 417 ResourceTemperatureStats temperature = null; 336 if(type_stats.get(resourceName).contains(Stats.textLoad)){ 337 resourceUsage = gatherResourceLoadStats(resource, basicResStats); 418 ResourceUsefulWorkStats usefulWork = null; 419 if(type_stats.get(resourceTypeName).contains(Stats.textLoad)){ 420 resourceUsage = gatherResourceLoadStats(compResource, basicResStats); 338 421 resourceUsage.setMeanValue(calculateMeanValue(resourceUsage)); 339 422 if (resourceLoadStatsFile != null) { … … 341 424 resourceLoadStatsFile.print(txt); 342 425 } 343 } 344 if(type_stats.get(resourceName).contains(Stats.chartLoad)){ 426 427 } 428 if(type_stats.get(resourceTypeName).contains(Stats.chartLoad)){ 345 429 if (configuration.creatediagrams_resutilization) { 346 430 createResourceLoadDiagram(resourceUsage); 347 431 } 348 432 } 349 if(type_stats.get(resource Name).contains(Stats.textEnergy)){350 energyUsage = gatherResourcePowerConsumptionStats( resource);433 if(type_stats.get(resourceTypeName).contains(Stats.textEnergy)){ 434 energyUsage = gatherResourcePowerConsumptionStats(compResource); 351 435 energyUsage.setMeanValue(calculateMeanValue(energyUsage)); 352 436 energyUsage.setSumValue(energyUsage.getMeanValue() * (endSimulationTime - startSimulationTime) / (3600 * MILLI_SEC)); 353 354 EnergyExtension een = (EnergyExtension)(resource.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); 355 if(resourceController.getComputingResources().contains(resource)) { 437 resourceEnergyAccumulator.add(energyUsage.getSumValue()); 438 maxResourceEnergyAccumulator.add(calculateMaxValue(energyUsage)); 439 double calulcationsEnergy = 0; 440 try { 441 /*boolean doCalc = false; 442 double prevTimestamp = 0; 443 for(Long key: resourceUsage.getHistory().keySet()){ 444 if(doCalc){ 445 System.out.println(energyUsage.getHistory().get(key)); 446 calulcationsEnergy = calulcationsEnergy + energyUsage.getHistory().get(prevTimestamp) * (key - prevTimestamp) /(3600 * MILLI_SEC); 447 doCalc = false; 448 } 449 if(resourceUsage.getHistory().get(key)>0){ 450 prevTimestamp = key; 451 doCalc = true; 452 } 453 }*/ 454 boolean doCalc = false; 455 long prevTimestamp = 0; 456 for(Long key: energyUsage.getHistory().keySet()){ 457 if(doCalc){ 458 double load = 0; 459 if(resourceUsage.getHistory().get(prevTimestamp)!= null){ 460 load = resourceUsage.getHistory().get(prevTimestamp); 461 } 462 calulcationsEnergy = calulcationsEnergy + load * energyUsage.getHistory().get(prevTimestamp) * (key - prevTimestamp) /(3600.0 * MILLI_SEC); 463 doCalc = false; 464 } 465 if(energyUsage.getHistory().get(key) > compResource.getPowerInterface().getSupportedPowerStates().get(0).getPowerUsage() - CoolEmAllTestbedMeasurements.SINGLE_FAN_ON_POWER_CONSUMPTION){ 466 467 prevTimestamp = key; 468 doCalc = true; 469 } 470 } 471 //calulcationsEnergy = energyUsage.getSumValue() - 472 // ((1 - resourceUsage.getMeanValue()) * (endSimulationTime - startSimulationTime) / (3600 * MILLI_SEC)) * 473 // (compResource.getPowerInterface().getSupportedPowerStates().get(0).getPowerUsage() - CoolEmAllTestbedMeasurements.SINGLE_FAN_ON_POWER_CONSUMPTION); 474 //System.out.println(compResource.getFullName() + ";" + resourceUsage.getMeanValue() +":"+ calulcationsEnergy + ":" + energyUsage.getSumValue()); 475 calculationsEnergyAccumulator.add(calulcationsEnergy); 476 } catch (Exception e) { 477 e.printStackTrace(); 478 } 479 EnergyExtension een = (EnergyExtension)(compResource.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); 480 if(resourceController.getComputingResources().contains(compResource)) { 356 481 if( een != null && een.getPowerProfile() != null && een.getPowerProfile().getEnergyEstimationPlugin() != null){ 357 482 accStats.meanEnergyUsage.add(energyUsage.getSumValue()); … … 359 484 360 485 } else if( een != null && een.getPowerProfile() != null && een.getPowerProfile().getEnergyEstimationPlugin() != null){ 361 ComputingResource parent = resource.getParent();486 ComputingResource parent = compResource.getParent(); 362 487 boolean top = true; 363 488 while(parent != null){ … … 377 502 energyStatsFile.print(txt); 378 503 } 379 } 380 if(type_stats.get(resourceName).contains(Stats.chartEnergy)){ 381 504 505 for(Device device: compResource.getResourceCharacteristic().getDevices()){ 506 GSSAccumulator devAccumulator = new GSSAccumulator(); 507 ResourcePowerStats deviceEnergyUsage = gatherResourcePowerConsumptionStats(device); 508 deviceEnergyUsage.setMeanValue(calculateMeanValue(deviceEnergyUsage)); 509 deviceEnergyUsage.setSumValue(deviceEnergyUsage.getMeanValue() * (endSimulationTime - startSimulationTime) / (3600 * MILLI_SEC)); 510 devAccumulator.add(deviceEnergyUsage.getSumValue()); 511 metCalc.addMetricsData(device.getType().getName(), devAccumulator); 512 if (deviceStatsFile != null) { 513 Object txt = deviceEnergyUsage.serialize(serializer); 514 deviceStatsFile.print(txt); 515 } 516 517 if(ArrayUtils.contains(configuration.resForEnergyChart, device.getType().getName())){ 518 if (configuration.creatediagrams_respowerusage) { 519 createResourceEnergyDiagramData(deviceEnergyUsage); 520 } 521 } 522 } 523 } 524 if(type_stats.get(resourceTypeName).contains(Stats.chartEnergy)){ 382 525 if (configuration.creatediagrams_respowerusage) { 383 526 createResourceEnergyDiagramData(energyUsage); … … 385 528 } 386 529 387 if(type_stats.get(resource Name).contains(Stats.textAirFlow)){388 airFlow = gatherResourceAirFlowStats( resource);530 if(type_stats.get(resourceTypeName).contains(Stats.textAirFlow)){ 531 airFlow = gatherResourceAirFlowStats(compResource); 389 532 airFlow.setMeanValue(calculateMeanValue(airFlow)); 390 533 airFlow.setSumValue(airFlow.getMeanValue() * (endSimulationTime - startSimulationTime) / (60 * MILLI_SEC)); 391 534 392 EnergyExtension een = (EnergyExtension)( resource.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION));393 if(resourceController.getComputingResources().contains( resource)) {535 EnergyExtension een = (EnergyExtension)(compResource.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); 536 if(resourceController.getComputingResources().contains(compResource)) { 394 537 if( een != null && een.getAirFlowProfile() != null && een.getPowerProfile().getEnergyEstimationPlugin() != null){ 395 538 accStats.meanAirFlow.add(airFlow.getMeanValue()); … … 397 540 398 541 } else if( een != null && een.getAirFlowProfile() != null ){ 399 ComputingResource parent = resource.getParent();542 ComputingResource parent = compResource.getParent(); 400 543 een = (EnergyExtension)(parent.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); 401 544 boolean top = true; … … 415 558 airFlowStatsFile.print(txt); 416 559 } 417 } 418 if(type_stats.get(resourceName).contains(Stats.chartAirFlow)){ 560 561 for(Device device: compResource.getResourceCharacteristic().getDevices()){ 562 ResourceAirFlowStats deviceAirFlow = gatherResourceAirFlowStats(device); 563 deviceAirFlow.setMeanValue(calculateMeanValue(deviceAirFlow)); 564 deviceAirFlow.setSumValue(deviceAirFlow.getMeanValue() * (endSimulationTime - startSimulationTime) / (60 * MILLI_SEC)); 565 566 if (deviceStatsFile != null) { 567 Object txt = deviceAirFlow.serialize(serializer); 568 deviceStatsFile.print(txt); 569 } 570 571 if(ArrayUtils.contains(configuration.resForAirFlowChart, device.getType().getName())){ 572 if (configuration.creatediagrams_resairflow) { 573 createResourceAirFlowDiagramData(deviceAirFlow); 574 } 575 } 576 } 577 } 578 if(type_stats.get(resourceTypeName).contains(Stats.chartAirFlow)){ 419 579 420 580 if (configuration.creatediagrams_resairflow) { … … 423 583 } 424 584 425 if(type_stats.get(resource Name).contains(Stats.textTemperature)){426 temperature = gatherResourceTemperatureStats( resource);585 if(type_stats.get(resourceTypeName).contains(Stats.textTemperature)){ 586 temperature = gatherResourceTemperatureStats(compResource); 427 587 temperature.setMeanValue(calculateMeanValue(temperature)); 428 588 temperature.setSumValue(temperature.getMeanValue() * (endSimulationTime - startSimulationTime) / (3600 * MILLI_SEC)); 429 589 430 EnergyExtension een = (EnergyExtension)( resource.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION));431 if(resourceController.getComputingResources().contains( resource)) {590 EnergyExtension een = (EnergyExtension)(compResource.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); 591 if(resourceController.getComputingResources().contains(compResource)) { 432 592 if( een != null && een.getThermalProfile() != null && een.getPowerProfile().getEnergyEstimationPlugin() != null){ 433 593 accStats.meanTemperature.add(temperature.getMeanValue()); … … 435 595 436 596 } else if( een != null && een.getThermalProfile() != null ){ 437 ComputingResource parent = resource.getParent();597 ComputingResource parent = compResource.getParent(); 438 598 een = (EnergyExtension)(parent.getExtensionList().getExtension(ExtensionType.ENERGY_EXTENSION)); 439 599 boolean top = true; … … 453 613 temperatureStatsFile.print(txt); 454 614 } 455 } 456 if(type_stats.get(resourceName).contains(Stats.chartTemperature)){ 457 615 616 for(Device device: compResource.getResourceCharacteristic().getDevices()){ 617 ResourceTemperatureStats deviceTemperature = gatherResourceTemperatureStats(device); 618 deviceTemperature.setMeanValue(calculateMeanValue(deviceTemperature)); 619 deviceTemperature.setSumValue(deviceTemperature.getMeanValue() * (endSimulationTime - startSimulationTime) / (3600 * MILLI_SEC)); 620 621 if (deviceStatsFile != null) { 622 Object txt = deviceTemperature.serialize(serializer); 623 deviceStatsFile.print(txt); 624 } 625 626 if(ArrayUtils.contains(configuration.resForTemperatureChart, device.getType().getName())){ 627 if (configuration.creatediagrams_restemperature) { 628 createResourceTemperatureDiagramData(deviceTemperature); 629 } 630 } 631 } 632 } 633 if(type_stats.get(resourceTypeName).contains(Stats.chartTemperature)){ 458 634 if (configuration.creatediagrams_restemperature) { 459 635 createResourceTemperatureDiagramData(temperature); 460 636 } 461 637 } 638 639 if(type_stats.get(resourceTypeName).contains(Stats.textLoad)){ 640 usefulWork = gatherResourceUsefulWorkStats(compResource); 641 if (usefulWorkStatsFile != null) { 642 Object txt = usefulWork.serialize(serializer); 643 usefulWorkStatsFile.print(txt); 644 } 645 } 646 647 648 if (nodesAvailabilityStatsFile != null) { 649 ResourceAvailabilityStats ras = new ResourceAvailabilityStats(compResource.getFullName(), compResource.getType(), "availableNodes", compResource.getChildren().size(), endSimulationTime); 650 Object txt = ras.serialize(serializer); 651 nodesAvailabilityStatsFile.print(txt); 652 ras = gatherResourceAvailabilityStats(compResource); 653 txt = ras.serialize(serializer); 654 nodesAvailabilityStatsFile.print(txt); 655 } 656 462 657 } 463 } 464 } 465 658 metCalc.addMetricsData(resourceTypeName + "_CALC", calculationsEnergyAccumulator); 659 metCalc.addMetricsData(resourceTypeName, resourceEnergyAccumulator); 660 metCalc.addMetricsData(resourceTypeName + "_MAX", maxResourceEnergyAccumulator); 661 } 662 } 663 664 665 if (metricsStatsFile != null) { 666 //log.info("#STATS " + "Metrics"); 667 System.out.println("#STATS " + "===== Metrics ====="); 668 for(MetricsStats metric: metCalc.calulateMetrics(endSimulationTime)){ 669 Object txt = metric.serialize(serializer); 670 //log.info("#STATS " + metric.getResourceName() + " " + metric.getMetricName() + ": " + metric.getValue()); 671 DecimalFormat df = new DecimalFormat(); 672 df.setMaximumFractionDigits(3); 673 df.setGroupingUsed(false); 674 System.out.println("#STATS " + metric.getMetricName().replaceAll("_", " ") + ": " + df.format(metric.getValue()) + " [" + metric.getUnit() + "]"); 675 metricsStatsFile.println(txt); 676 } 677 } 466 678 saveResourceUsageDiagrams(); 467 679 createAccumulatedResourceSimulationStatistic(); … … 479 691 resourceLoadStatsFile.close(); 480 692 } 693 694 if (usefulWorkStatsFile != null) { 695 usefulWorkStatsFile.close(); 696 } 697 if (deviceStatsFile != null) { 698 deviceStatsFile.close(); 699 } 700 701 if (nodesAvailabilityStatsFile != null) { 702 nodesAvailabilityStatsFile.close(); 703 } 704 705 if (metricsStatsFile != null) { 706 metricsStatsFile.close(); 707 } 708 481 709 } 482 710 … … 500 728 } 501 729 for(ComputingResource resource: resources){ 502 if(!basicResStats.containsKey(resource.get Name())){503 basicResStats.put(resource.get Name(), new ArrayList<ResStat>());730 if(!basicResStats.containsKey(resource.getFullName())){ 731 basicResStats.put(resource.getFullName(), new ArrayList<ResStat>()); 504 732 } 505 733 } … … 509 737 510 738 Map<String, List<ResStat>> basicResStats = new TreeMap<String, List<ResStat>>(new MapPEIdComparator()); 511 512 739 for (ExecTask execTask:executables) { 513 740 Executable exec = (Executable) execTask; … … 522 749 ProcessingElements pes = (ProcessingElements) resUnit; 523 750 for(ComputingResource pe: pes){ 524 String peName = pe.get Name();751 String peName = pe.getFullName(); 525 752 long startDate = Double.valueOf(exec.getExecStartTime()).longValue() * MILLI_SEC; 526 753 long endDate = Double.valueOf(exec.getFinishTime()).longValue() * MILLI_SEC; … … 541 768 String uniqueTaskID = getUniqueTaskId(execTask); 542 769 543 List<String> peNames = task_processorsMap.get(uniqueTaskID);770 Set<ComputingResource> peNames = task_processorsMap.get(uniqueTaskID); 544 771 if (peNames == null) { 545 peNames = new ArrayList<String>();546 peNames.add(pe Name);772 peNames = new HashSet<ComputingResource>(); 773 peNames.add(pe); 547 774 task_processorsMap.put(uniqueTaskID, peNames); 548 775 } else { 549 peNames.add(peName); 550 } 776 peNames.add(pe); 777 } 778 779 try{ 780 double usefulWork = execTask.getResourceConsumptionProfile().getUsefulWork(); 781 //double usefulWork = gatherUsefulWorkStats(pe).getValue(); 782 GSSAccumulator uwAcc; 783 if(metCalc.getMetricsData().containsKey(pe.getFullName())){ 784 uwAcc = metCalc.getMetricsData().get(pe.getFullName()).get(0); 785 uwAcc.add(usefulWork); 786 } else { 787 uwAcc = new GSSAccumulator(); 788 uwAcc.add(usefulWork); 789 metCalc.addMetricsData(pe.getFullName(), uwAcc); 790 } 791 } catch (Exception e){ 792 793 } 794 551 795 } 552 } else if (resUnit instanceof PEUnit){ 553 PEUnit peUnit = (PEUnit) resUnit; 554 } 555 796 } 556 797 } 557 798 return basicResStats; … … 571 812 } 572 813 814 573 815 private ResourceUsageStats gatherResourceLoadStats(ComputingResource resource, Map<String, List<ResStat>> basicStats) { 574 ResourceUsageStats usageStats = new ResourceUsageStats(resource.getFullName(), resource.getType(), "resourceLoadStats"); 816 String usageType = null; 817 if(resource.getResourceCharacteristic().getParameters().get("load-sensor")!= null){ 818 usageType = resource.getResourceCharacteristic().getParameters().get("load-sensor").get(0).getContent(); 819 } 820 ResourceUsageStats usageStats = new ResourceUsageStats(resource.getFullName(), resource.getType(), usageType); 575 821 int cnt = 0; 576 822 for(String resName: basicStats.keySet()){ 577 823 try { 578 if(resource.getDescendantByName(resName) != null || resource.get Name().compareTo(resName) == 0){824 if(resource.getDescendantByName(resName) != null || resource.getFullName().compareTo(resName) == 0){ 579 825 createResourceLoadData(usageStats, basicStats.get(resName)); 580 826 cnt++; … … 591 837 592 838 return usageStats; 839 } 840 841 private ResourceAvailabilityStats gatherResourceAvailabilityStats(ComputingResource resource) { 842 String usageType = new String ("usedNodes"); 843 844 int usedResources = 0; 845 for(ComputingResource compResource: resource.getChildren()){ 846 double meanLoad = calculateMeanValue(gatherResourceLoadStats(compResource, basicResStats)); 847 if(meanLoad > 0){ 848 usedResources++; 849 } 850 } 851 ResourceAvailabilityStats availabilityStats = new ResourceAvailabilityStats(resource.getFullName(), resource.getType(), usageType, usedResources, endSimulationTime); 852 return availabilityStats; 853 } 854 855 private ResourceUsefulWorkStats gatherResourceUsefulWorkStats(ComputingResource compResource) { 856 String usageType = "usefulWork"; 857 double usefulWork = 0; 858 JobRegistry jr = new JobRegistryImpl(compResource.getFullName()); 859 for(ExecTask task: jr.getFinishedTasks()){ 860 usefulWork = usefulWork + task.getResourceConsumptionProfile().getUsefulWork(); 861 } 862 ResourceUsefulWorkStats usefulWorkStats = new ResourceUsefulWorkStats(compResource.getFullName(), compResource.getType(), usageType, usefulWork, endSimulationTime); 863 return usefulWorkStats; 593 864 } 594 865 … … 629 900 } 630 901 } 631 902 if(ganttData.get(startSimulationTime) == null) 903 ganttData.put(startSimulationTime, 0.0); 904 if(ganttData.get(endSimulationTime) == null) 905 ganttData.put(endSimulationTime, 0.0); 632 906 return ganttData; 633 907 } … … 643 917 644 918 645 private ResourcePowerStats gatherResourcePowerConsumptionStats( ComputingResource resource) {919 private ResourcePowerStats gatherResourcePowerConsumptionStats(PhysicalResource resource) { 646 920 double power = 0; 647 ResourcePowerStats resEnergyUsage = new ResourcePowerStats(resource.getFullName(), resource.getType(), "resourcePowerConsumptionStats"); 921 922 String usageType = null; 923 if(resource.getResourceCharacteristic().getParameters().get("power-sensor")!= null){ 924 usageType = resource.getResourceCharacteristic().getParameters().get("power-sensor").get(0).getContent(); 925 } 926 ResourcePowerStats resEnergyUsage = new ResourcePowerStats(resource.getFullName(), resource.getType(), usageType); 648 927 Map<Long, Double> usage = resEnergyUsage.getHistory(); 649 928 … … 665 944 usage.put(pu.getTimestamp(), pu.getValue()); 666 945 667 /// System.out.println(resource.getName() + ":"+new DateTime(pu.getTimestamp())+";"+pu.getValue());668 946 power = power + (pu.getTimestamp() - lastTime) * lastPower/ (3600 * MILLI_SEC); 669 947 lastPower = pu.getValue(); … … 673 951 } 674 952 } 675 //System.out.println(power);676 953 return resEnergyUsage; 677 954 } 678 955 679 956 680 private ResourceAirFlowStats gatherResourceAirFlowStats(ComputingResource resource) { 681 682 ResourceAirFlowStats resAirFlow = new ResourceAirFlowStats(resource.getFullName(), resource.getType(), "resourceAirFlowStats"); 957 private ResourceAirFlowStats gatherResourceAirFlowStats(PhysicalResource resource) { 958 959 String usageType = null; 960 if(resource.getResourceCharacteristic().getParameters().get("airflow_volume-sensor")!= null){ 961 usageType = resource.getResourceCharacteristic().getParameters().get("airflow_volume-sensor").get(0).getContent(); 962 } 963 ResourceAirFlowStats resAirFlow = new ResourceAirFlowStats(resource.getFullName(), resource.getType(), usageType); 683 964 Map<Long, Double> airFlow = resAirFlow.getHistory(); 684 965 … … 704 985 } 705 986 706 private ResourceTemperatureStats gatherResourceTemperatureStats(ComputingResource resource) { 707 708 ResourceTemperatureStats resTemperature = new ResourceTemperatureStats(resource.getFullName(), resource.getType(), "resourceTemperatureStats"); 987 private ResourceTemperatureStats gatherResourceTemperatureStats(PhysicalResource resource) { 988 989 String usageType = null; 990 if(resource.getResourceCharacteristic().getParameters().get("temperature-sensor")!= null){ 991 usageType = resource.getResourceCharacteristic().getParameters().get("temperature-sensor").get(0).getContent(); 992 } 993 ResourceTemperatureStats resTemperature = new ResourceTemperatureStats(resource.getFullName(), resource.getType(), usageType); 709 994 Map<Long, Double> temperature = resTemperature.getHistory(); 710 995 … … 1065 1350 1066 1351 try { 1067 if(resource.getDescendantByName(resName) != null || resource.get Name().compareTo(resName) == 0){1352 if(resource.getDescendantByName(resName) != null || resource.getFullName().compareTo(resName) == 0){ 1068 1353 Double load = peLoad.get(resName); 1069 1354 sum += load; … … 1102 1387 1103 1388 1104 1105 1106 1389 private double calculateMaxValue(ResourceDynamicStats resDynamicStats ){ 1390 double maxValue = 0; 1391 1392 Map<Long, Double> history = resDynamicStats.getHistory(); 1393 for (Long key : history.keySet()) { 1394 if(history.get(key) > maxValue){ 1395 maxValue = history.get(key) ; 1396 } 1397 } 1398 return maxValue; 1399 } 1107 1400 1108 1401 … … 1221 1514 TaskStats taskStats = new TaskStats(task, startSimulationTime); 1222 1515 String uniqueTaskID = getUniqueTaskId(task); 1223 taskStats.setProcessors Name(task_processorsMap.get(uniqueTaskID));1516 taskStats.setProcessors(task_processorsMap.get(uniqueTaskID)); 1224 1517 return taskStats; 1225 1518 } … … 1484 1777 1485 1778 public int compare(String o1, String o2) { 1486 Integer o1int ;1487 Integer o2int ;1779 Integer o1int = 0; 1780 Integer o2int = 0; 1488 1781 String o1string; 1489 String o2string; 1490 o1string = o1.substring(0, o1.indexOf("_")); 1491 o2string = o2.substring(0, o2.indexOf("_")); 1492 o1int = Integer.parseInt(o1.substring(o1.indexOf("_")+1)); 1493 o2int = Integer.parseInt(o2.substring(o2.indexOf("_")+1)); 1494 //if(o1string.compareTo(o2string) != 0) 1495 // return o1string.compareTo(o2string); 1496 //else 1782 String o2string = null; 1783 1784 if(o1.contains("_")){ 1785 o1string = o1.substring(0, o1.lastIndexOf("_")); 1786 o1int = Integer.parseInt(o1.substring(o1.lastIndexOf("_")+1)); 1787 } else { 1788 o1string = o1; 1789 } 1790 1791 if(o2.contains("_")){ 1792 o2string = o2.substring(0, o2.lastIndexOf("_")); 1793 o2int = Integer.parseInt(o2.substring(o2.lastIndexOf("_")+1)); 1794 }else { 1795 o2string = o2; 1796 } 1797 1798 if(o1int.compareTo(o2int) != 0) 1497 1799 return o1int.compareTo(o2int); 1800 else 1801 return o1string.compareTo(o2string); 1498 1802 } 1499 1803 } … … 1573 1877 chartAirFlow, 1574 1878 textTemperature, 1575 chartTemperature; 1879 chartTemperature, 1880 textUsefulWorl; 1576 1881 }
Note: See TracChangeset
for help on using the changeset viewer.