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