X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/f1137465cab98cdaa8b0364e533fc82d9b7b0cdc..93a112bc3b5933cdc80d562bd637223ba4c26f60:/src/surf/plugins/energy.cpp diff --git a/src/surf/plugins/energy.cpp b/src/surf/plugins/energy.cpp index 9799f52c4f..993ac0b7ed 100644 --- a/src/surf/plugins/energy.cpp +++ b/src/surf/plugins/energy.cpp @@ -1,17 +1,29 @@ +/* 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. */ + #include "energy.hpp" #include "../cpu_cas01.hpp" +/** @addtogroup SURF_plugin_energy + * + * + * BlaBla energy + */ + XBT_LOG_EXTERNAL_CATEGORY(surf_kernel); XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_energy, surf, "Logging specific to the SURF energy plugin"); std::map *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::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){ 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(); - 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(cpu)->m_pstate, xbt_dynar_t); + xbt_dynar_t current_power_values = xbt_dynar_get_as(power_range_list, static_cast(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 */