Ardour  8.12
ardour/ardour/cycle_timer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2015 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
4  * Copyright (C) 2009 David Robillard <d@drobilla.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef __ardour_cycle_timer_h__
22 #define __ardour_cycle_timer_h__
23 
24 #include <string>
25 #include <iostream>
26 #include <cstdlib>
27 
29 #include "ardour/cycles.h"
30 #include "ardour/debug.h"
31 
32 float get_mhz ();
33 
35  private:
36  static float cycles_per_usec;
37 #ifndef NDEBUG
40  std::string _name;
41 #endif
42 
43  public:
44  CycleTimer(const std::string& name) {
45 #ifndef NDEBUG
47  _name = name;
48  if (cycles_per_usec == 0) {
49  cycles_per_usec = get_mhz ();
50  }
51  _entry = get_cycles();
52  }
53 #else
54  (void) name;
55 #endif
56  }
57 
59 #ifndef NDEBUG
61  _exit = get_cycles();
62  std::cerr << _name << ": " << (float) (_exit - _entry) / cycles_per_usec << " (" << _entry << ", " << _exit << ')' << std::endl;
63  }
64 #endif
65  }
66 };
67 
69 {
70 public:
71  StoringTimer (int);
72  void ref ();
73  void check (int);
74 #ifndef NDEBUG
75  void dump (std::string const &);
76 #endif
77 
78 private:
80  int* _point;
83  int _points;
85 };
86 
87 #ifdef PT_TIMING
88 extern StoringTimer ST;
89 #define PT_TIMING_REF ST.ref();
90 #define PT_TIMING_CHECK(x) ST.check(x);
91 #endif
92 
93 #ifndef PT_TIMING
94 #define PT_TIMING_REF
95 #define PT_TIMING_CHECK(x)
96 #endif
97 
98 #endif /* __ardour_cycle_timer_h__ */
float get_mhz()
static float cycles_per_usec
CycleTimer(const std::string &name)
void check(int)
void dump(std::string const &)
static cycles_t get_cycles(void)
Definition: cycles.h:245
long cycles_t
Definition: cycles.h:243
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
#define DEBUG_ENABLED(bits)
DebugBits CycleTimers