Blame gegl/gegl-debug.h

Packit Service 2781ba
#ifndef __GEGL_DEBUG_H__
Packit Service 2781ba
#define __GEGL_DEBUG_H__
Packit Service 2781ba
Packit Service 2781ba
#include <glib.h>
Packit Service 2781ba
#include "gegl-init.h"
Packit Service 2781ba
Packit Service 2781ba
G_BEGIN_DECLS
Packit Service 2781ba
Packit Service 2781ba
typedef enum {
Packit Service 2781ba
  GEGL_DEBUG_PROCESS         = 1 << 0,
Packit Service 2781ba
  GEGL_DEBUG_BUFFER_LOAD     = 1 << 1,
Packit Service 2781ba
  GEGL_DEBUG_BUFFER_SAVE     = 1 << 2,
Packit Service 2781ba
  GEGL_DEBUG_TILE_BACKEND    = 1 << 3,
Packit Service 2781ba
  GEGL_DEBUG_PROCESSOR       = 1 << 4,
Packit Service 2781ba
  GEGL_DEBUG_CACHE           = 1 << 5,
Packit Service 2781ba
  GEGL_DEBUG_MISC            = 1 << 6,
Packit Service 2781ba
  GEGL_DEBUG_INVALIDATION    = 1 << 7,
Packit Service 2781ba
  GEGL_DEBUG_OPENCL          = 1 << 8
Packit Service 2781ba
} GeglDebugFlag;
Packit Service 2781ba
Packit Service 2781ba
/* only compiled in from gegl-init.c but kept here to
Packit Service 2781ba
 * make it easier to update and keep in sync with the
Packit Service 2781ba
 * flags
Packit Service 2781ba
 */
Packit Service 2781ba
#ifdef __GEGL_INIT_C
Packit Service 2781ba
static const GDebugKey gegl_debug_keys[] = {
Packit Service 2781ba
  { "process",       GEGL_DEBUG_PROCESS},
Packit Service 2781ba
  { "cache",         GEGL_DEBUG_CACHE},
Packit Service 2781ba
  { "buffer-load",   GEGL_DEBUG_BUFFER_LOAD},
Packit Service 2781ba
  { "buffer-save",   GEGL_DEBUG_BUFFER_SAVE},
Packit Service 2781ba
  { "tile-backend",  GEGL_DEBUG_TILE_BACKEND},
Packit Service 2781ba
  { "processor",     GEGL_DEBUG_PROCESSOR},
Packit Service 2781ba
  { "invalidation",  GEGL_DEBUG_INVALIDATION},
Packit Service 2781ba
  { "opencl",        GEGL_DEBUG_OPENCL},
Packit Service 2781ba
  { "all",           GEGL_DEBUG_PROCESS|
Packit Service 2781ba
                     GEGL_DEBUG_BUFFER_LOAD|
Packit Service 2781ba
                     GEGL_DEBUG_BUFFER_SAVE|
Packit Service 2781ba
                     GEGL_DEBUG_TILE_BACKEND|
Packit Service 2781ba
                     GEGL_DEBUG_PROCESSOR|
Packit Service 2781ba
                     GEGL_DEBUG_CACHE|
Packit Service 2781ba
                     GEGL_DEBUG_OPENCL},
Packit Service 2781ba
};
Packit Service 2781ba
#endif /* GEGL_ENABLE_DEBUG */
Packit Service 2781ba
Packit Service 2781ba
#if defined(__cplusplus) && defined(GEGL_ISO_CXX_VARIADIC_MACROS)
Packit Service 2781ba
#  define GEGL_ISO_VARIADIC_MACROS 1
Packit Service 2781ba
#endif
Packit Service 2781ba
Packit Service 2781ba
#ifdef GEGL_ENABLE_DEBUG
Packit Service 2781ba
Packit Service 2781ba
#if defined(GEGL_ISO_VARIADIC_MACROS)
Packit Service 2781ba
Packit Service 2781ba
/* Use the C99 version; unfortunately, this does not allow us to pass
Packit Service 2781ba
 * empty arguments to the macro, which means we have to
Packit Service 2781ba
 * do an intemediate printf.
Packit Service 2781ba
 */
