18ff40f8f70a3cba5f22c81b5d7c5406a036caa6
[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
15 void
16 ArdourCanvas::set_epoch ()
17 {
18         gettimeofday (&epoch, 0);
19 }
20
21 void
22 ArdourCanvas::checkpoint (string group, string message)
23 {
24         struct timeval now;
25         gettimeofday (&now, 0);
26
27         now.tv_sec -= epoch.tv_sec;
28         now.tv_usec -= epoch.tv_usec;
29         if (now.tv_usec < 0) {
30                 now.tv_usec += 1e6;
31                 --now.tv_sec;
32         }
33                 
34         map<string, struct timeval>::iterator last = last_time.find (group);
35
36         if (last != last_time.end ()) {
37                 time_t seconds = now.tv_sec - last->second.tv_sec;
38                 suseconds_t useconds = now.tv_usec - last->second.tv_usec;
39                 if (useconds < 0) {
40                         useconds += 1e6;
41                         --seconds;
42                 }
43                 cout << (now.tv_sec + ((double) now.tv_usec / 1e6)) << " [" << (seconds + ((double) useconds / 1e6)) << "]: " << message << "\n";
44         } else {
45                 cout << message << "\n";
46         }
47
48         last_time[group] = now;
49 }
50