00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 00008 This program is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU General Public License as 00010 published by the Free Software Foundation; either version 2 of the 00011 License, or (at your option) any later version. See the file 00012 COPYING included with this distribution for more information. 00013 */ 00014 00015 /* 00016 This is a modified version of a source file from the 00017 Rosegarden MIDI and audio sequencer and notation editor. 00018 This file copyright 2000-2006 Chris Cannam, Guillaume Laurent, 00019 and QMUL. 00020 */ 00021 00022 00023 #ifndef _PROFILER_H_ 00024 #define _PROFILER_H_ 00025 00026 #include "system/System.h" 00027 00028 #include <ctime> 00029 #include <sys/time.h> 00030 #include <map> 00031 00032 #include "RealTime.h" 00033 00034 //#define NO_TIMING 1 00035 00036 #define WANT_TIMING 1 00037 00038 #ifdef NDEBUG 00039 #ifndef WANT_TIMING 00040 #define NO_TIMING 1 00041 #endif 00042 #endif 00043 00053 class Profiles 00054 { 00055 public: 00056 static Profiles* getInstance(); 00057 ~Profiles(); 00058 00059 void accumulate(const char* id, clock_t time, RealTime rt); 00060 void dump() const; 00061 00062 protected: 00063 Profiles(); 00064 00065 typedef std::pair<clock_t, RealTime> TimePair; 00066 typedef std::pair<int, TimePair> ProfilePair; 00067 typedef std::map<const char *, ProfilePair> ProfileMap; 00068 typedef std::map<const char *, TimePair> LastCallMap; 00069 typedef std::map<const char *, TimePair> WorstCallMap; 00070 ProfileMap m_profiles; 00071 LastCallMap m_lastCalls; 00072 WorstCallMap m_worstCalls; 00073 00074 static Profiles* m_instance; 00075 }; 00076 00077 #ifndef NO_TIMING 00078 00086 class Profiler 00087 { 00088 public: 00097 Profiler(const char *name, bool showOnDestruct = false); 00098 ~Profiler(); 00099 00100 void update() const; 00101 00102 protected: 00103 const char* m_c; 00104 clock_t m_startCPU; 00105 RealTime m_startTime; 00106 bool m_showOnDestruct; 00107 }; 00108 00109 #else 00110 00111 class Profiler 00112 { 00113 public: 00114 Profiler(const char *, bool) { } 00115 ~Profiler() { } 00116 00117 void update() { } 00118 }; 00119 00120 #endif 00121 00122 #endif
1.5.1