kradio4  r778
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
debug-profiler.h
Go to the documentation of this file.
1 /***************************************************************************
2  debug-profiler.h - description
3  -------------------
4  begin : Sat May 28 2005
5  copyright : (C) 2005 by Martin Witte
6  email : emw-kradio@nocabal.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef KRADIO_DEBUG_PROFILER_H
19 #define KRADIO_DEBUG_PROFILER_H
20 
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24 
25 #include <QtCore/QString>
26 #include <QtCore/QMap>
27 #include <kdemacros.h>
28 
29 #if (defined __i386__) || (defined __x86_64__)
30 static __inline__ unsigned long long int rdtsc()
31 {
32  unsigned int a, d;
33  asm volatile("rdtsc" : "=a" (a), "=d" (d));
34  return ((unsigned long long)a) | (((unsigned long long)d) << 32);
35 }
36 #else
37 static __inline__ unsigned long long int rdtsc()
38 {
39  return 0UL;
40 }
41 #endif
42 
43 class KDE_EXPORT Profiler
44 {
45 public:
46  Profiler();
47  virtual ~Profiler();
48 
49  void startProfile(const QString &descr);
50  void stopProfile (const QString &descr);
51 
52  void printData();
53 
54 protected:
55 
56  virtual long long getCounter() const = 0;
57 
58  void stopInternalCounter();
59  void startInternalCounter();
60 
61  long long m_internalCounter;
62  long long m_tmpStartVal;
63 
64  struct profile_data
65  {
66  profile_data(long long start = 0) :
67  startCounter(start), accumulatedCounter(0), callCounter(0),
68  minCounter(0x7FFFFFFFFFFFFFFFll), maxCounter(0) {}
69  long long startCounter;
70  long long accumulatedCounter;
71  long long callCounter;
72  long long minCounter;
73  long long maxCounter;
74  };
75 
76  QMap<QString, profile_data> m_ProfileData;
77 };
78 
79 
80 class KDE_EXPORT TimeProfiler : public Profiler
81 {
82 protected:
83  long long getCounter() const { return rdtsc(); }
84 };
85 
86 
87 class KDE_EXPORT MemProfiler : public Profiler
88 {
89 protected:
90  long long getCounter() const;
91 };
92 
93 
94 extern KDE_EXPORT TimeProfiler global_time_profiler;
95 extern KDE_EXPORT MemProfiler global_mem_profiler;
96 
97 
98 
99 class KDE_EXPORT BlockProfiler
100 {
101 public:
102  BlockProfiler(const QString &descr);
103  ~BlockProfiler();
104 
105  void stop();
106 
107 protected:
108  QString m_Description;
109 };
110 
111 
112 
113 #endif