00001 /*************************************************************************** 00002 debug-profiler.h - description 00003 ------------------- 00004 begin : Sat May 28 2005 00005 copyright : (C) 2005 by Martin Witte 00006 email : witte@kawo1.rwth-aachen.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef KRADIO_DEBUG_PROFILER_H 00019 #define KRADIO_DEBUG_PROFILER_H 00020 00021 #ifdef HAVE_CONFIG_H 00022 #include <config.h> 00023 #endif 00024 00025 #include <qstring.h> 00026 #include <qmap.h> 00027 00028 #if (defined __i386__) || (defined __x86_64__) 00029 static __inline__ unsigned long long int rdtsc() 00030 { 00031 unsigned int a, d; 00032 asm volatile("rdtsc" : "=a" (a), "=d" (d)); 00033 return ((unsigned long long)a) | (((unsigned long long)d) << 32); 00034 } 00035 #else 00036 static __inline__ unsigned long long int rdtsc() 00037 { 00038 return 0UL; 00039 } 00040 #endif 00041 00042 class Profiler 00043 { 00044 public: 00045 Profiler(); 00046 virtual ~Profiler(); 00047 00048 void startProfile(const QString &descr); 00049 void stopProfile (const QString &descr); 00050 00051 void printData(); 00052 00053 protected: 00054 00055 virtual long long getCounter() const = 0; 00056 00057 void stopInternalCounter(); 00058 void startInternalCounter(); 00059 00060 long long m_internalCounter; 00061 long long m_tmpStartVal; 00062 00063 struct profile_data 00064 { 00065 profile_data(long long start = 0) : 00066 startCounter(start), accumulatedCounter(0), callCounter(0), 00067 minCounter(0x7FFFFFFFFFFFFFFFll), maxCounter(0) {} 00068 long long startCounter; 00069 long long accumulatedCounter; 00070 long long callCounter; 00071 long long minCounter; 00072 long long maxCounter; 00073 }; 00074 00075 QMap<QString, profile_data> m_ProfileData; 00076 }; 00077 00078 00079 class TimeProfiler : public Profiler 00080 { 00081 protected: 00082 long long getCounter() const { return rdtsc(); } 00083 }; 00084 00085 00086 class MemProfiler : public Profiler 00087 { 00088 protected: 00089 long long getCounter() const; 00090 }; 00091 00092 00093 extern TimeProfiler global_time_profiler; 00094 extern MemProfiler global_mem_profiler; 00095 00096 00097 00098 class BlockProfiler 00099 { 00100 public: 00101 BlockProfiler(const QString &descr); 00102 ~BlockProfiler(); 00103 00104 void stop(); 00105 00106 protected: 00107 QString m_Description; 00108 }; 00109 00110 00111 00112 #endif