Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename the property used by the energy plugin for clarity
[simgrid.git] / src / surf / plugins / energy.cpp
index 9799f52..6c55cf4 100644 (file)
@@ -1,17 +1,29 @@
+/* Copyright (c) 2010, 2012-2015. 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. */
+
 #include "energy.hpp"
 #include "../cpu_cas01.hpp"
 
+/** @addtogroup SURF_plugin_energy
+ *
+ *
+ *  This is the energy plugin, enabling to account not only for computation time, but also for the dissipated energy in the simulated platform.
+ */
+
 XBT_LOG_EXTERNAL_CATEGORY(surf_kernel);
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_energy, surf,
                                 "Logging specific to the SURF energy plugin");
 
 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());
@@ -19,7 +31,7 @@ static void deleteCpuCallback(CpuPtr cpu){
   surf_energy->erase(cpuIt);
 }
 
-static void updateActionEnergyCallback(CpuActionPtr action){
+static void energyCpuActionStateChangedCallback(CpuActionPtr action, e_surf_action_state_t old, e_surf_action_state_t cur){
   CpuPtr cpu  = getActionCpu(action);
   CpuEnergyPtr cpu_energy = (*surf_energy)[cpu];
 
@@ -42,16 +54,29 @@ static void updateActionEnergyCallback(CpuActionPtr action){
   }
 }
 
-/* init Energy plugin */
+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.
+ */
 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);
   }
 }
 
+/**
+ *
+ */
 CpuEnergy::CpuEnergy(CpuPtr ptr)
  : cpu(ptr)
 {
@@ -87,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       */
@@ -119,7 +144,7 @@ xbt_dynar_t CpuEnergy::getWattsRangeList()
        if (cpu->getProperties() == NULL)
                return NULL;
 
-       char* all_power_values_str = (char*)xbt_dict_get_or_null(cpu->getProperties(), "power_per_state");
+       char* all_power_values_str = (char*)xbt_dict_get_or_null(cpu->getProperties(), "watt_per_state");
 
        if (all_power_values_str == NULL)
                return NULL;