3 * Copyright (C) 2008 - 2010 The Geeqie Team
5 * Authors: Vladimir Nadvornik, Laurent Monin
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!
15 #include "logwindow.h"
16 #include "ui_fileops.h"
18 #include <glib/gprintf.h>
25 gint log_domain_printf(const gchar *domain, const gchar *format, ...)
32 ret = g_vsnprintf(buf, sizeof(buf), format, ap);
36 if (strcmp(domain, DOMAIN_INFO) == 0)
37 log_window_append(buf, LOG_NORMAL);
39 log_window_append(buf, LOG_MSG);
46 * Debugging only functions
51 static gint debug_level = DEBUG_LEVEL_MIN;
54 gint get_debug_level(void)
59 void set_debug_level(gint new_level)
61 debug_level = CLAMP(new_level, DEBUG_LEVEL_MIN, DEBUG_LEVEL_MAX);
64 void debug_level_add(gint delta)
66 set_debug_level(debug_level + delta);
69 gint required_debug_level(gint level)
71 return (debug_level >= level);
74 static gint timeval_delta(struct timeval *result, struct timeval *x, struct timeval *y)
76 if (x->tv_usec < y->tv_usec)
78 gint nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
79 y->tv_usec -= 1000000 * nsec;
83 if (x->tv_usec - y->tv_usec > 1000000)
85 gint nsec = (x->tv_usec - y->tv_usec) / 1000000;
86 y->tv_usec += 1000000 * nsec;
90 result->tv_sec = x->tv_sec - y->tv_sec;
91 result->tv_usec = x->tv_usec - y->tv_usec;
93 return x->tv_sec < y->tv_sec;
96 const gchar *get_exec_time(void)
98 static gchar timestr[30];
99 static struct timeval start_tv = {0, 0};
100 static struct timeval previous = {0, 0};
101 static gint started = 0;
103 struct timeval tv = {0, 0};
104 static struct timeval delta = {0, 0};
106 gettimeofday(&tv, NULL);
108 if (start_tv.tv_sec == 0) start_tv = tv;
110 tv.tv_sec -= start_tv.tv_sec;
111 if (tv.tv_usec >= start_tv.tv_usec)
112 tv.tv_usec -= start_tv.tv_usec;
115 tv.tv_usec += 1000000 - start_tv.tv_usec;
119 if (started) timeval_delta(&delta, &tv, &previous);
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);
129 void init_exec_time(void)
135 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */