Profiler.h
Go to the documentation of this file.
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 SV_PROFILER_H
24 #define SV_PROFILER_H
25 
26 #include "system/System.h"
27 
28 #include <map>
29 
30 #include "RealTime.h"
31 
32 //#define NO_TIMING 1
33 
34 //#define WANT_TIMING 1
35 
36 #ifdef NDEBUG
37 #ifndef WANT_TIMING
38 #define NO_TIMING 1
39 #endif
40 #endif
41 
42 #ifndef NO_TIMING
43 #include <ctime>
44 #include <sys/time.h>
45 #endif
46 
56 class Profiles
57 {
58 public:
59  static Profiles* getInstance();
60  ~Profiles();
61 
62 #ifndef NO_TIMING
63  void accumulate(const char* id, clock_t time, RealTime rt);
64 #endif
65  void dump() const;
66 
67 protected:
68  Profiles();
69 
70 #ifndef NO_TIMING
71  typedef std::pair<clock_t, RealTime> TimePair;
72  typedef std::pair<int, TimePair> ProfilePair;
73  typedef std::map<const char *, ProfilePair> ProfileMap;
74  typedef std::map<const char *, TimePair> LastCallMap;
75  typedef std::map<const char *, TimePair> WorstCallMap;
76  ProfileMap m_profiles;
77  LastCallMap m_lastCalls;
78  WorstCallMap m_worstCalls;
79 #endif
80 
82 };
83 
84 #ifndef NO_TIMING
85 
93 class Profiler
94 {
95 public:
104  Profiler(const char *name, bool showOnDestruct = false);
105  ~Profiler();
106 
107  void update() const;
108  void end(); // same action as dtor
109 
110 protected:
111  const char* m_c;
112  clock_t m_startCPU;
115  bool m_ended;
116 };
117 
118 #else
119 
120 class Profiler
121 {
122 public:
123  Profiler(const char *, bool = false) { }
124  ~Profiler() { }
125 
126  void update() const { }
127  void end() { }
128 };
129 
130 #endif
131 
132 #endif
WorstCallMap m_worstCalls
Definition: Profiler.h:78
Profiles()
Definition: Profiler.cpp:41
std::pair< clock_t, RealTime > TimePair
Definition: Profiler.h:71
std::map< const char *, TimePair > WorstCallMap
Definition: Profiler.h:75
static Profiles * m_instance
Definition: Profiler.h:81
std::map< const char *, ProfilePair > ProfileMap
Definition: Profiler.h:73
~Profiles()
Definition: Profiler.cpp:45
Profiling classes.
Definition: Profiler.h:56
const char * m_c
Definition: Profiler.h:111
bool m_ended
Definition: Profiler.h:115
RealTime m_startTime
Definition: Profiler.h:113
ProfileMap m_profiles
Definition: Profiler.h:76
LastCallMap m_lastCalls
Definition: Profiler.h:77
clock_t m_startCPU
Definition: Profiler.h:112
std::map< const char *, TimePair > LastCallMap
Definition: Profiler.h:74
static Profiles * getInstance()
Definition: Profiler.cpp:34
std::pair< int, TimePair > ProfilePair
Definition: Profiler.h:72
void accumulate(const char *id, clock_t time, RealTime rt)
Definition: Profiler.cpp:51
void dump() const
Definition: Profiler.cpp:74
bool m_showOnDestruct
Definition: Profiler.h:114
Profile point instance class.
Definition: Profiler.h:93
RealTime represents time values to nanosecond precision with accurate arithmetic and frame-rate conve...
Definition: RealTime.h:42