annotate base/Profiler.h @ 717:bcdb2a18d9bc library_integration

Revert that change -- this code is used only in Sonic Annotator
author Chris Cannam
date Tue, 18 Oct 2011 10:14:17 +0100
parents 5a13b76cd034
children c811991a5efa
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 <ctime>
Chris@0 29 #include <sys/time.h>
Chris@0 30 #include <map>
Chris@0 31
Chris@0 32 #include "RealTime.h"
Chris@0 33
Chris@183 34 //#define NO_TIMING 1
Chris@183 35
Chris@434 36 //#define WANT_TIMING 1
Chris@183 37
Chris@183 38 #ifdef NDEBUG
Chris@183 39 #ifndef WANT_TIMING
Chris@183 40 #define NO_TIMING 1
Chris@183 41 #endif
Chris@183 42 #endif
Chris@0 43
Chris@0 44 /**
Chris@0 45 * Profiling classes
Chris@0 46 */
Chris@0 47
Chris@0 48 /**
Chris@0 49 * The class holding all profiling data
Chris@0 50 *
Chris@0 51 * This class is a singleton
Chris@0 52 */
Chris@0 53 class Profiles
Chris@0 54 {
Chris@0 55 public:
Chris@0 56 static Profiles* getInstance();
Chris@0 57 ~Profiles();
Chris@0 58
Chris@0 59 void accumulate(const char* id, clock_t time, RealTime rt);
Chris@183 60 void dump() const;
Chris@0 61
Chris@0 62 protected:
Chris@0 63 Profiles();
Chris@0 64
Chris@0 65 typedef std::pair<clock_t, RealTime> TimePair;
Chris@0 66 typedef std::pair<int, TimePair> ProfilePair;
Chris@0 67 typedef std::map<const char *, ProfilePair> ProfileMap;
Chris@0 68 typedef std::map<const char *, TimePair> LastCallMap;
Chris@183 69 typedef std::map<const char *, TimePair> WorstCallMap;
Chris@0 70 ProfileMap m_profiles;
Chris@0 71 LastCallMap m_lastCalls;
Chris@183 72 WorstCallMap m_worstCalls;
Chris@0 73
Chris@0 74 static Profiles* m_instance;
Chris@0 75 };
Chris@0 76
Chris@183 77 #ifndef NO_TIMING
Chris@183 78
Chris@183 79 /**
Chris@183 80 * Profile point instance class. Construct one of these on the stack
Chris@183 81 * at the start of a function, in order to record the time consumed
Chris@183 82 * within that function. The profiler object should be effectively
Chris@183 83 * optimised out if NO_TIMING is defined, so any overhead in a release
Chris@183 84 * build should be negligible so long as you remember to define that.
Chris@183 85 */
Chris@0 86 class Profiler
Chris@0 87 {
Chris@0 88 public:
Chris@183 89 /**
Chris@183 90 * Create a profile point instance that records time consumed
Chris@183 91 * against the given profiling point name. If showOnDestruct is
Chris@183 92 * true, the time consumed will be printed to stderr when the
Chris@183 93 * object is destroyed; otherwise, only the accumulated, mean and
Chris@183 94 * worst-case times will be shown when the program exits or
Chris@183 95 * Profiles::dump() is called.
Chris@183 96 */
Chris@183 97 Profiler(const char *name, bool showOnDestruct = false);
Chris@0 98 ~Profiler();
Chris@0 99
Chris@183 100 void update() const;
Chris@408 101 void end(); // same action as dtor
Chris@0 102
Chris@0 103 protected:
Chris@0 104 const char* m_c;
Chris@0 105 clock_t m_startCPU;
Chris@0 106 RealTime m_startTime;
Chris@0 107 bool m_showOnDestruct;
Chris@408 108 bool m_ended;
Chris@0 109 };
Chris@183 110
Chris@183 111 #else
Chris@183 112
Chris@183 113 class Profiler
Chris@183 114 {
Chris@183 115 public:
Chris@408 116 Profiler(const char *, bool = false) { }
Chris@183 117 ~Profiler() { }
Chris@408 118
Chris@408 119 void update() const { }
Chris@408 120 void end() { }
Chris@183 121 };
Chris@0 122
Chris@0 123 #endif
Chris@183 124
Chris@183 125 #endif