[gimp] pdb: add debug group; add debug-timer-{start,end} procs



commit 16bebedc448d8e23333044b0f0c578f03ef50776
Author: Ell <ell_se yahoo com>
Date:   Thu Apr 6 11:00:20 2017 -0400

    pdb: add debug group; add debug-timer-{start,end} procs
    
    Add a debug procedure group, living in 'debug.pdb', which would host
    useful debug helper functions.  Functions in this group are not part
    of the stable API, and may be changed at any point.
    
    All procedures added to 'debug.pdb' should have a 'debug_' prefix,
    and use the new std_pdb_debug() macro, which adds the proper "here be
    dragons" warning to their description.
    
    Add two debug procedures: gimp-debug-timer-start() and
    gimp-debug-timer-end(), which measure elapsed time, a la
    GIMP_TIMER_{START,END}, and can be used to profile script-fu
    commands.

 app/pdb/Makefile.am        |    1 +
 app/pdb/debug-cmds.c       |  140 ++++++++++++++++++++++++++++++++++++++++++++
 app/pdb/internal-procs.c   |    3 +-
 app/pdb/internal-procs.h   |    1 +
 libgimp/Makefile.am        |    2 +
 libgimp/gimp_pdb_headers.h |    1 +
 libgimp/gimpdebug_pdb.c    |  105 +++++++++++++++++++++++++++++++++
 libgimp/gimpdebug_pdb.h    |   41 +++++++++++++
 tools/pdbgen/Makefile.am   |    1 +
 tools/pdbgen/groups.pl     |    1 +
 tools/pdbgen/pdb/debug.pdb |  105 +++++++++++++++++++++++++++++++++
 tools/pdbgen/stddefs.pdb   |    9 +++
 12 files changed, 409 insertions(+), 1 deletions(-)
---
diff --git a/app/pdb/Makefile.am b/app/pdb/Makefile.am
index fdb3bc4..645d323 100644
--- a/app/pdb/Makefile.am
+++ b/app/pdb/Makefile.am
@@ -41,6 +41,7 @@ libappinternal_procs_a_SOURCES = \
        channel-cmds.c                  \
        color-cmds.c                    \
        context-cmds.c                  \
+       debug-cmds.c                    \
        display-cmds.c                  \
        drawable-cmds.c                 \
        drawable-color-cmds.c           \
