debug-profiler.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           debug-profiler.h  -  description
00003                              -------------------
00004     begin                : Sat May 28 2005
00005     copyright            : (C) 2005 by Martin Witte
00006     email                : emw-kradio@nocabal.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 <QtCore/QString>
00026 #include <QtCore/QMap>
00027 #include <kdemacros.h>
00028 
00029 #if (defined __i386__) || (defined __x86_64__)
00030 static __inline__ unsigned long long int rdtsc()
00031 {
00032     unsigned int a, d;
00033     asm volatile("rdtsc" : "=a" (a), "=d" (d));
00034     return ((unsigned long long)a) | (((unsigned long long)d) << 32);
00035 }
00036 #else
00037 static __inline__ unsigned long long int rdtsc()
00038 {
00039     return 0UL;
00040 }
00041 #endif
00042 
00043 class KDE_EXPORT Profiler
00044 {
00045 public:
00046     Profiler();
00047     virtual ~Profiler();
00048 
00049     void startProfile(const QString &descr);
00050     void stopProfile (const QString &descr);
00051 
00052     void printData();
00053 
00054 protected:
00055 
00056     virtual long long getCounter() const = 0;
00057 
00058     void stopInternalCounter();
00059     void startInternalCounter();
00060 
00061     long long m_internalCounter;
00062     long long m_tmpStartVal;
00063 
00064     struct profile_data
00065     {
00066         profile_data(long long start = 0) :
00067             startCounter(start), accumulatedCounter(0), callCounter(0),
00068             minCounter(0x7FFFFFFFFFFFFFFFll), maxCounter(0) {}
00069         long long startCounter;
00070         long long accumulatedCounter;
00071         long long callCounter;
00072         long long minCounter;
00073         long long maxCounter;
00074     };
00075 
00076     QMap<QString, profile_data> m_ProfileData;
00077 };
00078 
00079 
00080 class KDE_EXPORT TimeProfiler : public Profiler
00081 {
00082 protected:
00083     long long getCounter() const { return rdtsc(); }
00084 };
00085 
00086 
00087 class KDE_EXPORT MemProfiler : public Profiler
00088 {
00089 protected:
00090     long long getCounter() const;
00091 };
00092 
00093 
00094 extern KDE_EXPORT TimeProfiler global_time_profiler;
00095 extern KDE_EXPORT MemProfiler  global_mem_profiler;
00096 
00097 
00098 
00099 class KDE_EXPORT BlockProfiler
00100 {
00101 public:
00102     BlockProfiler(const QString &descr);
00103     ~BlockProfiler();
00104 
00105     void stop();
00106 
00107 protected:
00108     QString m_Description;
00109 };
00110 
00111 
00112 
00113 #endif

Generated on Tue Jun 2 19:19:57 2009 for kradio4 by  doxygen 1.5.8