merge with master and fix 2 conflicts
[ardour.git] / libs / canvas / debug.cc
1 /*
2     Copyright (C) 2011-2013 Paul Davis
3     Author: Carl Hetherington <cth@carlh.net>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <sys/time.h>
21 #include <iostream>
22 #include "canvas/debug.h"
23
24 using namespace std;
25
26 uint64_t PBD::DEBUG::CanvasItems = PBD::new_debug_bit ("canvasitems");
27 uint64_t PBD::DEBUG::CanvasItemsDirtied = PBD::new_debug_bit ("canvasitemsdirtied");
28 uint64_t PBD::DEBUG::CanvasEvents = PBD::new_debug_bit ("canvasevents");
29 uint64_t PBD::DEBUG::CanvasRender = PBD::new_debug_bit ("canvasrender");
30
31 struct timeval ArdourCanvas::epoch;
32 map<string, struct timeval> ArdourCanvas::last_time;
33 int ArdourCanvas::render_count;
34 int ArdourCanvas::render_depth;
35 int ArdourCanvas::dump_depth;
36
37 void
38 ArdourCanvas::set_epoch ()
39 {
40         gettimeofday (&epoch, 0);
41 }
42
43 void
44 ArdourCanvas::checkpoint (string group, string message)
45 {
46         struct timeval now;
47         gettimeofday (&now, 0);
48
49         now.tv_sec -= epoch.tv_sec;
50         now.tv_usec -= epoch.tv_usec;
51         if (now.tv_usec < 0) {
52                 now.tv_usec += 1e6;
53                 --now.tv_sec;
54         }
55                 
56         map<string, struct timeval>::iterator last = last_time.find (group);
57
58         if (last != last_time.end ()) {
59                 time_t seconds = now.tv_sec - last->second.tv_sec;
60                 suseconds_t useconds = now.tv_usec - last->second.tv_usec;
61                 if (useconds < 0) {
62                         useconds += 1e6;
63                         --seconds;
64                 }
65                 cout << (now.tv_sec + ((double) now.tv_usec / 1e6)) << " [" << (seconds + ((double) useconds / 1e6)) << "]: " << message << "\n";
66         } else {
67                 cout << message << "\n";
68         }
69
70         last_time[group] = now;
71 }
72