diff --git a/app/pdb/debug-cmds.c b/app/pdb/debug-cmds.c
new file mode 100644
index 0000000..26a997e
--- /dev/null
+++ b/app/pdb/debug-cmds.c
@@ -0,0 +1,140 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995-2003 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/* NOTE: This file is auto-generated by pdbgen.pl. */
+
+#include "config.h"
+
+#include <gegl.h>
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+#include "libgimpbase/gimpbase.h"
+
+#include "pdb-types.h"
+
+#include "core/gimpparamspecs.h"
+
+#include "gimppdb.h"
+#include "gimpprocedure.h"
+#include "internal-procs.h"
+
+
+static GTimer *gimp_debug_timer         = NULL;
+static gint    gimp_debug_timer_counter = 0;
+
+static GimpValueArray *
+debug_timer_start_invoker (GimpProcedure         *procedure,
+                           Gimp                  *gimp,
+                           GimpContext           *context,
+                           GimpProgress          *progress,
+                           const GimpValueArray  *args,
+                           GError               **error)
+{
+  if (gimp_debug_timer_counter++ == 0)
+    gimp_debug_timer = g_timer_new ();
+
+  return gimp_procedure_get_return_values (procedure, TRUE, NULL);
+}
+
+static GimpValueArray *
+debug_timer_end_invoker (GimpProcedure         *procedure,
+                         Gimp                  *gimp,
+                         GimpContext           *context,
+                         GimpProgress          *progress,
+                         const GimpValueArray  *args,
+                         GError               **error)
+{
+  gboolean success = TRUE;
+  GimpValueArray *return_vals;
+  gdouble elapsed = 0.0;
+
+  elapsed = 0.0;
+
+  if (gimp_debug_timer_counter == 0)
+    success = FALSE;
+  else if (--gimp_debug_timer_counter == 0)
+    {
+      elapsed = g_timer_elapsed (gimp_debug_timer, NULL);
+
+      g_printerr ("GIMP debug timer: %g seconds\n", elapsed);
+
+      g_timer_destroy (gimp_debug_timer);
+
+      gimp_debug_timer = NULL;
+    }
+
+  return_vals = gimp_procedure_get_return_values (procedure, success,
+                                                  error ? *error : NULL);
+
+  if (success)
+    g_value_set_double (gimp_value_array_index (return_vals, 1), elapsed);
+
+  return return_vals;
+}
+
+void
+register_debug_procs (GimpPDB *pdb)
+{
+  GimpProcedure *procedure;
+
+  /*
+   * gimp-debug-timer-start
+   */
+  procedure = gimp_procedure_new (debug_timer_start_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-debug-timer-start");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-debug-timer-start",
+                                     "Starts measuring elapsed time.",
+                                     "This procedure starts a timer, measuring the elapsed time since the 
call. Each call to this procedure should be matched by a call to 'gimp-debug-timer-end', which returns the 
elapsed time.\n"
+                                     "If there is already an active timer, it is not affected by the call, 
however, a matching 'gimp-debug-timer-end' call is still required.\n"
+                                     "\n"
+                                     "This is a debug utility procedure. It is subject to change at any 
point, and should not be used in production.",
+                                     "Ell",
+                                     "Ell",
+                                     "2017",
+                                     NULL);
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+
+  /*
+   * gimp-debug-timer-end
+   */
+  procedure = gimp_procedure_new (debug_timer_end_invoker);
+  gimp_object_set_static_name (GIMP_OBJECT (procedure),
+                               "gimp-debug-timer-end");
+  gimp_procedure_set_static_strings (procedure,
+                                     "gimp-debug-timer-end",
+                                     "Finishes measuring elapsed time.",
+                                     "This procedure stops the timer started by a previous 
'gimp-debug-timer-start' call, and prints and returns the elapsed time.\n"
+                                     "If there was already an active timer at the time of corresponding call 
to 'gimp-debug-timer-start', a dummy value is returned.\n"
+                                     "\n"
+                                     "This is a debug utility procedure. It is subject to change at any 
point, and should not be used in production.",
+                                     "Ell",
+                                     "Ell",
+                                     "2017",
+                                     NULL);
+  gimp_procedure_add_return_value (procedure,
+                                   g_param_spec_double ("elapsed",
+                                                        "elapsed",
+                                                        "The elapsed time, in seconds",
+                                                        -G_MAXDOUBLE, G_MAXDOUBLE, 0,
+                                                        GIMP_PARAM_READWRITE));
+  gimp_pdb_register_procedure (pdb, procedure);
+  g_object_unref (procedure);
+}
diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c
index ebb1a62..2338cb6 100644
--- a/app/pdb/internal-procs.c
+++ b/app/pdb/internal-procs.c
@@ -28,7 +28,7 @@
 #include "internal-procs.h"
 
 
-/* 808 procedures registered total */
+/* 810 procedures registered total */
 
 void
 internal_procs_init (GimpPDB *pdb)
@@ -42,6 +42,7 @@ internal_procs_init (GimpPDB *pdb)
   register_channel_procs (pdb);
   register_color_procs (pdb);
   register_context_procs (pdb);
+  register_debug_procs (pdb);
   register_display_procs (pdb);
   register_drawable_procs (pdb);
   register_drawable_color_procs (pdb);
diff --git a/app/pdb/internal-procs.h b/app/pdb/internal-procs.h
index f9175cd..3dd0b14 100644
--- a/app/pdb/internal-procs.h
+++ b/app/pdb/internal-procs.h
@@ -31,6 +31,7 @@ void   register_buffer_procs              (GimpPDB *pdb);
 void   register_channel_procs             (GimpPDB *pdb);
 void   register_color_procs               (GimpPDB *pdb);
 void   register_context_procs             (GimpPDB *pdb);
+void   register_debug_procs               (GimpPDB *pdb);
 void   register_display_procs             (GimpPDB *pdb);
 void   register_drawable_procs            (GimpPDB *pdb);
 void   register_drawable_color_procs      (GimpPDB *pdb);
diff --git a/libgimp/Makefile.am b/libgimp/Makefile.am
index 72ce2b7..97924ae 100644
--- a/libgimp/Makefile.am
+++ b/libgimp/Makefile.am
@@ -89,6 +89,7 @@ PDB_WRAPPERS_C = \
        gimpchannel_pdb.c               \
        gimpcolor_pdb.c                 \
        gimpcontext_pdb.c               \
+       gimpdebug_pdb.c                 \
        gimpdisplay_pdb.c               \
        gimpdrawable_pdb.c              \
        gimpdrawablecolor_pdb.c         \
@@ -146,6 +147,7 @@ PDB_WRAPPERS_H = \
        gimpchannel_pdb.h               \
        gimpcolor_pdb.h                 \
        gimpcontext_pdb.h               \
+       gimpdebug_pdb.h                 \
        gimpdisplay_pdb.h               \
        gimpdrawable_pdb.h              \
        gimpdrawablecolor_pdb.h         \
