Blender V2.61 - r43446

KX_TimeCategoryLogger.cpp

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #include "KX_TimeCategoryLogger.h"
00034 
00035 KX_TimeCategoryLogger::KX_TimeCategoryLogger(unsigned int maxNumMeasurements)
00036 : m_maxNumMeasurements(maxNumMeasurements)
00037 {
00038 }
00039 
00040 
00041 KX_TimeCategoryLogger::~KX_TimeCategoryLogger(void)
00042 {
00043     DisposeLoggers();
00044 }
00045 
00046 
00047 void KX_TimeCategoryLogger::SetMaxNumMeasurements(unsigned int maxNumMeasurements)
00048 {
00049     KX_TimeLoggerMap::iterator it;
00050     for (it = m_loggers.begin(); it != m_loggers.end(); it++) {
00051         it->second->SetMaxNumMeasurements(maxNumMeasurements);
00052     }
00053     m_maxNumMeasurements = maxNumMeasurements;
00054 }
00055 
00056 
00057 unsigned int KX_TimeCategoryLogger::GetMaxNumMeasurements(void) const
00058 {
00059     return m_maxNumMeasurements;
00060 }
00061 
00062 
00063 void KX_TimeCategoryLogger::AddCategory(TimeCategory tc)
00064 {
00065     // Only add if not already present
00066     if (m_loggers.find(tc) == m_loggers.end()) {
00067         KX_TimeLogger* logger = new KX_TimeLogger(m_maxNumMeasurements);
00068         //assert(logger);
00069         m_loggers.insert(KX_TimeLoggerMap::value_type(tc, logger));
00070     }
00071 }
00072 
00073 
00074 void KX_TimeCategoryLogger::StartLog(TimeCategory tc, double now, bool endOtherCategories)
00075 {
00076     if (endOtherCategories) {
00077         KX_TimeLoggerMap::iterator it;
00078         for (it = m_loggers.begin(); it != m_loggers.end(); it++) {
00079             if (it->first != tc) {
00080                 it->second->EndLog(now);
00081             }
00082         }
00083     }
00084     //assert(m_loggers[tc] != m_loggers.end());
00085     m_loggers[tc]->StartLog(now);
00086 }
00087 
00088 
00089 void KX_TimeCategoryLogger::EndLog(TimeCategory tc, double now)
00090 {
00091     //assert(m_loggers[tc] != m_loggers.end());
00092     m_loggers[tc]->EndLog(now);
00093 }
00094 
00095 
00096 void KX_TimeCategoryLogger::EndLog(double now)
00097 {
00098     KX_TimeLoggerMap::iterator it;
00099     for (it = m_loggers.begin(); it != m_loggers.end(); it++) {
00100         it->second->EndLog(now);
00101     }
00102 }
00103 
00104 
00105 void KX_TimeCategoryLogger::NextMeasurement(double now)
00106 {
00107     KX_TimeLoggerMap::iterator it;
00108     for (it = m_loggers.begin(); it != m_loggers.end(); it++) {
00109         it->second->NextMeasurement(now);
00110     }
00111 }
00112 
00113 
00114 double KX_TimeCategoryLogger::GetAverage(TimeCategory tc)
00115 {
00116     //assert(m_loggers[tc] != m_loggers.end());
00117     return m_loggers[tc]->GetAverage();
00118 }
00119 
00120 
00121 double KX_TimeCategoryLogger::GetAverage(void)
00122 {
00123     double time = 0.;
00124 
00125     KX_TimeLoggerMap::iterator it;
00126     for (it = m_loggers.begin(); it != m_loggers.end(); it++) {
00127         time += it->second->GetAverage();
00128     }
00129 
00130     return time;
00131 }
00132 
00133 
00134 void KX_TimeCategoryLogger::DisposeLoggers(void)
00135 {
00136     KX_TimeLoggerMap::iterator it;
00137     for (it = m_loggers.begin(); it != m_loggers.end(); it++) {
00138         delete it->second;
00139     }
00140 }
00141