ardour
timers.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 Tim Mayberry
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 
18 */
19 
20 #include "timers.h"
21 
22 #include "pbd/timer.h"
23 #include "pbd/debug.h"
24 #include "pbd/compose.h"
25 
26 #include "debug.h"
27 
28 namespace {
29 
30 class StandardTimer : public PBD::StandardTimer
31 {
32 public:
33  StandardTimer (unsigned int interval)
34  : PBD::StandardTimer(interval)
35  { }
36 
37  virtual bool on_elapsed () {
38  DEBUG_TIMING_ADD_ELAPSED(PBD::DEBUG::GUITiming, timing_interval_data);
39  DEBUG_TIMING_START(PBD::DEBUG::GUITiming, timing_exec_data);
40 
41  bool ret_val = PBD::StandardTimer::on_elapsed ();
42 
44  DEBUG_TIMING_START(PBD::DEBUG::GUITiming, timing_interval_data);
45  return ret_val;
46  }
47 
48 #ifndef NDEBUG
49  PBD::TimingData timing_interval_data;
50  PBD::TimingData timing_exec_data;
51 #endif
52 };
53 
54 class BlinkTimer : public PBD::BlinkTimer
55 {
56 public:
57  BlinkTimer (unsigned int interval)
58  : PBD::BlinkTimer(interval)
59  { }
60 
61  virtual bool on_elapsed () {
62  DEBUG_TIMING_ADD_ELAPSED(PBD::DEBUG::GUITiming, timing_interval_data);
63  DEBUG_TIMING_START(PBD::DEBUG::GUITiming, timing_exec_data);
64 
65  bool ret_val = PBD::BlinkTimer::on_elapsed ();
66 
68  DEBUG_TIMING_START(PBD::DEBUG::GUITiming, timing_interval_data);
69  return ret_val;
70  }
71 
72 #ifndef NDEBUG
73  PBD::TimingData timing_interval_data;
74  PBD::TimingData timing_exec_data;
75 #endif
76 };
77 
78 
79 class UITimers
80 {
81 
82 public:
83 
84  UITimers ()
85  : blink(240)
86  , second(1000)
87  , rapid(100)
88  , super_rapid(40)
89  , fps(40)
90  {
91 #ifndef NDEBUG
92  second.connect (sigc::mem_fun (*this, &UITimers::on_second_timer));
93 #endif
94  }
95 
96  BlinkTimer blink;
97  StandardTimer second;
98  StandardTimer rapid;
99  StandardTimer super_rapid;
100  StandardTimer fps;
101 
102 #ifndef NDEBUG
103  std::vector<uint64_t> rapid_eps_count;
104  std::vector<uint64_t> super_rapid_eps_count;
105  std::vector<uint64_t> fps_eps_count;
106 
107 private:
108 
109  void debug_rapid_timer () {
110  DEBUG_TRACE(PBD::DEBUG::GUITiming, string_compose ("Rapid Connections: %1\n", rapid.connection_count ()));
111 
112  rapid_eps_count.push_back (rapid.timing_exec_data.size());
113 
114  DEBUG_TRACE(PBD::DEBUG::GUITiming, string_compose ("Rapid Exec Totals: %1", PBD::timing_summary (rapid_eps_count)));
115 
116  DEBUG_TRACE(PBD::DEBUG::GUITiming, string_compose ("Rapid Interval: %1", rapid.timing_interval_data.summary()));
117  DEBUG_TRACE(PBD::DEBUG::GUITiming, string_compose ("Rapid Exec: %1", rapid.timing_exec_data.summary()));
118  DEBUG_TIMING_RESET(PBD::DEBUG::GUITiming, rapid.timing_interval_data);
119  DEBUG_TIMING_RESET(PBD::DEBUG::GUITiming, rapid.timing_exec_data);
120  }
121 
122  void debug_super_rapid_timer () {
123  // we don't use this timer on windows so don't display empty data for it
124 #ifndef PLATFORM_WINDOWS
125 
126  DEBUG_TRACE(PBD::DEBUG::GUITiming, string_compose ("Super Rapid Connections: %1\n", super_rapid.connection_count ()));
127 
128  super_rapid_eps_count.push_back (super_rapid.timing_exec_data.size());
129 
130  DEBUG_TRACE(PBD::DEBUG::GUITiming, string_compose ("Super Rapid Exec Totals: %1", PBD::timing_summary (super_rapid_eps_count)));
131  DEBUG_TRACE(PBD::DEBUG::GUITiming, string_compose ("Super Rapid Interval: %1", super_rapid.timing_interval_data.summary()));
132  DEBUG_TRACE(PBD::DEBUG::GUITiming, string_compose ("Super Rapid Exec: %1", super_rapid.timing_exec_data.summary()));
133  DEBUG_TIMING_RESET(PBD::DEBUG::GUITiming, super_rapid.timing_interval_data);
134  DEBUG_TIMING_RESET(PBD::DEBUG::GUITiming, super_rapid.timing_exec_data);
135 #endif
136  }
137 
138  void debug_fps_timer () {
139  DEBUG_TRACE(PBD::DEBUG::GUITiming, string_compose ("FPS Connections: %1\n", fps.connection_count ()));
140 
141  fps_eps_count.push_back (fps.timing_exec_data.size());
142 
143  DEBUG_TRACE(PBD::DEBUG::GUITiming, string_compose ("FPS Exec Totals: %1", PBD::timing_summary (fps_eps_count)));
144 
145  DEBUG_TRACE(PBD::DEBUG::GUITiming, string_compose ("FPS Interval: %1", fps.timing_interval_data.summary()));
146  DEBUG_TRACE(PBD::DEBUG::GUITiming, string_compose ("FPS Exec: %1", fps.timing_exec_data.summary()));
147  DEBUG_TIMING_RESET(PBD::DEBUG::GUITiming, fps.timing_interval_data);
148  DEBUG_TIMING_RESET(PBD::DEBUG::GUITiming, fps.timing_exec_data);
149  }
150 
151  void on_second_timer () {
152  debug_rapid_timer ();
153  debug_super_rapid_timer ();
154  debug_fps_timer ();
155  }
156 #endif
157 };
158 
159 UITimers&
160 get_timers ()
161 {
162  static UITimers timers;
163  return timers;
164 }
165 
166 } // anon namespace
167 
168 namespace Timers {
169 
170 sigc::connection
171 blink_connect(const sigc::slot<void,bool>& slot)
172 {
173  return get_timers().blink.connect (slot);
174 }
175 
176 sigc::connection
177 second_connect(const sigc::slot<void>& slot)
178 {
179  return get_timers().second.connect (slot);
180 }
181 
182 sigc::connection
183 rapid_connect(const sigc::slot<void>& slot)
184 {
185  return get_timers().rapid.connect (slot);
186 }
187 
188 sigc::connection
189 super_rapid_connect(const sigc::slot<void>& slot)
190 {
191 #ifdef PLATFORM_WINDOWS
192  return get_timers().fps.connect (slot);
193 #else
194  return get_timers().super_rapid.connect (slot);
195 #endif
196 }
197 
198 void
199 set_fps_interval (unsigned int interval)
200 {
201  get_timers().fps.set_interval (interval);
202 }
203 
204 sigc::connection
205 fps_connect(const sigc::slot<void>& slot)
206 {
207  return get_timers().fps.connect (slot);
208 }
209 
210 } // namespace Timers
#define DEBUG_TIMING_START(bits, td)
Definition: debug.h:66
#define DEBUG_TIMING_ADD_ELAPSED(bits, td)
Definition: debug.h:67
sigc::connection super_rapid_connect(const sigc::slot< void > &slot)
Definition: timers.cc:189
BlinkTimer(unsigned int interval, const Glib::RefPtr< Glib::MainContext > &main_context=Glib::MainContext::get_default())
Definition: timer.cc:128
#define DEBUG_TIMING_RESET(bits, td)
Definition: debug.h:68
void set_fps_interval(unsigned int interval)
Definition: timers.cc:199
virtual bool on_elapsed()
Definition: timer.cc:116
#define DEBUG_TRACE(bits, str)
Definition: debug.h:55
sigc::connection blink_connect(const sigc::slot< void, bool > &slot)
Definition: timers.cc:171
sigc::connection second_connect(const sigc::slot< void > &slot)
Definition: timers.cc:177
uint64_t GUITiming
Definition: debug.cc:31
virtual bool on_elapsed()
Definition: timer.cc:142
sigc::connection fps_connect(const sigc::slot< void > &slot)
Definition: timers.cc:205
Definition: debug.h:30
LIBPBD_API std::string timing_summary(const std::vector< uint64_t > &values)
Definition: timing.cc:54
sigc::connection rapid_connect(const sigc::slot< void > &slot)
Definition: timers.cc:183
StandardTimer(unsigned int interval, const Glib::RefPtr< Glib::MainContext > &main_context=Glib::MainContext::get_default())
Definition: timer.cc:102
std::string string_compose(const std::string &fmt, const T1 &o1)
Definition: compose.h:208