[tracker-miners/sam/debug: 1/4] Add TRACKER_DEBUG environment variable, use for miner fs debug



commit 17f2d9edcf88e0fb5971965418b8201cbfcccb5e
Author: Sam Thursfield <sam afuera me uk>
Date:   Mon Apr 20 02:13:57 2020 +0200

    Add TRACKER_DEBUG environment variable, use for miner fs debug
    
    This works the same as GTK's GTK_DEBUG variable. It will
    allow us to include more types of optional debugging info
    and will make the default debug output more readlable.

 .gitlab-ci.yml                                |  4 ++
 meson.build                                   | 13 ++++++
 src/libtracker-miner/tracker-miner-fs.c       | 56 ++++++++++++++------------
 src/libtracker-miners-common/meson.build      |  1 +
 src/libtracker-miners-common/tracker-common.h |  2 +
 src/libtracker-miners-common/tracker-debug.c  | 57 +++++++++++++++++++++++++++
 src/libtracker-miners-common/tracker-debug.h  | 54 +++++++++++++++++++++++++
 7 files changed, 161 insertions(+), 26 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index da3352fc5..f442a392f 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -4,6 +4,8 @@
 variables:
   # These can be used to see verbose log output from the functional-tests.
   # See HACKING.md for more information.
+  G_MESSAGES_DEBUG: "Tracker"
+  TRACKER_DEBUG: ""
   TRACKER_VERBOSITY: "1"
   TRACKER_TESTS_VERBOSE: "no"
 
@@ -40,6 +42,8 @@ stages:
       echo
       echo "Test suite settings:"
       echo
+      echo "G_MESSAGES_DEBUG: ${G_MESSAGES_DEBUG}"
+      echo "TRACKER_DEBUG: ${TRACKER_DEBUG}"
       echo "TRACKER_VERBOSITY: ${TRACKER_VERBOSITY}"
       echo "TRACKER_TESTS_VERBOSE: ${TRACKER_TESTS_VERBOSE}"
       echo "MESON_TEST_EXTRA_ARGS: ${MESON_TEST_EXTRA_ARGS}"
diff --git a/meson.build b/meson.build
index 04b82d9f7..3d8afa9c9 100644
--- a/meson.build
+++ b/meson.build
@@ -120,6 +120,19 @@ add_project_arguments('-Wno-pointer-sign', language: 'c')
 add_project_arguments('-DTRACKER_COMPILATION', language: 'c')
 add_project_arguments('-DG_LOG_DOMAIN="Tracker"', language: 'c')
 
+debug_cflags = []
+buildtype = get_option('buildtype')
+if buildtype.startswith('debug')
+  debug_cflags += '-DG_ENABLE_DEBUG'
+  if buildtype == 'debug'
+    debug_cflags += '-DG_ENABLE_CONSISTENCY_CHECKS'
+  endif
+elif buildtype == 'release'
+  debug_cflags += '-DG_DISABLE_CAST_CHECKS'
+endif
+
+add_project_arguments(debug_cflags, language: 'c')
+
 ##################################################################
 # Check for libtracker-common: battery/mains power detection
 #
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 24e5c405f..0cd4f3177 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -30,32 +30,6 @@
 #include "tracker-sparql-buffer.h"
 #include "tracker-file-notifier.h"
 
-/* If defined will print push/pop actions on queues */
-#ifdef EVENT_QUEUE_ENABLE_TRACE
-#warning Event Queue traces enabled
-#define EVENT_QUEUE_LOG_PREFIX "[Event Queues] "
-#define EVENT_QUEUE_STATUS_TIMEOUT_SECS 30
-#define trace_eq(message, ...) g_message (EVENT_QUEUE_LOG_PREFIX message, ##__VA_ARGS__)
-#define trace_eq_event(event) \
-       do { \
-               const gchar *event_type_name[] = { "CREATED", "UPDATED", "DELETED", "MOVED" }; \
-               gchar *uri1 = g_file_get_uri (event->file); \
-               gchar *uri2 = event->dest_file ? g_file_get_uri (event->dest_file) : NULL; \
-               g_message ("%s New %s event: %s%s%s%s", \
-                          EVENT_QUEUE_LOG_PREFIX, \
-                          event_type_name[event->type], \
-                          event->attributes_update ? "(attributes only) " : "", \
-                          uri1, \
-                          uri2 ? "->" : "", \
-                          uri2 ? uri2 : ""); \
-               g_free (uri1); \
-               g_free (uri2); \
-       } while (0)
-#else
-#define trace_eq(...)
-#define trace_eq_event(...)
-#endif /* EVENT_QUEUE_ENABLE_TRACE */
-
 /* Default processing pool limits to be set */
 #define DEFAULT_WAIT_POOL_LIMIT 1
 #define DEFAULT_READY_POOL_LIMIT 1
@@ -299,6 +273,36 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (TrackerMinerFS, tracker_miner_fs, TRACKER_TYPE
                                   G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
                                                          miner_fs_initable_iface_init));
 
