annotate base/Profiler.h @ 1290:fa574c909c3d 3.0-integration

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