ProfileManager.h

Go to the documentation of this file.
00001 /****************** <VPR heading BEGIN do not edit this line> *****************
00002  *
00003  * VR Juggler Portable Runtime
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Patrick Hartling, Kevin Meinert, Carolina Cruz-Neira
00007  *
00008  * -----------------------------------------------------------------
00009  * File:          $RCSfile$
00010  * Date modified: $Date: 2005-05-16 15:13:18 -0500 (Mon, 16 May 2005) $
00011  * Version:       $Revision: 17502 $
00012  * -----------------------------------------------------------------
00013  *
00014  ****************** <VPR heading END do not edit this line> ******************/
00015 
00016 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00017  *
00018  * VR Juggler is (C) Copyright 1998-2005 by Iowa State University
00019  *
00020  * Original Authors:
00021  *   Allen Bierbaum, Christopher Just,
00022  *   Patrick Hartling, Kevin Meinert,
00023  *   Carolina Cruz-Neira, Albert Baker
00024  *
00025  * This library is free software; you can redistribute it and/or
00026  * modify it under the terms of the GNU Library General Public
00027  * License as published by the Free Software Foundation; either
00028  * version 2 of the License, or (at your option) any later version.
00029  *
00030  * This library is distributed in the hope that it will be useful,
00031  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00032  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00033  * Library General Public License for more details.
00034  *
00035  * You should have received a copy of the GNU Library General Public
00036  * License along with this library; if not, write to the
00037  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00038  * Boston, MA 02111-1307, USA.
00039  *
00040  *************** <auto-copyright.pl END do not edit this line> ***************/
00041 
00042 #ifndef VPR_PROFILE_MANAGER_H
00043 #define VPR_PROFILE_MANAGER_H
00044 
00053 #include <vpr/vprConfig.h>
00054 
00055 #include <string>
00056 #include <vector>
00057 #include <map>
00058 #include <sstream>
00059 
00060 #include <vpr/Sync/Guard.h>
00061 #include <vpr/Sync/Mutex.h>
00062 
00063 #include <vpr/Perf/ProfileIterator.h>
00064 #include <vpr/Perf/ProfileNode.h>
00065 
00066 #include <vpr/Thread/TSObjectProxy.h>
00067 #include <vpr/Thread/Thread.h>
00068 
00069 namespace vpr
00070 {
00071 
00076    class VPR_CLASS_API ProfileManager
00077    {
00078    public:
00079       struct ThreadProfileData
00080       {
00081          ThreadProfileData()
00082             : mRoot("root")
00083          {
00084             mCurrentNode = &mRoot;
00085          }
00086 
00087          ProfileNode    mRoot;         
00088          ProfileNode*   mCurrentNode;  
00089          vpr::Interval  mResetTime;    
00090       };
00091 
00093       typedef std::map<std::string, vpr::Interval> ProfileSampleResult;
00094 
00109       static void startProfile(const char* profileName,
00110                                const unsigned int queueSize = 0);
00111 
00115       static void stopProfile();
00117 
00124       static ProfileNode* getRootNode(vpr::Thread* thread = NULL);
00125 
00127       static void printTree(bool forAllThreads = true);
00128 
00132       static ProfileIterator begin()
00133       {
00134          return ProfileIterator(getRootNode());
00135       }
00136 
00138       static ProfileIterator end()
00139       {
00140          return ProfileIterator(NULL);
00141       }
00142 
00144       static void releaseIterator(ProfileIterator* iterator)
00145       {
00146          delete iterator;
00147       }
00149 
00157       static void reset();
00158 
00162       static float getTimeSinceReset();
00164 
00165    public:
00173       static std::vector<std::string> getNames()
00174       {
00175          std::vector<std::string> names_list;
00176          getNamesRecursively(names_list, getRootNode());
00177          return names_list;
00178       }
00179 
00184       static ProfileSampleResult getSampleResult()
00185       {
00186          ProfileSampleResult sample_time_map;
00187          std::vector<Thread*>::size_type num_threads =
00188             vpr::ThreadManager::instance()->getNumThreads();
00189          for ( std::vector<Thread*>::size_type t = 0; t < num_threads; ++t )
00190          {
00191             vpr::Thread* thread = vpr::ThreadManager::instance()->getThread(t);
00192             getSampleResultRecursively(sample_time_map, getRootNode(thread));
00193          }
00194          return sample_time_map;
00195       }
00196 
00200        static float getNamedNodeSample( const char * nodeName )
00201        {
00202            ProfileNode* node = getRootNode()->getNamedChild( nodeName );
00203 
00204            if(node == NULL )
00205            {
00206               return 0.0;
00207            }
00208            else
00209            {
00210               return node->getLastSample().msecf();
00211            }
00212        }
00214 
00215    private:
00216       static TSObjectProxy<ThreadProfileData>  mThreadData;    
00218       // Private Member Functions
00219       static void getNamesRecursively( std::vector<std::string>& nameList,
00220                                        ProfileNode* node )
00221       {
00222          if ( NULL == node )
00223          {
00224             return;
00225          }
00226 
00227          getNamesRecursively(nameList, node->getSibling());
00228          nameList.push_back(node->getName());
00229          getNamesRecursively(nameList, node->getChild());
00230        }
00231 
00232       static void getSampleResultRecursively( ProfileSampleResult& sampleTimeMap,
00233                                           ProfileNode* node )
00234       {
00235          if ( NULL == node )
00236          {
00237             return;
00238          }
00239 
00240          getSampleResultRecursively(sampleTimeMap, node->getSibling());
00241          vpr::Interval last_sample;
00242          last_sample.msecf( node->getNodeHistoryRange().first->msecf());
00243          std::string name = node->getName();
00244          sampleTimeMap[name] = last_sample;
00245          getSampleResultRecursively(sampleTimeMap, node->getChild());
00246       }
00247    };
00248 
00249 
00253 namespace prof
00254 {
00255 #if defined(DISABLE_VPR_PROFILE)
00256    inline void start(const char* name) {;}
00257    inline void start(const char* name, unsigned int histSize) {;}
00258    inline void next(const char* name) {;}
00259    inline void next(const char* name, unsigned int histSize) {;}
00260    inline void stop() {;}
00261    inline void printTree() {;}
00262 #else
00263 
00264    inline void start(const char* name)
00265    {
00266       vpr::ProfileManager::startProfile(name);
00267    }
00269    inline void start(const char* name, unsigned int histSize)
00270    {
00271       vpr::ProfileManager::startProfile(name,histSize);
00272    }
00274    inline void next(const char* name)
00275    {
00276       vpr::ProfileManager::stopProfile();
00277       vpr::ProfileManager::startProfile(name);
00278    }
00280    inline void next(const char* name, unsigned int histSize)
00281    {
00282       vpr::ProfileManager::stopProfile();
00283       vpr::ProfileManager::startProfile(name,histSize);
00284    }
00286    inline void stop()
00287    {
00288       vpr::ProfileManager::stopProfile();
00289    }
00291    inline void printTree()
00292    {
00293       vpr::ProfileManager::printTree();
00294    }
00295 #endif
00296 } // End prof namespace
00297 
00309    class ProfileSample
00310    {
00311    public:
00312       ProfileSample(const char * name)
00313       {
00314          ProfileManager::startProfile(name);
00315       }
00316 
00317       ProfileSample(const char * name, const unsigned int queue_size)
00318       {
00319          ProfileManager::startProfile(name, queue_size);
00320       }
00321 
00322       ~ProfileSample()
00323       {
00324          ProfileManager::stopProfile();
00325       }
00326    };
00327 
00328 
00329 #if defined(DISABLE_VPR_PROFILE)
00330 #define  VPR_PROFILE_GUARD( name )
00331 #else
00332 #define  VPR_PROFILE_GUARD( name )        vpr::ProfileSample __profile( name )
00333 #endif
00334 
00335 #if defined(DISABLE_VPR_PROFILE)
00336 #define  VPR_PROFILE_GUARD_HISTORY( name, queue_size )
00337 #else
00338 #define  VPR_PROFILE_GUARD_HISTORY( name, queue_size )         vpr::ProfileSample __profile( name, queue_size)
00339 #endif
00340 
00341 #if defined(DISABLE_VPR_PROFILE)
00342 #define  VPR_PROFILE_RESULTS( )
00343 #else
00344 #define  VPR_PROFILE_RESULTS( )        vpr::ProfileManager::printTree( )
00345 #endif
00346 
00347 } // end vpr namespace
00348 
00349 #endif

Generated on Thu Jan 4 10:52:10 2007 for VR Juggler Portable Runtime by  doxygen 1.5.1