annotate src/debug.c @ 1661:28863300018a

German translation update
author mow
date Sat, 27 Jun 2009 22:58:20 +0000
parents 2abdd6e50120
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
507
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
1 /*
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
2 * Geeqie
1284
8b89e3ff286b Add year 2009 to copyright info everywhere.
zas_
parents: 1055
diff changeset
3 * Copyright (C) 2008 - 2009 The Geeqie Team
507
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
4 *
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
5 * Authors: Vladimir Nadvornik, Laurent Monin
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
6 *
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
7 * This software is released under the GNU General Public License (GNU GPL).
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
8 * Please read the included file COPYING for more information.
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
9 * This software comes with no warranty of any kind, use at your own risk!
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
10 */
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
11
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
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
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
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
1305
2abdd6e50120 Glibification.
zas_
parents: 1284
diff changeset
18 #include <glib/gprintf.h>
2abdd6e50120 Glibification.
zas_
parents: 1284
diff changeset
19
2abdd6e50120 Glibification.
zas_
parents: 1284
diff changeset
20
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
21 /*
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
22 * Logging functions
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
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 995
diff changeset
25 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
26 {
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
27 va_list ap;
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
28 gchar buf[4096];
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
29 gint ret;
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
30
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
31 va_start(ap, format);
1305
2abdd6e50120 Glibification.
zas_
parents: 1284
diff changeset
32 ret = g_vsnprintf(buf, sizeof(buf), format, ap);
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
33 va_end(ap);
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
34
693
bbe9cef644f8 Use print_term() instead of printf(), since it handles charset conversion
zas_
parents: 678
diff changeset
35 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
36 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
37 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
38 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
39 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
40
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
41 return ret;
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
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 /*
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
46 * Debugging only functions
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
47 */
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
48
507
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
49 #ifdef DEBUG
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
50
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
51 static gint debug_level = DEBUG_LEVEL_MIN;
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
52
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
53
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
54 gint get_debug_level(void)
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
55 {
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
56 return debug_level;
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
57 }
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
58
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
59 void set_debug_level(gint new_level)
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
60 {
995
6ca2c5fd7b13 Whitespaces cleanup.
zas_
parents: 693
diff changeset
61 debug_level = CLAMP(new_level, DEBUG_LEVEL_MIN, DEBUG_LEVEL_MAX);
507
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
62 }
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
63
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
64 void debug_level_add(gint delta)
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
65 {
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
66 set_debug_level(debug_level + delta);
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
67 }
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
68
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
69 gint required_debug_level(gint level)
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
70 {
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
71 return (debug_level >= level);
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
72 }
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
73
509
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
74 static gint timeval_delta(struct timeval *result, struct timeval *x, struct timeval *y)
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
75 {
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
76 if (x->tv_usec < y->tv_usec)
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
77 {
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
78 gint nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
79 y->tv_usec -= 1000000 * nsec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
80 y->tv_sec += nsec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
81 }
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
82
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
83 if (x->tv_usec - y->tv_usec > 1000000)
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
84 {
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
85 gint nsec = (x->tv_usec - y->tv_usec) / 1000000;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
86 y->tv_usec += 1000000 * nsec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
87 y->tv_sec -= nsec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
88 }
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
89
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
90 result->tv_sec = x->tv_sec - y->tv_sec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
91 result->tv_usec = x->tv_usec - y->tv_usec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
92
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
93 return x->tv_sec < y->tv_sec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
94 }
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
95
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
96 const gchar *get_exec_time(void)
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
97 {
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
98 static gchar timestr[30];
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
99 static struct timeval start_tv = {0, 0};
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
100 static struct timeval previous = {0, 0};
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
101 static gint started = 0;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
102
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
103 struct timeval tv = {0, 0};
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
104 static struct timeval delta = {0, 0};
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
105
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
106 gettimeofday(&tv, NULL);
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
107
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
108 if (start_tv.tv_sec == 0) start_tv = tv;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
109
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
110 tv.tv_sec -= start_tv.tv_sec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
111 if (tv.tv_usec >= start_tv.tv_usec)
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
112 tv.tv_usec -= start_tv.tv_usec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
113 else
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
114 {
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
115 tv.tv_usec += 1000000 - start_tv.tv_usec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
116 tv.tv_sec -= 1;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
117 }
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
118
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
119 if (started) timeval_delta(&delta, &tv, &previous);
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
120
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
121 previous = tv;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
122 started = 1;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
123
1000
4fe8f9656107 For the sake of consistency, use glib basic types everywhere.
zas_
parents: 995
diff changeset
124 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
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
125
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
126 return timestr;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
127 }
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
128
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
129 void init_exec_time(void)
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
130 {
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
131 get_exec_time();
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
132 }
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
133
673
fbebf5cf4a55 Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents: 671
diff changeset
134 #endif /* DEBUG */
1055
1646720364cf Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents: 1000
diff changeset
135 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */