Move get_exec_time() to debug.{c,h}.
authorLaurent Monin <geeqie@norz.org>
Thu, 24 Apr 2008 09:43:23 +0000 (09:43 +0000)
committerLaurent Monin <geeqie@norz.org>
Thu, 24 Apr 2008 09:43:23 +0000 (09:43 +0000)
src/debug.c
src/debug.h
src/main.c
src/main.h

index a12cc30..92aa2f0 100644 (file)
@@ -37,4 +37,64 @@ gint required_debug_level(gint level)
        return (debug_level >= level);
 }
 
+static gint timeval_delta(struct timeval *result, struct timeval *x, struct timeval *y)
+{
+       if (x->tv_usec < y->tv_usec)
+               {
+               gint nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
+               y->tv_usec -= 1000000 * nsec;
+               y->tv_sec += nsec;
+               }
+
+       if (x->tv_usec - y->tv_usec > 1000000)
+               {
+               gint nsec = (x->tv_usec - y->tv_usec) / 1000000;
+               y->tv_usec += 1000000 * nsec;
+               y->tv_sec -= nsec;
+       }
+
+       result->tv_sec = x->tv_sec - y->tv_sec;
+       result->tv_usec = x->tv_usec - y->tv_usec;
+
+       return x->tv_sec < y->tv_sec;
+}
+
+const gchar *get_exec_time(void)
+{
+       static gchar timestr[30];
+       static struct timeval start_tv = {0, 0};
+       static struct timeval previous = {0, 0};
+       static gint started = 0;
+
+       struct timeval tv = {0, 0};
+       static struct timeval delta = {0, 0};
+
+       gettimeofday(&tv, NULL);
+
+       if (start_tv.tv_sec == 0) start_tv = tv;
+
+       tv.tv_sec -= start_tv.tv_sec;
+       if (tv.tv_usec >= start_tv.tv_usec)
+               tv.tv_usec -= start_tv.tv_usec;
+       else
+               {
+               tv.tv_usec += 1000000 - start_tv.tv_usec;
+               tv.tv_sec -= 1;
+               }
+
+       if (started) timeval_delta(&delta, &tv, &previous);
+
+       previous = tv;
+       started = 1;
+
+       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);
+
+       return timestr;
+}
+
+void init_exec_time(void)
+{
+       get_exec_time();
+}
+
 #endif
index d5aae8b..f413b21 100644 (file)
@@ -27,6 +27,8 @@ gint get_debug_level(void);
 void set_debug_level(gint new_level);
 void debug_level_add(gint delta);
 gint required_debug_level(gint level);
+const gchar *get_exec_time(void);
+void init_exec_time(void);
 
 #define DEBUG_N(n, ...) do \
                                { \
@@ -38,15 +40,19 @@ gint required_debug_level(gint level);
                                        putchar('\n'); \
                                        } \
                                } while (0)
-#else
+
+#else /* DEBUG */
 
 #define get_debug_level() (0)
 #define set_debug_level(new_level) do { } while(0)
 #define debug_level_add(delta) do { } while(0)
 #define required_debug_level(level) (0)
+#define get_exec_time() ""
+#define init_exec_time() do { } while(0)
+
 #define DEBUG_N(n, ...)  do { } while(0)
 
-#endif
+#endif /* DEBUG */
 
 #define DEBUG_0(...) DEBUG_N(0, __VA_ARGS__)
 #define DEBUG_1(...) DEBUG_N(1, __VA_ARGS__)
index ee20132..b27d5c9 100644 (file)
@@ -119,60 +119,6 @@ gdouble get_zoom_increment(void)
        return ((options->image.zoom_increment != 0) ? (gdouble)options->image.zoom_increment / 10.0 : 1.0);
 }
 
-static gint timeval_delta(struct timeval *result, struct timeval *x, struct timeval *y)
-{
-       if (x->tv_usec < y->tv_usec)
-               {
-               gint nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
-               y->tv_usec -= 1000000 * nsec;
-               y->tv_sec += nsec;
-               }
-
-       if (x->tv_usec - y->tv_usec > 1000000)
-               {
-               gint nsec = (x->tv_usec - y->tv_usec) / 1000000;
-               y->tv_usec += 1000000 * nsec;
-               y->tv_sec -= nsec;
-       }
-
-       result->tv_sec = x->tv_sec - y->tv_sec;
-       result->tv_usec = x->tv_usec - y->tv_usec;
-
-       return x->tv_sec < y->tv_sec;
-}
-
-const gchar *get_exec_time()
-{
-       static gchar timestr[30];
-       static struct timeval start_tv = {0, 0};
-       static struct timeval previous = {0, 0};
-       static gint started = 0;
-
-       struct timeval tv = {0, 0};
-       static struct timeval delta = {0, 0};
-
-       gettimeofday(&tv, NULL);
-
-       if (start_tv.tv_sec == 0) start_tv = tv;
-
-       tv.tv_sec -= start_tv.tv_sec;
-       if (tv.tv_usec >= start_tv.tv_usec)
-               tv.tv_usec -= start_tv.tv_usec;
-       else
-               {
-               tv.tv_usec += 1000000 - start_tv.tv_usec;
-               tv.tv_sec -= 1;
-               }
-
-       if (started) timeval_delta(&delta, &tv, &previous);
-
-       previous = tv;
-       started = 1;
-
-       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);
-
-       return timestr;
-}
 
 /*
  *-----------------------------------------------------------------------------
@@ -1372,8 +1318,8 @@ int main (int argc, char *argv[])
        gchar *buf;
        gchar *bufl;
 
-       /* init execution time counter*/
-       get_exec_time();
+       /* init execution time counter (debug only) */
+       init_exec_time();
 
        /* setup locale, i18n */
        gtk_set_locale();
index 8d9e79d..5d3754e 100644 (file)
@@ -131,8 +131,6 @@ gint window_maximized(GtkWidget *window);
 
 gdouble get_zoom_increment(void);
 
-const gchar *get_exec_time();
-
 void help_window_show(const gchar *key);
 
 void keyboard_scroll_calc(gint *x, gint *y, GdkEventKey *event);