Profiling.h

00001 // $Id: Profiling.h 21 2010-09-05 04:18:17Z cschwarz1 $
00002 
00003 #ifndef BASE_PROFILING_H
00004 #define BASE_PROFILING_H
00005 
00006 #include <iostream>
00007 #include <map>
00008 #include "String.h"
00009 #include "Timer.h"
00010 
00011 namespace base {
00013 
00017     class PPBASE_EXPORT Profiling: public Timer {
00018     public:
00020         template<class TO> void dump(TO &out) {
00021             std::map<String, std::pair<unsigned, u_longlong_t> >::const_iterator i;
00022             unsigned                                                                  ms;
00023             u_longlong_t                                                              ticks;
00024 
00025             for (i = _tasks.begin(), ticks = 0; i != _tasks.end(); i++) {
00026                 ms = getMilliSecondsFromTicks(i->second.second);
00027                 out << i->first << ' ' << i->second.first << '/' << ms << "ms, "
00028                     << (i->second.first ? static_cast<float>(ms) / i->second.first : 0.0f)
00029                     << "ms per item" << std::endl;
00030                 ticks += i->second.second;
00031             }
00032             out << "total: " << getMilliSecondsFromTicks(ticks) << "ms" << std::endl;
00033         }
00034 
00036 
00039         const std::map<String, std::pair<unsigned, u_longlong_t> > &getTasks() const;
00040 
00042         void start();
00043 
00045 
00049         void stop(const char *name, unsigned count = 1);
00050 
00051     private:
00053         std::map<String, std::pair<unsigned, u_longlong_t> > _tasks;
00054     };
00055 }
00056 
00057 #endif