Commit 16bebedc authored by Ell's avatar Ell

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.
parent 32239a25
......@@ -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 \
......
/* 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);
}
......@@ -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);
......
......@@ -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);
......
......@@ -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 \
......
......@@ -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>
......
/* 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;
}
/* 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__ */
......@@ -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 \
......
......@@ -7,6 +7,7 @@
channel
color
context
debug
display
drawable
drawable_color
......
# 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;
......@@ -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;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment