annotate src/debug.c @ 521:57007e49d767

Do not allow to add anything but directories to sort bar in folder mode through drag'n'drop. Introduce a new field only_directories to _BookMarkData struct.
author zas_
date Thu, 24 Apr 2008 20:18:59 +0000
parents b78a91d0779e
children 8268cbe682f1
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
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
3 * Copyright (C) 2008 The Geeqie Team
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"
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
13 #include "debug.h"
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
14
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
15 #ifdef DEBUG
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
16
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
17 static gint debug_level = DEBUG_LEVEL_MIN;
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
18
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
19
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
20 gint get_debug_level(void)
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
21 {
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
22 return debug_level;
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
23 }
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
24
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
25 void set_debug_level(gint new_level)
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
26 {
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
27 debug_level = CLAMP(new_level, DEBUG_LEVEL_MIN, DEBUG_LEVEL_MAX);
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
28 }
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
29
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
30 void debug_level_add(gint delta)
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
31 {
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
32 set_debug_level(debug_level + delta);
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
33 }
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
34
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
35 gint required_debug_level(gint level)
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
36 {
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
37 return (debug_level >= level);
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
38 }
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
39
509
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
40 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
41 {
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
42 if (x->tv_usec < y->tv_usec)
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
43 {
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
44 gint nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
45 y->tv_usec -= 1000000 * nsec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
46 y->tv_sec += nsec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
47 }
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
48
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
49 if (x->tv_usec - y->tv_usec > 1000000)
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
50 {
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
51 gint nsec = (x->tv_usec - y->tv_usec) / 1000000;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
52 y->tv_usec += 1000000 * nsec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
53 y->tv_sec -= nsec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
54 }
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
55
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
56 result->tv_sec = x->tv_sec - y->tv_sec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
57 result->tv_usec = x->tv_usec - y->tv_usec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
58
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
59 return x->tv_sec < y->tv_sec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
60 }
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
61
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
62 const gchar *get_exec_time(void)
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
63 {
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
64 static gchar timestr[30];
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
65 static struct timeval start_tv = {0, 0};
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
66 static struct timeval previous = {0, 0};
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
67 static gint started = 0;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
68
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
69 struct timeval tv = {0, 0};
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
70 static struct timeval delta = {0, 0};
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
71
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
72 gettimeofday(&tv, NULL);
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
73
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
74 if (start_tv.tv_sec == 0) start_tv = tv;
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 tv.tv_sec -= start_tv.tv_sec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
77 if (tv.tv_usec >= start_tv.tv_usec)
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
78 tv.tv_usec -= start_tv.tv_usec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
79 else
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
80 {
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
81 tv.tv_usec += 1000000 - start_tv.tv_usec;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
82 tv.tv_sec -= 1;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
83 }
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 if (started) timeval_delta(&delta, &tv, &previous);
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
86
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
87 previous = tv;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
88 started = 1;
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 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);
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
91
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
92 return timestr;
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
93 }
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 void init_exec_time(void)
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
96 {
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
97 get_exec_time();
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
98 }
b78a91d0779e Move get_exec_time() to debug.{c,h}.
zas_
parents: 507
diff changeset
99
507
135570a8bd96 Move debug macros from main.h to new debug.h.
zas_
parents:
diff changeset
100 #endif