comparison base/Profiler.h @ 0:fc9323a41f5a

start base : Sonic Visualiser sv1-1.0rc1
author lbajardsilogic
date Fri, 11 May 2007 09:08:14 +0000
parents
children be6d31baecb9
comparison
equal deleted inserted replaced
-1:000000000000 0:fc9323a41f5a
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version. See the file
12 COPYING included with this distribution for more information.
13 */
14
15 /*
16 This is a modified version of a source file from the
17 Rosegarden MIDI and audio sequencer and notation editor.
18 This file copyright 2000-2006 Chris Cannam, Guillaume Laurent,
19 and QMUL.
20 */
21
22
23 #ifndef _PROFILER_H_
24 #define _PROFILER_H_
25
26 #include "system/System.h"
27
28 #include <ctime>
29 //#include <sys/time.h>
30 #include <map>
31
32 #include "RealTime.h"
33
34 //#define NO_TIMING 1
35
36 #define WANT_TIMING 1
37
38 #ifdef NDEBUG
39 #ifndef WANT_TIMING
40 #define NO_TIMING 1
41 #endif
42 #endif
43
44 /**
45 * Profiling classes
46 */
47
48 /**
49 * The class holding all profiling data
50 *
51 * This class is a singleton
52 */
53 class Profiles
54 {
55 public:
56 static Profiles* getInstance();
57 ~Profiles();
58
59 void accumulate(const char* id, clock_t time, RealTime rt);
60 void dump() const;
61
62 protected:
63 Profiles();
64
65 typedef std::pair<clock_t, RealTime> TimePair;
66 typedef std::pair<int, TimePair> ProfilePair;
67 typedef std::map<const char *, ProfilePair> ProfileMap;
68 typedef std::map<const char *, TimePair> LastCallMap;
69 typedef std::map<const char *, TimePair> WorstCallMap;
70 ProfileMap m_profiles;
71 LastCallMap m_lastCalls;
72 WorstCallMap m_worstCalls;
73
74 static Profiles* m_instance;
75 };
76
77 #ifndef NO_TIMING
78
79 /**
80 * Profile point instance class. Construct one of these on the stack
81 * at the start of a function, in order to record the time consumed
82 * within that function. The profiler object should be effectively
83 * optimised out if NO_TIMING is defined, so any overhead in a release
84 * build should be negligible so long as you remember to define that.
85 */
86 class Profiler
87 {
88 public:
89 /**
90 * Create a profile point instance that records time consumed
91 * against the given profiling point name. If showOnDestruct is
92 * true, the time consumed will be printed to stderr when the
93 * object is destroyed; otherwise, only the accumulated, mean and
94 * worst-case times will be shown when the program exits or
95 * Profiles::dump() is called.
96 */
97 Profiler(const char *name, bool showOnDestruct = false);
98 ~Profiler();
99
100 void update() const;
101
102 protected:
103 const char* m_c;
104 clock_t m_startCPU;
105 RealTime m_startTime;
106 bool m_showOnDestruct;
107 };
108
109 #else
110
111 class Profiler
112 {
113 public:
114 Profiler(const char *, bool) { }
115 ~Profiler() { }
116
117 void update() { }
118 };
119
120 #endif
121
122 #endif