Mercurial > geeqie.yaz
annotate src/debug.c @ 1055:1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
author | nadvornik |
---|---|
date | Tue, 07 Oct 2008 18:20:22 +0000 |
parents | 4fe8f9656107 |
children | 8b89e3ff286b |
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" |
693
bbe9cef644f8
Use print_term() instead of printf(), since it handles charset conversion
zas_
parents:
678
diff
changeset
|
16 #include "ui_fileops.h" |
673
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 /* |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
19 * Logging functions |
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 |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
22 gint log_domain_printf(const gchar *domain, const gchar *format, ...) |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
23 { |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
24 va_list ap; |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
25 gchar buf[4096]; |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
26 gint ret; |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
27 |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
28 va_start(ap, format); |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
29 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
|
30 va_end(ap); |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
31 |
693
bbe9cef644f8
Use print_term() instead of printf(), since it handles charset conversion
zas_
parents:
678
diff
changeset
|
32 print_term(buf); |
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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
38 return ret; |
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 /* |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
43 * Debugging only functions |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
44 */ |
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
45 |
507 | 46 #ifdef DEBUG |
47 | |
48 static gint debug_level = DEBUG_LEVEL_MIN; | |
49 | |
50 | |
51 gint get_debug_level(void) | |
52 { | |
53 return debug_level; | |
54 } | |
55 | |
56 void set_debug_level(gint new_level) | |
57 { | |
995 | 58 debug_level = CLAMP(new_level, DEBUG_LEVEL_MIN, DEBUG_LEVEL_MAX); |
507 | 59 } |
60 | |
61 void debug_level_add(gint delta) | |
62 { | |
63 set_debug_level(debug_level + delta); | |
64 } | |
65 | |
66 gint required_debug_level(gint level) | |
67 { | |
68 return (debug_level >= level); | |
69 } | |
70 | |
509 | 71 static gint timeval_delta(struct timeval *result, struct timeval *x, struct timeval *y) |
72 { | |
73 if (x->tv_usec < y->tv_usec) | |
74 { | |
75 gint nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1; | |
76 y->tv_usec -= 1000000 * nsec; | |
77 y->tv_sec += nsec; | |
78 } | |
79 | |
80 if (x->tv_usec - y->tv_usec > 1000000) | |
81 { | |
82 gint nsec = (x->tv_usec - y->tv_usec) / 1000000; | |
83 y->tv_usec += 1000000 * nsec; | |
84 y->tv_sec -= nsec; | |
85 } | |
86 | |
87 result->tv_sec = x->tv_sec - y->tv_sec; | |
88 result->tv_usec = x->tv_usec - y->tv_usec; | |
89 | |
90 return x->tv_sec < y->tv_sec; | |
91 } | |
92 | |
93 const gchar *get_exec_time(void) | |
94 { | |
95 static gchar timestr[30]; | |
96 static struct timeval start_tv = {0, 0}; | |
97 static struct timeval previous = {0, 0}; | |
98 static gint started = 0; | |
99 | |
100 struct timeval tv = {0, 0}; | |
101 static struct timeval delta = {0, 0}; | |
102 | |
103 gettimeofday(&tv, NULL); | |
104 | |
105 if (start_tv.tv_sec == 0) start_tv = tv; | |
106 | |
107 tv.tv_sec -= start_tv.tv_sec; | |
108 if (tv.tv_usec >= start_tv.tv_usec) | |
109 tv.tv_usec -= start_tv.tv_usec; | |
110 else | |
111 { | |
112 tv.tv_usec += 1000000 - start_tv.tv_usec; | |
113 tv.tv_sec -= 1; | |
114 } | |
115 | |
116 if (started) timeval_delta(&delta, &tv, &previous); | |
117 | |
118 previous = tv; | |
119 started = 1; | |
120 | |
1000
4fe8f9656107
For the sake of consistency, use glib basic types everywhere.
zas_
parents:
995
diff
changeset
|
121 g_snprintf(timestr, sizeof(timestr), "%5d.%06d (+%05d.%06d)", (gint)tv.tv_sec, (gint)tv.tv_usec, (gint)delta.tv_sec, (gint)delta.tv_usec); |
509 | 122 |
123 return timestr; | |
124 } | |
125 | |
126 void init_exec_time(void) | |
127 { | |
128 get_exec_time(); | |
129 } | |
130 | |
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
671
diff
changeset
|
131 #endif /* DEBUG */ |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1000
diff
changeset
|
132 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |