User Manual, Developers Guide and API Documentation

BottleNeckDetective.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 5, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #include <WNS/ldk/tools/BottleNeckDetective.hpp>
00029 
00030 using namespace wns::ldk;
00031 using namespace wns::ldk::tools;
00032 
00033 STATIC_FACTORY_REGISTER_WITH_CREATOR(
00034     BottleNeckDetective,
00035     FunctionalUnit,
00036     "wns.ldk.tools.BottleNeckDetective",
00037     FUNConfigCreator);
00038 
00039 BottleNeckDetectiveCommand::BottleNeckDetectiveCommand() :
00040     Command()
00041 {
00042     magic.sender = NULL;
00043     magic.id = -1;
00044 } // BottleNeckDetectiveCommand
00045 
00046 BottleNeckDetectiveCommand::~BottleNeckDetectiveCommand()
00047 {
00048     magic.sender = NULL;
00049     magic.id = -1;
00050 } // ~BottleNeckDetectiveCommand
00051 
00052 BottleNeckDetective::BottleNeckDetective(fun::FUN* fuNet, const wns::pyconfig::View& config) :
00053     Processor<BottleNeckDetective>(),
00054     CommandTypeSpecifier<BottleNeckDetectiveCommand>(fuNet),
00055     HasReceptor<>(),
00056     HasConnector<>(),
00057     HasDeliverer<>(),
00058     Cloneable<BottleNeckDetective>(),
00059     PeriodicTimeout(),
00060     id(0),
00061     compounds(),
00062     logger(config.get("logger"))
00063 {
00064     MESSAGE_BEGIN(NORMAL, logger, m, "Setting periodic timeout to: ");
00065 
00066     m << config.get<simTimeType>("observationInterval") << " (observation interval), ";
00067     m << config.get<simTimeType>("offset") << " (offset)";
00068 
00069     this->startPeriodicTimeout(
00070         config.get<simTimeType>("observationInterval"),
00071         config.get<simTimeType>("offset"));
00072 
00073     MESSAGE_END();
00074 } // BottleNeckDetective
00075 
00076 
00077 BottleNeckDetective::~BottleNeckDetective()
00078 {
00079     MESSAGE_BEGIN(NORMAL, logger, m, "Canceling periodic timeout: ");
00080     this->cancelPeriodicTimeout();
00081     MESSAGE_END();
00082 
00083     compounds.clear();
00084 } // ~BottleNeckDetective
00085 
00086 
00087 #ifndef WNS_NO_LOGGING
00088 void
00089 BottleNeckDetective::processOutgoing(const CompoundPtr& compound)
00090 {
00091     BottleNeckDetectiveCommand* bndc = this->activateCommand(compound->getCommandPool());
00092     bndc->magic.sender = this;
00093     bndc->magic.id = ++this->id;
00094     compounds[id] = compound;
00095 } // processOutgoing
00096 #else
00097 void
00098 BottleNeckDetective::processOutgoing(const CompoundPtr&)
00099 {
00100 } // processOutgoing
00101 #endif // WNS_NO_LOGGING
00102 
00103 
00104 #ifndef WNS_NO_LOGGING
00105 void
00106 BottleNeckDetective::processIncoming(const CompoundPtr& compound)
00107 {
00108     long long int id = this->getCommand(compound->getCommandPool())->magic.id;
00109     BottleNeckDetective* sender = this->getCommand(compound->getCommandPool())->magic.sender;
00110     // remove this compound from sender, it's no longer in the FUN
00111     sender->compounds.erase(id);
00112 } // processOutgoing
00113 #else
00114 void
00115 BottleNeckDetective::processIncoming(const CompoundPtr&)
00116 {
00117 } // processOutgoing
00118 #endif //WNS_NO_LOGGING
00119 
00120 void
00121 BottleNeckDetective::periodically()
00122 {
00123     MESSAGE_BEGIN(NORMAL, logger, m, "Current compound distribution in FUN:\n");
00124     std::map<std::string, int> countCompounds;
00125     // create map and show highscore:
00126     for(CompoundContainer::const_iterator itr = compounds.begin();
00127         itr != compounds.end();
00128         ++itr)
00129     {
00130         if(itr->second->getJourney().size() > 0)
00131         {
00132             Visit v = *(itr->second->getJourney().rbegin());
00133             if(countCompounds.find(v.location) != countCompounds.end())
00134             {
00135                 countCompounds[v.location]++;
00136             }
00137             else
00138             {
00139                 countCompounds[v.location] = 0;
00140             }
00141         }
00142     }
00143 
00144     std::multimap<int, std::string> countCompoundsSorted;
00145     for(std::map<std::string, int>::const_iterator itr = countCompounds.begin();
00146         itr != countCompounds.end();
00147         ++itr)
00148     {
00149         countCompoundsSorted.insert(std::pair<int, std::string>(itr->second, itr->first));
00150     }
00151 
00152     for(std::multimap<int, std::string>::const_iterator itr = countCompoundsSorted.begin();
00153         itr != countCompoundsSorted.end();
00154         ++itr)
00155     {
00156         m << "Location: " <<  itr->second << ", Compounds: " << itr->first << "\n";
00157     }
00158     m << "End of compound distribution list";
00159     MESSAGE_END();
00160 
00161     // start counting again
00162     compounds.clear();
00163 }
00164 
00165 
00166 
00167 
00168 

Generated on Mon May 21 03:31:50 2012 for openWNS by  doxygen 1.5.5