3 Copyright (C) 2013 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 Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser 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.
22 #include "irrlichttypes.h"
28 #include "threading/mutex_auto_lock.h"
29 #include "util/timetaker.h"
30 #include "util/numeric.h" // paging()
34 extern Profiler *g_profiler;
45 void add(const std::string &name, float value);
46 void avg(const std::string &name, float value);
49 float getValue(const std::string &name) const;
50 int getAvgCount(const std::string &name) const;
51 u64 getElapsedMs() const;
53 typedef std::map<std::string, float> GraphValues;
55 // Returns the line count
56 int print(std::ostream &o, u32 page = 1, u32 pagecount = 1);
57 void getPage(GraphValues &o, u32 page, u32 pagecount);
60 void graphAdd(const std::string &id, float value)
62 MutexAutoLock lock(m_mutex);
63 std::map<std::string, float>::iterator i =
64 m_graphvalues.find(id);
65 if(i == m_graphvalues.end())
66 m_graphvalues[id] = value;
70 void graphGet(GraphValues &result)
72 MutexAutoLock lock(m_mutex);
73 result = m_graphvalues;
74 m_graphvalues.clear();
77 void remove(const std::string& name)
79 MutexAutoLock lock(m_mutex);
80 m_avgcounts.erase(name);
86 std::map<std::string, float> m_data;
87 std::map<std::string, int> m_avgcounts;
88 std::map<std::string, float> m_graphvalues;
92 enum ScopeProfilerType{
101 ScopeProfiler(Profiler *profiler, const std::string &name,
102 ScopeProfilerType type = SPT_ADD);
105 Profiler *m_profiler = nullptr;
107 TimeTaker *m_timer = nullptr;
108 enum ScopeProfilerType m_type;