summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrbuj <[email protected]>2020-11-12 12:58:25 +0100
committerraveit65 <[email protected]>2022-07-21 19:33:49 +0200
commit448390c4c0a78a792da6e699900eef945a20895b (patch)
tree47f256052b8d97daa3719196fd3c952ef020253e
parenta7431f985b56240ce4947b31507c9a31cd66821c (diff)
downloadcaja-448390c4c0a78a792da6e699900eef945a20895b.tar.bz2
caja-448390c4c0a78a792da6e699900eef945a20895b.tar.xz
Remove the use of the gettimeofday function
-rw-r--r--libcaja-private/caja-debug-log.c27
-rw-r--r--test/test-eel-pixbuf-scale.c26
2 files changed, 36 insertions, 17 deletions
diff --git a/libcaja-private/caja-debug-log.c b/libcaja-private/caja-debug-log.c
index 646e7f66..d872f91d 100644
--- a/libcaja-private/caja-debug-log.c
+++ b/libcaja-private/caja-debug-log.c
@@ -25,11 +25,14 @@
#include <errno.h>
#include <stdio.h>
#include <string.h>
-#include <time.h>
-#include <sys/time.h>
#include "caja-debug-log.h"
#include "caja-file.h"
+#if !GLIB_CHECK_VERSION(2,65,2)
+#include <time.h>
+#include <sys/time.h>
+#endif
+
#define DEFAULT_RING_BUFFER_NUM_LINES 1000
#define KEY_FILE_GROUP "debug log"
@@ -151,8 +154,13 @@ caja_debug_logv (gboolean is_milestone, const char *domain, const GList *uris, c
{
char *str;
char *debug_str;
+#if GLIB_CHECK_VERSION(2,65,2)
+ char *date_str;
+ GDateTime* datetime;
+#else
struct timeval tv;
struct tm tm;
+#endif
lock ();
@@ -160,10 +168,20 @@ caja_debug_logv (gboolean is_milestone, const char *domain, const GList *uris, c
goto out;
str = g_strdup_vprintf (format, args);
- gettimeofday (&tv, NULL);
+#if GLIB_CHECK_VERSION(2,65,2)
+ datetime = g_date_time_new_now_local ();
+ date_str = g_date_time_format (datetime, "%Y/%m/%d %H:%M:%S.%f");
+ g_date_time_unref (datetime);
+ debug_str = g_strdup_printf ("%p %s (%s): %s",
+ g_thread_self (),
+ date_str,
+ domain,
+ str);
+ g_free (date_str);
+#else
+ gettimeofday (&tv, NULL);
tm = *localtime (&tv.tv_sec);
-
debug_str = g_strdup_printf ("%p %04d/%02d/%02d %02d:%02d:%02d.%04d (%s): %s",
g_thread_self (),
tm.tm_year + 1900,
@@ -175,6 +193,7 @@ caja_debug_logv (gboolean is_milestone, const char *domain, const GList *uris, c
(int) (tv.tv_usec / 100),
domain,
str);
+#endif
g_free (str);
if (uris)
diff --git a/test/test-eel-pixbuf-scale.c b/test/test-eel-pixbuf-scale.c
index bace672d..5524b354 100644
--- a/test/test-eel-pixbuf-scale.c
+++ b/test/test-eel-pixbuf-scale.c
@@ -14,7 +14,7 @@ main (int argc, char* argv[])
{
GdkPixbuf *pixbuf, *scaled;
GError *error;
- struct timeval t1, t2;
+ gint64 t1, t2;
int i;
test_init (&argc, &argv);
@@ -36,35 +36,35 @@ main (int argc, char* argv[])
(double)gdk_pixbuf_get_width(pixbuf)/DEST_WIDTH,
(double)gdk_pixbuf_get_height(pixbuf)/DEST_HEIGHT);
- gettimeofday(&t1, NULL);
+ t1 = g_get_monotonic_time ();
for (i = 0; i < N_SCALES; i++) {
scaled = eel_gdk_pixbuf_scale_down (pixbuf, DEST_WIDTH, DEST_HEIGHT);
g_object_unref (scaled);
}
- gettimeofday(&t2, NULL);
- g_print ("Time for eel_gdk_pixbuf_scale_down: %ld msecs\n",
- (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec) / 1000);
+ t2 = g_get_monotonic_time ();
+ g_print ("Time for eel_gdk_pixbuf_scale_down: %" G_GINT64_FORMAT " msecs\n",
+ (t2 - t1) / G_TIME_SPAN_MILLISECOND);
- gettimeofday(&t1, NULL);
+ t1 = g_get_monotonic_time ();
for (i = 0; i < N_SCALES; i++) {
scaled = gdk_pixbuf_scale_simple (pixbuf, DEST_WIDTH, DEST_HEIGHT, GDK_INTERP_NEAREST);
g_object_unref (scaled);
}
- gettimeofday(&t2, NULL);
- g_print ("Time for INTERP_NEAREST: %ld msecs\n",
- (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec) / 1000);
+ t2 = g_get_monotonic_time ();
+ g_print ("Time for INTERP_NEAREST: %" G_GINT64_FORMAT " msecs\n",
+ (t2 - t1) / G_TIME_SPAN_MILLISECOND);
- gettimeofday(&t1, NULL);
+ t1 = g_get_monotonic_time ();
for (i = 0; i < N_SCALES; i++) {
scaled = gdk_pixbuf_scale_simple (pixbuf, DEST_WIDTH, DEST_HEIGHT, GDK_INTERP_BILINEAR);
g_object_unref (scaled);
}
- gettimeofday(&t2, NULL);
- g_print ("Time for INTERP_BILINEAR: %ld msecs\n",
- (t2.tv_sec - t1.tv_sec) * 1000 + (t2.tv_usec - t1.tv_usec) / 1000);
+ t2 = g_get_monotonic_time ();
+ g_print ("Time for INTERP_BILINEAR: %" G_GINT64_FORMAT " msecs\n",
+ (t2 - t1) / G_TIME_SPAN_MILLISECOND);
scaled = eel_gdk_pixbuf_scale_down (pixbuf, DEST_WIDTH, DEST_HEIGHT);
gdk_pixbuf_save (scaled, "eel_scaled.png", "png", NULL, NULL);