6 #include <boost/thread.hpp>
7 #include <boost/utility.hpp>
14 static std::string LOGGING_LOCATION =
"~/profile_logs";
25 Statistics() : msec(0), callAmount(0), parent(
""), running(true) {}
26 Statistics(
std::string p) : msec(0), callAmount(0), parent(p), running(true){}
38 threadId = boost::this_thread::get_id();
39 currentlyProfiling =
"";
40 stats =
new FunctionStats();
46 static FunctionStatsPtr ReturnCurrentStatistics();
49 FunctionStatsPtr stats;
52 boost::thread::id threadId;
56 class ThreadProfilerManager
60 ThreadProfilerManager();
67 boost::lock_guard<boost::mutex>
lock(mutex);
68 threadStats.push_back(
profiler.get()->stats);
74 ~ThreadProfilerManager();
76 boost::thread_specific_ptr<ThreadProfiler>
profiler;
84 static ThreadProfilerManager manager;
90 if(instance.stats->find(name) == instance.stats->end() && !instance.stats->find(name)->second.running)
92 (*instance.stats)[name] = Statistics(instance.currentlyProfiling);
94 (*instance.stats)[name].timer.start();
95 (*instance.stats)[name].running =
true;
96 instance.currentlyProfiling = name;
102 FunctionStats::iterator mapIt = instance.stats->find(name);
104 if(mapIt == instance.stats->end())
107 mapIt->second.msec += mapIt->second.timer.getElapsedTimeInMilliSec();
108 mapIt->second.callAmount++;
109 mapIt->second.running =
false;
112 inline FunctionStatsPtr ThreadProfiler::ReturnCurrentStatistics()
115 return instance.stats;
121 void deleteElement(T
t)
126 template<
typename _Element,
typename T>
133 inline ThreadProfiler::~ThreadProfiler(){ }
135 inline ThreadProfilerManager::ThreadProfilerManager()
140 inline ThreadProfilerManager::~ThreadProfilerManager()
143 ProfileLog::PrintLog(threadStats, timer.getElapsedTimeInMilliSec());
144 deleteAll<FunctionStatsPtr>(threadStats);