4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
30 #ifndef __KX_TIME_CATEGORY_LOGGER_H
31 #define __KX_TIME_CATEGORY_LOGGER_H
34 #pragma warning (disable:4786) // suppress stl-MSVC debug info warning
39 #include "KX_TimeLogger.h"
42 * Stores and manages time measurements by category.
43 * Categories can be added dynamically.
44 * Average measurements can be established for each separate category
45 * or for all categories together.
47 class KX_TimeCategoryLogger {
49 typedef int TimeCategory;
53 * @param maxNumMesasurements Maximum number of measurements stored (> 1).
55 KX_TimeCategoryLogger(unsigned int maxNumMeasurements = 10);
60 virtual ~KX_TimeCategoryLogger(void);
63 * Changes the maximum number of measurements that can be stored.
65 virtual void SetMaxNumMeasurements(unsigned int maxNumMeasurements);
68 * Changes the maximum number of measurements that can be stored.
70 virtual unsigned int GetMaxNumMeasurements(void) const;
74 * @param category The new category.
76 virtual void AddCategory(TimeCategory tc);
79 * Starts logging in current measurement for the given category.
80 * @param tc The category to log to.
81 * @param now The current time.
82 * @param endOtherCategories Whether to stop logging to other categories.
84 virtual void StartLog(TimeCategory tc, double now, bool endOtherCategories = true);
87 * End logging in current measurement for the given category.
88 * @param tc The category to log to.
89 * @param now The current time.
91 virtual void EndLog(TimeCategory tc, double now);
94 * End logging in current measurement for all categories.
95 * @param now The current time.
97 virtual void EndLog(double now);
100 * Logs time in next measurement.
101 * @param now The current time.
103 virtual void NextMeasurement(double now);
106 * Returns average of all but the current measurement time.
107 * @return The average of all but the current measurement.
109 virtual double GetAverage(TimeCategory tc);
112 * Returns average for grand total.
114 virtual double GetAverage(void);
120 virtual void DisposeLoggers(void);
122 /** Storage for the loggers. */
123 typedef std::map<TimeCategory, KX_TimeLogger*> KX_TimeLoggerMap;
124 KX_TimeLoggerMap m_loggers;
125 /** Maximum number of measurements. */
126 unsigned int m_maxNumMeasurements;
130 #endif // __KX_TIME_CATEGORY_LOGGER_H