summaryrefslogtreecommitdiff
path: root/src/libtracker-common
diff options
context:
space:
mode:
authorSam Thursfield <sam@afuera.me.uk>2020-04-20 00:29:47 +0200
committerSam Thursfield <sam@afuera.me.uk>2020-04-20 01:42:34 +0200
commitca1a0f3c28fdbc3dae2c7bd6019fdcacb021e610 (patch)
tree3a8c102969cde7182d6fd9566287021af97eac09 /src/libtracker-common
parent9bb96a716581371e3229f036136234af476fc82b (diff)
downloadtracker-ca1a0f3c28fdbc3dae2c7bd6019fdcacb021e610.tar.gz
Add TRACKER_DEBUG environment variable, use for SQL 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. See https://gitlab.gnome.org/GNOME/tracker/issues/178
Diffstat (limited to 'src/libtracker-common')
-rw-r--r--src/libtracker-common/meson.build1
-rw-r--r--src/libtracker-common/tracker-common.h1
-rw-r--r--src/libtracker-common/tracker-debug.c57
-rw-r--r--src/libtracker-common/tracker-debug.h54
4 files changed, 113 insertions, 0 deletions
diff --git a/src/libtracker-common/meson.build b/src/libtracker-common/meson.build
index 3ec6caec0..11e610d09 100644
--- a/src/libtracker-common/meson.build
+++ b/src/libtracker-common/meson.build
@@ -12,6 +12,7 @@ tracker_common_enum_header = enums[1]
tracker_common_sources = [
'tracker-date-time.c',
+ 'tracker-debug.c',
'tracker-file-utils.c',
'tracker-log.c',
'tracker-type-utils.c',
diff --git a/src/libtracker-common/tracker-common.h b/src/libtracker-common/tracker-common.h
index 8d5df2be9..0a9267ed9 100644
--- a/src/libtracker-common/tracker-common.h
+++ b/src/libtracker-common/tracker-common.h
@@ -29,6 +29,7 @@
#define __LIBTRACKER_COMMON_INSIDE__
#include "tracker-date-time.h"
+#include "tracker-debug.h"
#include "tracker-file-utils.h"
#include "tracker-language.h"
#include "tracker-log.h"
diff --git a/src/libtracker-common/tracker-debug.c b/src/libtracker-common/tracker-debug.c
new file mode 100644
index 000000000..647b78b09
--- /dev/null
+++ b/src/libtracker-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.h"
+
+#include "tracker-debug.h"
+
+#ifdef G_ENABLE_DEBUG
+static const GDebugKey tracker_debug_keys[] = {
+ { "sql-statements", TRACKER_DEBUG_SQL_STATEMENTS },
+};
+#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_debug_keys, G_N_ELEMENTS (tracker_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_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-common/tracker-debug.h b/src/libtracker-common/tracker-debug.h
new file mode 100644
index 000000000..aaca4fc07
--- /dev/null
+++ b/src/libtracker-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-common/tracker-common.h> must be included directly."
+#endif
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef enum {
+ TRACKER_DEBUG_SQL_STATEMENTS = 1 << 1,
+} TrackerDebugFlag;
+
+#ifdef G_ENABLE_DEBUG
+
+#define TRACKER_DEBUG_CHECK(type) G_UNLIKELY (tracker_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_get_debug_flags (void);
+
+G_END_DECLS
+
+#endif /* __TRACKER_DEBUG_H__ */