diff --git a/libgimp/gimp_pdb_headers.h b/libgimp/gimp_pdb_headers.h
index 9fe5cde..000e4ef 100644
--- a/libgimp/gimp_pdb_headers.h
+++ b/libgimp/gimp_pdb_headers.h
@@ -35,6 +35,7 @@
 #include <libgimp/gimpchannel_pdb.h>
 #include <libgimp/gimpcolor_pdb.h>
 #include <libgimp/gimpcontext_pdb.h>
+#include <libgimp/gimpdebug_pdb.h>
 #include <libgimp/gimpdisplay_pdb.h>
 #include <libgimp/gimpdrawable_pdb.h>
 #include <libgimp/gimpdrawablecolor_pdb.h>
diff --git a/libgimp/gimpdebug_pdb.c b/libgimp/gimpdebug_pdb.c
new file mode 100644
index 0000000..2eb51ef
--- /dev/null
+++ b/libgimp/gimpdebug_pdb.c
@@ -0,0 +1,105 @@
+/* LIBGIMP - The GIMP Library
+ * Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
+ *
+ * gimpdebug_pdb.c
+ *
+ * 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 3 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, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+/* NOTE: This file is auto-generated by pdbgen.pl */
+
+#include "config.h"
+
+#include "gimp.h"
+
+
+/**
+ * SECTION: gimpdebug
+ * @title: gimpdebug
+ * @short_description: Debug utility functions
+ *
+ * Miscellaneous debug utility functions. Not part of the stable
+ * library interface.
+ **/
+
+
+/**
+ * gimp_debug_timer_start:
+ *
+ * Starts measuring elapsed time.
+ *
+ * This procedure starts a timer, measuring the elapsed time since the
+ * call. Each call to this procedure should be matched by a call to
+ * gimp_debug_timer_end(), which returns the elapsed time.
+ * If there is already an active timer, it is not affected by the call,
+ * however, a matching gimp_debug_timer_end() call is still required.
+ *
+ * This is a debug utility procedure. It is subject to change at any
+ * point, and should not be used in production.
+ *
+ * Returns: TRUE on success.
+ **/
+gboolean
+gimp_debug_timer_start (void)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  gboolean success = TRUE;
+
+  return_vals = gimp_run_procedure ("gimp-debug-timer-start",
+                                    &nreturn_vals,
+                                    GIMP_PDB_END);
+
+  success = return_vals[0].data.d_status == GIMP_PDB_SUCCESS;
+
+  gimp_destroy_params (return_vals, nreturn_vals);
+
+  return success;
+}
+
+/**
+ * gimp_debug_timer_end:
+ *
+ * Finishes measuring elapsed time.
+ *
+ * This procedure stops the timer started by a previous
+ * gimp_debug_timer_start() call, and prints and returns the elapsed
+ * time.
+ * If there was already an active timer at the time of corresponding
+ * call to gimp_debug_timer_start(), a dummy value is returned.
+ *
+ * This is a debug utility procedure. It is subject to change at any
+ * point, and should not be used in production.
+ *
+ * Returns: The elapsed time, in seconds.
+ **/
+gdouble
+gimp_debug_timer_end (void)
+{
+  GimpParam *return_vals;
+  gint nreturn_vals;
+  gdouble elapsed = 0.0;
+
+  return_vals = gimp_run_procedure ("gimp-debug-timer-end",
+                                    &nreturn_vals,
+                                    GIMP_PDB_END);
+
+  if (return_vals[0].data.d_status == GIMP_PDB_SUCCESS)
+    elapsed = return_vals[1].data.d_float;
+
+  gimp_destroy_params (return_vals, nreturn_vals);
+
+  return elapsed;
+}
diff --git a/libgimp/gimpdebug_pdb.h b/libgimp/gimpdebug_pdb.h
new file mode 100644
index 0000000..760aad1
--- /dev/null
+++ b/libgimp/gimpdebug_pdb.h
@@ -0,0 +1,41 @@
+/* LIBGIMP - The GIMP Library
+ * Copyright (C) 1995-2003 Peter Mattis and Spencer Kimball
+ *
+ * gimpdebug_pdb.h
+ *
+ * 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 3 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, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+/* NOTE: This file is auto-generated by pdbgen.pl */
+
+#if !defined (__GIMP_H_INSIDE__) && !defined (GIMP_COMPILATION)
+#error "Only <libgimp/gimp.h> can be included directly."
+#endif
+
+#ifndef __GIMP_DEBUG_PDB_H__
+#define __GIMP_DEBUG_PDB_H__
+
+G_BEGIN_DECLS
+
+/* For information look into the C source or the html documentation */
+
+
+gboolean gimp_debug_timer_start (void);
+gdouble  gimp_debug_timer_end   (void);
+
+
+G_END_DECLS
+
+#endif /* __GIMP_DEBUG_PDB_H__ */
diff --git a/tools/pdbgen/Makefile.am b/tools/pdbgen/Makefile.am
index 8940408..a1fc0cd 100644
--- a/tools/pdbgen/Makefile.am
+++ b/tools/pdbgen/Makefile.am
@@ -9,6 +9,7 @@ pdb_sources = \
        pdb/channel.pdb                 \
        pdb/color.pdb                   \
        pdb/context.pdb                 \