Packit Service 2781ba
#define GEGL_NOTE(type,...)               G_STMT_START {        \
Packit Service 2781ba
        if (gegl_debug_flags & type)                            \
Packit Service 2781ba
	{                                                       \
Packit Service 2781ba
	  gchar * _fmt = g_strdup_printf (__VA_ARGS__);         \
Packit Service 2781ba
          g_message ("[" #type "] " G_STRLOC ": %s",_fmt);      \
Packit Service 2781ba
          g_free (_fmt);                                        \
Packit Service 2781ba
	}                                                       \
Packit Service 2781ba
                                                } G_STMT_END
Packit Service 2781ba
Packit Service 2781ba
#define GEGL_TIMESTAMP(type,...)             G_STMT_START {     \
Packit Service 2781ba
        if (gegl_debug_flags & type)                            \
Packit Service 2781ba
	{                                                       \
Packit Service 2781ba
	  gchar * _fmt = g_strdup_printf (__VA_ARGS__);         \
Packit Service 2781ba
          g_message ("[" #type "]" " %li:"  G_STRLOC ": %s",    \
Packit Service 2781ba
                       gegl_get_timestamp(), _fmt);             \
Packit Service 2781ba
          g_free (_fmt);                                        \
Packit Service 2781ba
	}                                                       \
Packit Service 2781ba
                                                   } G_STMT_END
Packit Service 2781ba
Packit Service 2781ba
#elif defined(GEGL_GNUC_VARIADIC_MACROS)
Packit Service 2781ba
Packit Service 2781ba
#define GEGL_NOTE(type,format,a...)          G_STMT_START {     \
Packit Service 2781ba
        if (gegl_debug_flags & type)                            \
