Merge branch 'master' into cairocanvas
[ardour.git] / libs / canvas / debug.cc
1 #include <sys/time.h>
2 #include <iostream>
3 #include "canvas/debug.h"
4
5 using namespace std;
6
7 uint64_t PBD::DEBUG::CanvasItems = PBD::new_debug_bit ("canvasitems");
8 uint64_t PBD::DEBUG::CanvasItemsDirtied = PBD::new_debug_bit ("canvasitemsdirtied");
9 uint64_t PBD::DEBUG::CanvasEvents = PBD::new_debug_bit ("canvasevents");
10
11 struct timeval ArdourCanvas::epoch;
12 map<string, struct timeval> ArdourCanvas::last_time;
13 int ArdourCanvas::render_count;
14 int ArdourCanvas::dump_depth;
15
16 void
17 ArdourCanvas::set_epoch ()
18 {
19         gettimeofday (&epoch, 0);
20 }
21
22 void
23 ArdourCanvas::checkpoint (string group, string message)
24 {
25         struct timeval now;
26         gettimeofday (&now, 0);
27
28         now.tv_sec -= epoch.tv_sec;
29         now.tv_usec -= epoch.tv_usec;
30         if (now.tv_usec < 0) {
31                 now.tv_usec += 1e6;
32                 --now.tv_sec;
33         }
34                 
35         map<string, struct timeval>::iterator last = last_time.find (group);
36
37         if (last != last_time.end ()) {
38                 time_t seconds = now.tv_sec - last->second.tv_sec;
39                 suseconds_t useconds = now.tv_usec - last->second.tv_usec;
40                 if (useconds < 0) {
41                         useconds += 1e6;
42                         --seconds;
43                 }
44                 cout << (now.tv_sec + ((double) now.tv_usec / 1e6)) << " [" << (seconds + ((double) useconds / 1e6)) << "]: " << message << "\n";
45         } else {
46                 cout << message << "\n";
47         }
48
49         last_time[group] = now;
50 }
51