3 Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #ifndef PROFILER_HEADER
21 #define PROFILER_HEADER
23 #include "common_irrlicht.h"
27 #include <jmutexautolock.h>
41 void add(const std::string &name, u32 duration)
43 JMutexAutoLock lock(m_mutex);
44 core::map<std::string, u32>::Node *n = m_data.find(name);
47 m_data[name] = duration;
51 n->setValue(n->getValue()+duration);
57 JMutexAutoLock lock(m_mutex);
58 for(core::map<std::string, u32>::Iterator
59 i = m_data.getIterator();
60 i.atEnd() == false; i++)
62 i.getNode()->setValue(0);
66 void print(std::ostream &o)
68 JMutexAutoLock lock(m_mutex);
69 for(core::map<std::string, u32>::Iterator
70 i = m_data.getIterator();
71 i.atEnd() == false; i++)
73 std::string name = i.getNode()->getKey();
76 s32 space = clampsize-name.size();
77 for(s32 j=0; j<space; j++)
79 if(j%2 == 0 && j < space - 1)
84 o<<i.getNode()->getValue();
91 core::map<std::string, u32> m_data;
97 ScopeProfiler(Profiler *profiler, const std::string &name):
103 m_timer = new TimeTaker(m_name.c_str());
106 ScopeProfiler(Profiler *profiler, const char *name):
107 m_profiler(profiler),
112 m_timer = new TimeTaker(m_name.c_str());
118 u32 duration = m_timer->stop(true);
120 m_profiler->add(m_name, duration);
125 Profiler *m_profiler;