Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Clean surf cpu cas01
[simgrid.git] / src / surf / plugins / energy.cpp
index 8719d9c..993ac0b 100644 (file)
@@ -1,8 +1,8 @@
-/* Copyright (c) 2010, 2012-2013. The SimGrid Team.
+/* Copyright (c) 2010, 2012-2014. The SimGrid Team.
  * All rights reserved.                                                     */
 
 /* This program is free software; you can redistribute it and/or modify it
 * under the terms of the license (GNU LGPL) which comes with this package. */
+ * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "energy.hpp"
 #include "../cpu_cas01.hpp"
@@ -19,11 +19,11 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_energy, surf,
 
 std::map<CpuPtr, CpuEnergyPtr> *surf_energy=NULL;
 
-static void createCpuCallback(CpuPtr cpu){
+static void energyCpuCreatedCallback(CpuPtr cpu){
   (*surf_energy)[cpu] = new CpuEnergy(cpu);
 }
 
-static void deleteCpuCallback(CpuPtr cpu){
+static void energyCpuDestructedCallback(CpuPtr cpu){
   std::map<CpuPtr, CpuEnergyPtr>::iterator cpuIt = surf_energy->find(cpu);
   xbt_assert(cpuIt != surf_energy->end(), "The cpu is not in surf_energy.");
   XBT_INFO("Total energy (Joules) of host %s: %f", cpu->getName(), cpuIt->second->getConsumedEnergy());
@@ -31,7 +31,7 @@ static void deleteCpuCallback(CpuPtr cpu){
   surf_energy->erase(cpuIt);
 }
 
-static void updateActionEnergyCallback(CpuActionPtr action){
+static void energyCpuActionStateChangedCallback(CpuActionPtr action){
   CpuPtr cpu  = getActionCpu(action);
   CpuEnergyPtr cpu_energy = (*surf_energy)[cpu];
 
@@ -54,6 +54,12 @@ static void updateActionEnergyCallback(CpuActionPtr action){
   }
 }
 
+static void sg_energy_plugin_exit()
+{
+  delete surf_energy;
+  surf_energy = NULL;
+}
+
 /** \ingroup SURF_plugin_energy
  * \brief Enable energy plugin
  * \details Enable energy plugin to get joules consumption of each cpu.
@@ -61,9 +67,10 @@ static void updateActionEnergyCallback(CpuActionPtr action){
 void sg_energy_plugin_init() {
   if (surf_energy == NULL) {
     surf_energy = new std::map<CpuPtr, CpuEnergyPtr>();
-    surf_callback_connect(createCpuCallbacks, createCpuCallback);
-    surf_callback_connect(deleteCpuCallbacks, deleteCpuCallback);
-    surf_callback_connect(updateCpuActionCallbacks, updateActionEnergyCallback);
+    surf_callback_connect(cpuCreatedCallbacks, energyCpuCreatedCallback);
+    surf_callback_connect(cpuDestructedCallbacks, energyCpuDestructedCallback);
+    surf_callback_connect(cpuActionStateChangedCallbacks, energyCpuActionStateChangedCallback);
+    surf_callback_connect(surfExitCallbacks, sg_energy_plugin_exit);
   }
 }
 
@@ -105,7 +112,7 @@ double CpuEnergy::getCurrentWattsValue(double cpu_load)
                                                cpu->getName());*/
 
     /* retrieve the power values associated with the current pstate */
-    xbt_dynar_t current_power_values = xbt_dynar_get_as(power_range_list, static_cast<CpuCas01Ptr>(cpu)->m_pstate, xbt_dynar_t);
+    xbt_dynar_t current_power_values = xbt_dynar_get_as(power_range_list, static_cast<CpuCas01Ptr>(cpu)->getPState(), xbt_dynar_t);
 
     /* min_power corresponds to the idle power (cpu load = 0) */
     /* max_power is the power consumed at 100% cpu load       */