Packit Service 2781ba
          { g_message ("[" #type "] " G_STRLOC ": "             \
Packit Service 2781ba
                       format, ##a); }                          \
Packit Service 2781ba
                                                } G_STMT_END
Packit Service 2781ba
Packit Service 2781ba
#define GEGL_TIMESTAMP(type,format,a...)        G_STMT_START {  \
Packit Service 2781ba
        if (gegl_debug_flags & type)                            \
Packit Service 2781ba
          { g_message ("[" #type "]" " %li:"  G_STRLOC ": "     \
Packit Service 2781ba
                       format, gegl_get_timestamp(), ##a); }    \
Packit Service 2781ba
                                                   } G_STMT_END
Packit Service 2781ba
Packit Service 2781ba
#else
Packit Service 2781ba
Packit Service 2781ba
#include <stdarg.h>
Packit Service 2781ba
Packit Service 2781ba
static const gchar *
Packit Service 2781ba
gegl_lookup_debug_string  (guint type)
Packit Service 2781ba
{
Packit Service 2781ba
  const gchar *key = "!INVALID!";
Packit Service 2781ba
  guint i = 0;
Packit Service 2781ba
Packit Service 2781ba
  if (type == GEGL_DEBUG_MISC)
Packit Service 2781ba
    {
Packit Service 2781ba
      key = "misc";
Packit Service 2781ba
    }
Packit Service 2781ba
  else
Packit Service 2781ba
    {
Packit Service 2781ba
      while (g_strcmp0 (gegl_debug_keys[i].key, "all") != 0)
Packit Service 2781ba
        {
Packit Service 2781ba
          if (gegl_debug_keys[i].value == type)
Packit Service 2781ba
            {
Packit Service 2781ba
              key = gegl_debug_keys[i].key;
Packit Service 2781ba
              break;
Packit Service 2781ba
            }
Packit Service 2781ba
          i++;
Packit Service 2781ba
        }
Packit Service 2781ba
    }
Packit Service 2781ba
Packit Service 2781ba
  return key;
Packit Service 2781ba
}
Packit Service 2781ba
Packit Service 2781ba
static inline void
Packit Service 2781ba
GEGL_NOTE (guint type, const char *format, ...)
Packit Service 2781ba
{
Packit Service 2781ba
  va_alist args;
Packit Service 2781ba
Packit Service 2781ba
  if (gegl_debug_flags & type)
Packit Service 2781ba
  {
Packit Service 2781ba
    gchar *formatted;
Packit Service 2781ba
    va_start (args, format);
Packit Service 2781ba
    formatted = g_strdup_printf (format, args);
Packit Service 2781ba
    g_message ("[ %s ] " G_STRLOC ": %s",
Packit Service 2781ba
               gegl_lookup_debug_string (type), formatted);
Packit Service 2781ba
    g_free (formatted);
Packit Service 2781ba
    va_end (args);
Packit Service 2781ba
  }
Packit Service 2781ba
}
Packit Service 2781ba
Packit Service 2781ba
static inline void
Packit Service 2781ba
GEGL_TIMESTAMP (guint type, const char *format, ...)
Packit Service 2781ba
{
Packit Service 2781ba
  va_alist args;
Packit Service 2781ba
  
Packit Service 2781ba
  if (gegl_debug_flags & type)
Packit Service 2781ba
  {
Packit Service 2781ba
    gchar *formatted;
Packit Service 2781ba
    va_start (args, format);
Packit Service 2781ba
    formatted = g_strdup_printf (format, args);
Packit Service 2781ba
    g_message ("[ %s ] %li: " G_STRLOC ": %s",
Packit Service 2781ba
               gegl_lookup_debug_string (type), gegl_get_timestamp(),
Packit Service 2781ba
               formatted);
Packit Service 2781ba
    g_free (formatted);
Packit Service 2781ba
    va_end (args);
Packit Service 2781ba
  }
Packit Service 2781ba
}
Packit Service 2781ba
Packit Service 2781ba
#endif
Packit Service 2781ba
Packit Service 2781ba
#define GEGL_MARK()      GEGL_NOTE(GEGL_DEBUG_MISC, "== mark ==")
Packit Service 2781ba
#define GEGL_DBG(x) { a }
Packit Service 2781ba
Packit Service 2781ba
#else /* !GEGL_ENABLE_DEBUG */
Packit Service 2781ba
Packit Service 2781ba
#if defined(GEGL_ISO_VARIADIC_MACROS)
Packit Service 2781ba
Packit Service 2781ba
#define GEGL_NOTE(type,...)
Packit Service 2781ba
#define GEGL_TIMESTAMP(type,...)
Packit Service 2781ba
Packit Service 2781ba
#elif defined(GEGL_GNUC_VARIADIC_MACROS)
Packit Service 2781ba
Packit Service 2781ba
#define GEGL_NOTE(type,format,a...)
Packit Service 2781ba
#define GEGL_TIMESTAMP(type,format,a...)
Packit Service 2781ba
Packit Service 2781ba
#else
Packit Service 2781ba
Packit Service 2781ba
static inline void
Packit Service 2781ba
GEGL_NOTE (guint type, const char *format, ...)
Packit Service 2781ba
{
Packit Service 2781ba
  return;
Packit Service 2781ba
}
Packit Service 2781ba
Packit Service 2781ba
static inline void
Packit Service 2781ba
GEGL_TIMESTAMP (guint type, const char *format, ...)
Packit Service 2781ba
{
Packit Service 2781ba
  return;
Packit Service 2781ba
}
Packit Service 2781ba
Packit Service 2781ba
#endif
Packit Service 2781ba
Packit Service 2781ba
#define GEGL_MARK()
Packit Service 2781ba
#define GEGL_DBG(x)
Packit Service 2781ba
Packit Service 2781ba
#endif /* GEGL_ENABLE_DEBUG */
Packit Service 2781ba
Packit Service 2781ba
extern guint gegl_debug_flags;
Packit Service 2781ba
Packit Service 2781ba
G_END_DECLS
Packit Service 2781ba
Packit Service 2781ba
#endif /* __GEGL_DEBUG_H__  */