Mercurial > geeqie.yaz
annotate src/debug.c @ 678:6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
author | zas_ |
---|---|
date | Sat, 17 May 2008 21:26:45 +0000 |
parents | fbebf5cf4a55 |
children | bbe9cef644f8 |
rev | line source |
---|---|
507 | 1 /* |
2 * Geeqie | |
3 * Copyright (C) 2008 The Geeqie Team | |
4 * | |
5 * Authors: Vladimir Nadvornik, Laurent Monin | |
6 * | |
7 * This software is released under the GNU General Public License (GNU GPL). | |
8 * Please read the included file COPYING for more information. | |
9 * This software comes with no warranty of any kind, use at your own risk! | |
10 */ | |
11 | |
12 #include "main.h" | |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
673
diff
changeset
|
13 #include "debug.h" |
507 | 14 |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
673
diff
changeset
|
15 #include "logwindow.h" |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
16 |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
17 /* |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
18 * Logging functions |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
19 */ |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
20 |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
21 gint log_domain_printf(const char *domain, const gchar *format, ...) |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
22 { |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
23 va_list ap; |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
24 gchar buf[4096]; |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
25 gint ret; |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
26 |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
27 va_start(ap, format); |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
28 ret = vsnprintf(buf, sizeof(buf), format, ap); |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
29 va_end(ap); |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
30 |
678
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
673
diff
changeset
|
31 printf("%s", buf); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
673
diff
changeset
|
32 if (strcmp(domain, DOMAIN_INFO) == 0) |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
673
diff
changeset
|
33 log_window_append(buf, LOG_NORMAL); |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
673
diff
changeset
|
34 else |
6d6f042b8ca5
Add a log window that shows normal and debug messages. For now, it was added to Help menu.
zas_
parents:
673
diff
changeset
|
35 log_window_append(buf, LOG_MSG); |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
36 |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
37 return ret; |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
38 } |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
39 |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
40 |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
41 /* |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
42 * Debugging only functions |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
43 */ |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
44 |
507 | 45 #ifdef DEBUG |
46 | |
47 static gint debug_level = DEBUG_LEVEL_MIN; | |
48 | |
49 | |
50 gint get_debug_level(void) | |
51 { | |
52 return debug_level; | |
53 } | |
54 | |
55 void set_debug_level(gint new_level) | |
56 { | |
57 debug_level = CLAMP(new_level, DEBUG_LEVEL_MIN, DEBUG_LEVEL_MAX); | |
58 } | |
59 | |
60 void debug_level_add(gint delta) | |
61 { | |
62 set_debug_level(debug_level + delta); | |
63 } | |
64 | |
65 gint required_debug_level(gint level) | |
66 { | |
67 return (debug_level >= level); | |
68 } | |
69 | |
509 | 70 static gint timeval_delta(struct timeval *result, struct timeval *x, struct timeval *y) |
71 { | |
72 if (x->tv_usec < y->tv_usec) | |
73 { | |
74 gint nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1; | |
75 y->tv_usec -= 1000000 * nsec; | |
76 y->tv_sec += nsec; | |
77 } | |
78 | |
79 if (x->tv_usec - y->tv_usec > 1000000) | |
80 { | |
81 gint nsec = (x->tv_usec - y->tv_usec) / 1000000; | |
82 y->tv_usec += 1000000 * nsec; | |
83 y->tv_sec -= nsec; | |
84 } | |
85 | |
86 result->tv_sec = x->tv_sec - y->tv_sec; | |
87 result->tv_usec = x->tv_usec - y->tv_usec; | |
88 | |
89 return x->tv_sec < y->tv_sec; | |
90 } | |
91 | |
92 const gchar *get_exec_time(void) | |
93 { | |
94 static gchar timestr[30]; | |
95 static struct timeval start_tv = {0, 0}; | |
96 static struct timeval previous = {0, 0}; | |
97 static gint started = 0; | |
98 | |
99 struct timeval tv = {0, 0}; | |
100 static struct timeval delta = {0, 0}; | |
101 | |
102 gettimeofday(&tv, NULL); | |
103 | |
104 if (start_tv.tv_sec == 0) start_tv = tv; | |
105 | |
106 tv.tv_sec -= start_tv.tv_sec; | |
107 if (tv.tv_usec >= start_tv.tv_usec) | |
108 tv.tv_usec -= start_tv.tv_usec; | |
109 else | |
110 { | |
111 tv.tv_usec += 1000000 - start_tv.tv_usec; | |
112 tv.tv_sec -= 1; | |
113 } | |
114 | |
115 if (started) timeval_delta(&delta, &tv, &previous); | |
116 | |
117 previous = tv; | |
118 started = 1; | |
119 | |
120 g_snprintf(timestr, sizeof(timestr), "%5d.%06d (+%05d.%06d)", (int)tv.tv_sec, (int)tv.tv_usec, (int)delta.tv_sec, (int)delta.tv_usec); | |
121 | |
122 return timestr; | |
123 } | |
124 | |
125 void init_exec_time(void) | |
126 { | |
127 get_exec_time(); | |
128 } | |
129 | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
130 #endif /* DEBUG */ |