merge with master, with minor conflict fixes
[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 <gdk/gdk.h>
23 #include "canvas/debug.h"
24
25 using namespace std;
26
27 uint64_t PBD::DEBUG::CanvasItems = PBD::new_debug_bit ("canvasitems");
28 uint64_t PBD::DEBUG::CanvasItemsDirtied = PBD::new_debug_bit ("canvasitemsdirtied");
29 uint64_t PBD::DEBUG::CanvasEvents = PBD::new_debug_bit ("canvasevents");
30 uint64_t PBD::DEBUG::CanvasRender = PBD::new_debug_bit ("canvasrender");
31
32 struct timeval ArdourCanvas::epoch;
33 map<string, struct timeval> ArdourCanvas::last_time;
34 int ArdourCanvas::render_count;
35 int ArdourCanvas::render_depth;
36 int ArdourCanvas::dump_depth;
37
38 void
39 ArdourCanvas::set_epoch ()
40 {
41         gettimeofday (&epoch, 0);
42 }
43
44 void
45 ArdourCanvas::checkpoint (string group, string message)
46 {
47         struct timeval now;
48         gettimeofday (&now, 0);
49
50         now.tv_sec -= epoch.tv_sec;
51         now.tv_usec -= epoch.tv_usec;
52         if (now.tv_usec < 0) {
53                 now.tv_usec += 1e6;
54                 --now.tv_sec;
55         }
56                 
57         map<string, struct timeval>::iterator last = last_time.find (group);
58
59         if (last != last_time.end ()) {
60                 time_t seconds = now.tv_sec - last->second.tv_sec;
61                 suseconds_t useconds = now.tv_usec - last->second.tv_usec;
62                 if (useconds < 0) {
63                         useconds += 1e6;
64                         --seconds;
65                 }
66                 cout << (now.tv_sec + ((double) now.tv_usec / 1e6)) << " [" << (seconds + ((double) useconds / 1e6)) << "]: " << message << "\n";
67         } else {
68                 cout << message << "\n";
69         }
70
71         last_time[group] = now;
72 }
73
74 const char*
75 ArdourCanvas::event_type_string (int event_type)
76 {
77         switch (event_type) {
78         case GDK_NOTHING:
79                 return "nothing";
80         case GDK_DELETE:
81                 return "delete";
82         case GDK_DESTROY:
83                 return "destroy";
84         case GDK_EXPOSE:
85                 return "expose";
86         case GDK_MOTION_NOTIFY:
87                 return "motion_notify";
88         case GDK_BUTTON_PRESS:
89                 return "button_press";
90         case GDK_2BUTTON_PRESS:
91                 return "2button_press";
92         case GDK_3BUTTON_PRESS:
93                 return "3button_press";
94         case GDK_BUTTON_RELEASE:
95                 return "button_release";
96         case GDK_KEY_PRESS:
97                 return "key_press";
98         case GDK_KEY_RELEASE:
99                 return "key_release";
100         case GDK_ENTER_NOTIFY:
101                 return "enter_notify";
102         case GDK_LEAVE_NOTIFY:
103                 return "leave_notify";
104         case GDK_FOCUS_CHANGE:
105                 return "focus_change";
106         case GDK_CONFIGURE:
107                 return "configure";
108         case GDK_MAP:
109                 return "map";
110         case GDK_UNMAP:
111                 return "unmap";
112         case GDK_PROPERTY_NOTIFY:
113                 return "property_notify";
114         case GDK_SELECTION_CLEAR:
115                 return "selection_clear";
116         case GDK_SELECTION_REQUEST:
117                 return "selection_request";
118         case GDK_SELECTION_NOTIFY:
119                 return "selection_notify";
120         case GDK_PROXIMITY_IN:
121                 return "proximity_in";
122         case GDK_PROXIMITY_OUT:
123                 return "proximity_out";
124         case GDK_DRAG_ENTER:
125                 return "drag_enter";
126         case GDK_DRAG_LEAVE:
127                 return "drag_leave";
128         case GDK_DRAG_MOTION:
129                 return "drag_motion";
130         case GDK_DRAG_STATUS:
131                 return "drag_status";
132         case GDK_DROP_START:
133                 return "drop_start";
134         case GDK_DROP_FINISHED:
135                 return "drop_finished";
136         case GDK_CLIENT_EVENT:
137                 return "client_event";
138         case GDK_VISIBILITY_NOTIFY:
139                 return "visibility_notify";
140         case GDK_NO_EXPOSE:
141                 return "no_expose";
142         case GDK_SCROLL:
143                 return "scroll";
144         case GDK_WINDOW_STATE:
145                 return "window_state";
146         case GDK_SETTING:
147                 return "setting";
148         case GDK_OWNER_CHANGE:
149                 return "owner_change";
150         case GDK_GRAB_BROKEN:
151                 return "grab_broken";
152         case GDK_DAMAGE:
153                 return "damage";
154         }
155
156         return "unknown";
157 }