svcore  1.9
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 _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 
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;
73 
75 };
76 
77 #ifndef NO_TIMING
78 
86 class Profiler
87 {
88 public:
97  Profiler(const char *name, bool showOnDestruct = false);
98  ~Profiler();
99 
100  void update() const;
101  void end(); // same action as dtor
102 
103 protected:
104  const char* m_c;
105  clock_t m_startCPU;
108  bool m_ended;
109 };
110 
111 #else
112 
113 class Profiler
114 {
115 public:
116  Profiler(const char *, bool = false) { }
117  ~Profiler() { }
118 
119  void update() const { }
120  void end() { }
121 };
122 
123 #endif
124 
125 #endif
void update() const
Definition: Profiler.cpp:190
WorstCallMap m_worstCalls
Definition: Profiler.h:72
Profiles()
Definition: Profiler.cpp:41
void end()
Definition: Profiler.cpp:209
std::pair< clock_t, RealTime > TimePair
Definition: Profiler.h:65
std::map< const char *, TimePair > WorstCallMap
Definition: Profiler.h:69
static Profiles * m_instance
Definition: Profiler.h:74
std::map< const char *, ProfilePair > ProfileMap
Definition: Profiler.h:67
~Profiles()
Definition: Profiler.cpp:45
Profiling classes.
Definition: Profiler.h:53
const char * m_c
Definition: Profiler.h:104
bool m_ended
Definition: Profiler.h:108
RealTime m_startTime
Definition: Profiler.h:106
ProfileMap m_profiles
Definition: Profiler.h:70
LastCallMap m_lastCalls
Definition: Profiler.h:71
clock_t m_startCPU
Definition: Profiler.h:105
std::map< const char *, TimePair > LastCallMap
Definition: Profiler.h:68
static Profiles * getInstance()
Definition: Profiler.cpp:34
std::pair< int, TimePair > ProfilePair
Definition: Profiler.h:66
Profiler(const char *name, bool showOnDestruct=false)
Create a profile point instance that records time consumed against the given profiling point name.
Definition: Profiler.cpp:177
void dump() const
Definition: Profiler.cpp:78
void accumulate(const char *id, clock_t time, RealTime rt)
Definition: Profiler.cpp:50
bool m_showOnDestruct
Definition: Profiler.h:107
Profile point instance class.
Definition: Profiler.h:86
RealTime represents time values to nanosecond precision with accurate arithmetic and frame-rate conve...
Definition: RealTime.h:35