+       pdb/debug.pdb                   \
        pdb/display.pdb                 \
        pdb/drawable.pdb                \
        pdb/drawable_color.pdb          \
diff --git a/tools/pdbgen/groups.pl b/tools/pdbgen/groups.pl
index a44c3c9..504253e 100644
--- a/tools/pdbgen/groups.pl
+++ b/tools/pdbgen/groups.pl
@@ -7,6 +7,7 @@
     channel
     color
     context
+    debug
     display
     drawable
     drawable_color
diff --git a/tools/pdbgen/pdb/debug.pdb b/tools/pdbgen/pdb/debug.pdb
new file mode 100644
index 0000000..416a457
--- /dev/null
+++ b/tools/pdbgen/pdb/debug.pdb
@@ -0,0 +1,105 @@
+# GIMP - The GNU Image Manipulation Program
+# Copyright (C) 1995 Spencer Kimball and Peter Mattis
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program 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 General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# "Perlized" from C source by Manish Singh <yosh gimp org>
+
+sub debug_timer_start {
+    $blurb = 'Starts measuring elapsed time.';
+
+    $help = <<'HELP';
+This procedure starts a timer, measuring the elapsed time since the call.
+Each call to this procedure should be matched by a call to
+gimp_debug_timer_end(), which returns the elapsed time.
+
+If there is already an active timer, it is not affected by the call, however, a
+matching gimp_debug_timer_end() call is still required.
+HELP
+
+    &ell_pdb_misc('2017');
+
+    &std_pdb_debug();
+
+    %invoke = (
+       code => <<'CODE'
+{
+  if (gimp_debug_timer_counter++ == 0)
+    gimp_debug_timer = g_timer_new ();
+}
+CODE
+    );
+}
+
+sub debug_timer_end {
+    $blurb = 'Finishes measuring elapsed time.';
+
+    $help = <<'HELP';
+This procedure stops the timer started by a previous gimp_debug_timer_start()
+call, and prints and returns the elapsed time.
+
+If there was already an active timer at the time of corresponding call to
+gimp_debug_timer_start(), a dummy value is returned.
+HELP
+
+    &ell_pdb_misc('2017');
+
+    &std_pdb_debug();
+
+    @outargs = (
+        { name => 'elapsed', type => 'float',
+          desc => 'The elapsed time, in seconds' }
+    );
+
+
+    %invoke = (
+       code => <<'CODE'
+{
+  elapsed = 0.0;
+
+  if (gimp_debug_timer_counter == 0)
+    success = FALSE;
+  else if (--gimp_debug_timer_counter == 0)
+    {
+      elapsed = g_timer_elapsed (gimp_debug_timer, NULL);
+
+      g_printerr ("GIMP debug timer: %g seconds\n", elapsed);
+
+      g_timer_destroy (gimp_debug_timer);
+
+      gimp_debug_timer = NULL;
+    }
+}
+CODE
+    );
+}
+
+
+$extra{app}->{code} = <<'CODE';
+static GTimer *gimp_debug_timer         = NULL;
+static gint    gimp_debug_timer_counter = 0;
+CODE
+
+
+@procs = qw(debug_timer_start
+            debug_timer_end);
+
+%exports = (app => [@procs], lib => [@procs]);
+
+$desc = 'Debug';
+$doc_title = 'gimpdebug';
+$doc_short_desc = 'Debug utility functions';
+$doc_long_desc = 'Miscellaneous debug utility functions. Not part of the stable library interface.';
+
+1;
diff --git a/tools/pdbgen/stddefs.pdb b/tools/pdbgen/stddefs.pdb
index e4e3cb7..17a8b2c 100644
--- a/tools/pdbgen/stddefs.pdb
+++ b/tools/pdbgen/stddefs.pdb
@@ -176,5 +176,14 @@ sub std_pdb_compat {
     $author = $copyright = "Compatibility procedure. Please see '@_' for credits.";
 }
 
+sub std_pdb_debug {
+    $help .= <<'HELP';
+
+
+This is a debug utility procedure. It is subject to change at any point,
+and should not be used in production.
+HELP
+}
+
 
 1;


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