+/* For TRACKER_DEBUG=miner-fs-events */
+#ifdef G_ENABLE_DEBUG
+#define EVENT_QUEUE_LOG_PREFIX "[Event Queues] "
+#define EVENT_QUEUE_STATUS_TIMEOUT_SECS 30
+
+static void
+debug_print_event (QueueEvent *event)
+{
+       const gchar *event_type_name[] = { "CREATED", "UPDATED", "DELETED", "MOVED" };
+       gchar *uri1 = g_file_get_uri (event->file);
+       gchar *uri2 = event->dest_file ? g_file_get_uri (event->dest_file) : NULL;
+       g_message ("%s New %s event: %s%s%s%s",
+                   EVENT_QUEUE_LOG_PREFIX,
+                   event_type_name[event->type],
+                   event->attributes_update ? "(attributes only) " : "",
+                   uri1,
+                   uri2 ? "->" : "",
+                   uri2 ? uri2 : "");
+       g_free (uri1);
+       g_free (uri2);
+}
+
+#define trace_eq(message, ...) TRACKER_NOTE (MINER_FS_EVENTS, g_message (EVENT_QUEUE_LOG_PREFIX message, 
##__VA_ARGS__))
+#define trace_eq_event(event) TRACKER_NOTE (MINER_FS_EVENTS, debug_print_event (event));
+
+#else
+#define trace_eq(...)
+#define trace_eq_event(...)
+#endif /* G_ENABLE_DEBUG */
+
 static void
 tracker_miner_fs_class_init (TrackerMinerFSClass *klass)
 {
diff --git a/src/libtracker-miners-common/meson.build b/src/libtracker-miners-common/meson.build
index 1c29eef1b..ee0674262 100644
--- a/src/libtracker-miners-common/meson.build
+++ b/src/libtracker-miners-common/meson.build
@@ -10,6 +10,7 @@ tracker_miners_common_sources = [
   'tracker-date-time.c',
   'tracker-dbus.c',
   'tracker-domain-ontology.c',
+  'tracker-debug.c',
   'tracker-file-utils.c',
   'tracker-fts-config.c',
   'tracker-ioprio.c',
diff --git a/src/libtracker-miners-common/tracker-common.h b/src/libtracker-miners-common/tracker-common.h
index 062e73141..3723c2838 100644
--- a/src/libtracker-miners-common/tracker-common.h
+++ b/src/libtracker-miners-common/tracker-common.h
@@ -30,7 +30,9 @@
 
 #include "tracker-date-time.h"
 #include "tracker-dbus.h"
+#include "tracker-debug.h"
 #include "tracker-domain-ontology.h"
+#include "tracker-enums.h"
 #include "tracker-file-utils.h"
 #include "tracker-fts-config.h"
 #include "tracker-ioprio.h"
diff --git a/src/libtracker-miners-common/tracker-debug.c b/src/libtracker-miners-common/tracker-debug.c
new file mode 100644
index 000000000..ed56f44c8
--- /dev/null
+++ b/src/libtracker-miners-common/tracker-debug.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2020, Sam Thursfield <sam afuera me uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.          See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#include "config-miners.h"
+
+#include "tracker-debug.h"
+
+#ifdef G_ENABLE_DEBUG
+static const GDebugKey tracker_miners_debug_keys[] = {
+  { "miner-fs-events", TRACKER_DEBUG_MINER_FS_EVENTS },
+};
+#endif /* G_ENABLE_DEBUG */
+
+static gpointer
+parse_debug_flags ()
+{
+       const gchar *env_string;
+       guint flags = 0;
+
+       env_string = g_getenv ("TRACKER_DEBUG");
+       if (env_string != NULL) {
+#ifdef G_ENABLE_DEBUG
+               flags = g_parse_debug_string (env_string, tracker_miners_debug_keys, G_N_ELEMENTS 
(tracker_miners_debug_keys));
+#else
+               g_warning ("TRACKER_DEBUG set but ignored because tracker isn't built with G_ENABLE_DEBUG");
+#endif  /* G_ENABLE_DEBUG */
+               env_string = NULL;
+       }
+
+       return GINT_TO_POINTER (flags);
+}
+
+guint
+tracker_miners_get_debug_flags (void)
+{
+       static GOnce once = G_ONCE_INIT;
+
+       g_once (&once, parse_debug_flags, NULL);
+
+       return GPOINTER_TO_INT (once.retval);
+}
diff --git a/src/libtracker-miners-common/tracker-debug.h b/src/libtracker-miners-common/tracker-debug.h
new file mode 100644
index 000000000..e40faeed4
--- /dev/null
+++ b/src/libtracker-miners-common/tracker-debug.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2020, Sam Thursfield <sam afuera me uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#ifndef __TRACKER_DEBUG_H__
+#define __TRACKER_DEBUG_H__
+
+#if !defined (__LIBTRACKER_COMMON_INSIDE__) && !defined (TRACKER_COMPILATION)
+#error "only <libtracker-miners/common/tracker-common.h> must be included directly."
+#endif
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef enum {
+  TRACKER_DEBUG_MINER_FS_EVENTS     = 1 <<  1,
+} TrackerDebugFlag;
+
+#ifdef G_ENABLE_DEBUG
+
+#define TRACKER_DEBUG_CHECK(type) G_UNLIKELY (tracker_miners_get_debug_flags () & TRACKER_DEBUG_##type)
+
+#define TRACKER_NOTE(type,action)                G_STMT_START {     \
+    if (TRACKER_DEBUG_CHECK (type))                                 \
+       { action; };                              } G_STMT_END
+
+#else /* !G_ENABLE_DEBUG */
+
+#define TRACKER_DEBUG_CHECK(type) 0
+#define TRACKER_NOTE(type, action)
+
+#endif /* G_ENABLE_DEBUG */
+
+guint tracker_miners_get_debug_flags (void);
+
+G_END_DECLS
+
+#endif /* __TRACKER_DEBUG_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]