3 * Copyright (C) 2008 - 2012 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>
24 static gboolean log_msg_cb(gpointer data)
27 log_window_append(buf, LOG_MSG);
32 static gboolean log_normal_cb(gpointer data)
35 log_window_append(buf, LOG_NORMAL);
40 void log_domain_printf(const gchar *domain, const gchar *format, ...)
46 buf = g_strdup_vprintf(format, ap);
50 if (strcmp(domain, DOMAIN_INFO) == 0)
51 g_idle_add(log_normal_cb, buf);
53 g_idle_add(log_msg_cb, buf);
58 * Debugging only functions
63 static gint debug_level = DEBUG_LEVEL_MIN;
66 gint get_debug_level(void)
71 void set_debug_level(gint new_level)
73 debug_level = CLAMP(new_level, DEBUG_LEVEL_MIN, DEBUG_LEVEL_MAX);
76 void debug_level_add(gint delta)
78 set_debug_level(debug_level + delta);
81 gint required_debug_level(gint level)
83 return (debug_level >= level);
86 static gint timeval_delta(struct timeval *result, struct timeval *x, struct timeval *y)
88 if (x->tv_usec < y->tv_usec)
90 gint nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
91 y->tv_usec -= 1000000 * nsec;
95 if (x->tv_usec - y->tv_usec > 1000000)
97 gint nsec = (x->tv_usec - y->tv_usec) / 1000000;
98 y->tv_usec += 1000000 * nsec;
102 result->tv_sec = x->tv_sec - y->tv_sec;
103 result->tv_usec = x->tv_usec - y->tv_usec;
105 return x->tv_sec < y->tv_sec;
108 const gchar *get_exec_time(void)
110 static gchar timestr[30];
111 static struct timeval start_tv = {0, 0};
112 static struct timeval previous = {0, 0};
113 static gint started = 0;
115 struct timeval tv = {0, 0};
116 static struct timeval delta = {0, 0};
118 gettimeofday(&tv, NULL);
120 if (start_tv.tv_sec == 0) start_tv = tv;
122 tv.tv_sec -= start_tv.tv_sec;
123 if (tv.tv_usec >= start_tv.tv_usec)
124 tv.tv_usec -= start_tv.tv_usec;
127 tv.tv_usec += 1000000 - start_tv.tv_usec;
131 if (started) timeval_delta(&delta, &tv, &previous);
136 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);
141 void init_exec_time(void)
147 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */