Commit d2f82a64 authored by Jorge Arévalo's avatar Jorge Arévalo

Fixes on PostGIS Raster debug system. The raster core uses

default_info_handler() call. Other minor bugs fixed. Created DEBUG file in
raster directory, similar to postgis/DEBUG file. Erased references to old raster debug variables in configure.ac. Deleted old readme file.


git-svn-id: http://svn.osgeo.org/postgis/trunk@6136 b70326c6-7e19-0410-871a-916f4a2858ee
parent fb40e2f1
......@@ -54,7 +54,7 @@ PRE-INSTALL TEST
After a successful build, you can run:
$ make rt-check
$ make raster-check
It won't test postgresql interface, as that would require more setup
then a simple make check. See POST-INSTALL TESTING for more info on how
......@@ -66,14 +66,14 @@ INSTALL
You need to install the library to the postgresql library
directory. You do it by running:
$ sudo make rt-install
$ sudo make install
POST-INSTALL TEST
-----------------
You can run the post install tests against it:
$ make rt-post-install-check
$ make raster-post-install-check
USE
---
......
1. PostGIS Raster Configuration
Run ./configure --help and check 3 options:
--enable-rtapi-debug
Defines POSTGIS_RASTER_API_DEBUG, turns on debugging of RASTER core API
--enable-rtpg-debug
Defines POSTGIS_RASTER_PG_DEBUG, turns on debugging of PostGIS RASTER activity
--enable-rtpgmem-debug
Defines POSTGIS_RASTER_PG_DEBUG_MEM, turns on debugging PostGIS RASTER memory activity.
Simply, overrides de-/allocators with custom calls to help tracking memory usage.
2. Execution
export PGHOST=$PWD/tmp
/usr/lib/postgresql/8.3/bin/postgres --single -k $PGHOST < test.sql
psql
......@@ -770,73 +770,6 @@ if test "x$RASTER" = "xyes"; then
AC_SUBST([LIBGDAL_CFLAGS])
AC_SUBST([LIBGDAL_LDFLAGS])
dnl ===========================================================================
dnl Detect if various RT DEBUG modes requested
dnl ===========================================================================
POSTGIS_RASTER_API_DEBUG_CFLAGS=""
POSTGIS_RASTER_PG_DEBUG_CFLAGS=""
rt_debug_msg=""
AC_MSG_CHECKING([for low-level RASTER API debug mode])
AC_ARG_ENABLE([rtapi-debug],
AC_HELP_STRING([--enable-rtapi-debug=@<:@yes|no@:>@],
[enable to debug low-level RASTER API @<:@default=no@:>@]
),
[
if test "x$enableval" = "xyes"; then
rt_api_debug=1
AC_DEFINE_UNQUOTED([POSTGIS_RASTER_API_DEBUG], [$rt_api_debug], [debug low-level RASTER API])
POSTGIS_RASTER_API_DEBUG_CFLAGS="-DPOSTGIS_RASTER_API_DEBUG=$rt_api_debug"
rt_debug_msg="enabled"
else
rt_debug_msg="disabled"
fi
],
[rt_debug_msg="disabled"]
)
AC_MSG_RESULT([$rt_debug_msg])
AC_MSG_CHECKING([for PostGIS RASTER activity debug mode])
AC_ARG_ENABLE([rtpg-debug],
AC_HELP_STRING([--enable-rtpg-debug=@<:@yes|no@:>@],
[enable to debug PostGIS RASTER activity @<:@default=no@:>@]
),
[
if test "x$enableval" = "xyes"; then
rt_pg_debug=1
AC_DEFINE_UNQUOTED([POSTGIS_RASTER_PG_DEBUG], [$rt_pg_debug], [debug PostGIS RASTER activity])
POSTGIS_RASTER_PG_DEBUG_CFLAGS="$POSTGIS_RASTER_PG_DEBUG_CFLAGS -DPOSTGIS_RASTER_PG_DEBUG=$rt_pg_debug"
rt_debug_msg="enabled"
else
rt_debug_msg="disabled"
fi
],
[rt_debug_msg="disabled"]
)
AC_MSG_RESULT([$rt_debug_msg])
AC_MSG_CHECKING([for PostGIS RASTER memory activity debug mode])
AC_ARG_ENABLE([rtpgmem-debug],
AC_HELP_STRING([--enable-rtpgmem-debug=@<:@yes|no@:>@],
[enable to debug PostGIS RASTER memory activity @<:@default=no@:>@]
),
[
if test "x$enableval" = "xyes"; then
rt_pgmem_debug=1
AC_DEFINE_UNQUOTED([POSTGIS_RASTER_PG_DEBUG_MEM], [$POSTGIS_RASTER_PG_DEBUG_MEM], [debug PostGIS RASTER memory activity])
POSTGIS_RASTER_PG_DEBUG_CFLAGS="$POSTGIS_RASTER_PG_DEBUG_CFLAGS -DPOSTGIS_RASTER_PG_DEBUG_MEM=$rt_pgmem_debug"
rt_debug_msg="enabled"
else
rt_debug_msg="disabled"
fi
],
[rt_debug_msg="disabled"]
)
AC_MSG_RESULT([$rt_debug_msg])
AC_SUBST([POSTGIS_RASTER_API_DEBUG_CFLAGS])
AC_SUBST([POSTGIS_RASTER_PG_DEBUG_CFLAGS])
dnl Define raster objects, for makefiles
RT_CORE_LIB=corelib
RT_PG_LIB=pglib
......
PostGIS debugging information
=============================
Written by Jorge Arevalo
2010-10-26
Based on the ../postgis/DEBUG document, written by Mark Cave-Ayland
Description
===========
The philosophy of the PostGIS Raster debug system is the same used in PostGIS.
Review the ../postgis/DEBUG document for further understanding on this
philosophy.
Debugging is accomplished using four new macros:
RASTER_DEBUG(level, "message")
- If the current debug level >= level, emit message
RASTER_DEBUGF(level, "format message", ...)
- If the current debug level >= level, emit formatted message
(this allows placeholders and extra arguments in exactly the
same way as vasprintf())
POSTGIS_RASTER_DEBUG(level, "message")
- If the current debug level >= level, emit message
POSTGIS_RASTER_DEBUGF(level, "format message", ...)
- If the current debug level >= level, emit formatted message
(this allows placeholders and extra arguments in exactly the
same way as vasprintf())
The two RASTER_DEBUG macros are designed for use within librtcore; i.e. raster
core routines that may not necessarily be used from PostgreSQL, and make use of the
default_info_handler() call.
Similarly, the POSTGIS_RASTER_DEBUG macros are designed for code that can *only* be called
from within PostgreSQL, i.e. it calls ereport() directly. The trick is, of course,
to distinguish between the two. Generally anything within a function declared as
returning type Datum should use the POSTGIS_RASTER_DEBUG macros, as well as code that can
only be called from these functions. Similarly, any functions that do not take
PostgreSQL-specific datatypes should use the RASTER_DEBUG functions.
Note that the debugging macros automatically prefix the current filename, function name
and line number to any debugging messages. As well as allowing debug messages to be
shorter, it also makes following program flow much easier.
Usage
=====
The current debug level is set by the POSTGIS_DEBUG_LEVEL #define in postgis_config.h.
By default, configure sets POSTGIS_DEBUG_LEVEL to 0 which disables all debugging output.
If debugging output is required, it is necessary to either redefine POSTGIS_DEBUG_LEVEL
to the required level (and rebuild the shared library), or re-run configure with the
--enable-debug option and then rebuild the shared library (currently configure defaults
to level 4).
A rebuild of the library is required since the output of the debug macros is conditional;
if POSTGIS_DEBUG_LEVEL is set to 0 then instead of providing debug output, the macros
simply evaluate to (void)0 which can be optimised away by the compiler. Hence adding
debugging statements during development will have negligible performance impact during
execution when debugging is disabled.
Verbosity levels
================
The following verbosity levels have been defined in the initial implementation; obviously
these may need to change as experience dictates. By specifying a debug level, output for
all levels up to and including the current debug level is generated. It should also be
obvious that as the debug level is increased, more complex output is generated.
0 - All debugging output is disable
1 - Reserved
2 - Function entry; for simply announcing when a function has been entered
3 - Normal function debug; output any information of interest to the developer
4 - Verbose function debug; output lots of useful detail
5 - Memory allocation; output all uses of alloc/free within the code
......@@ -39,39 +39,30 @@
/* Define to the sub-directory in which libtool stores uninstalled libraries.*/
#undef LT_OBJDIR
/* debug low-level RASTER API */
#undef POSTGIS_RASTER_API_DEBUG
/* WKTRaster build date */
/* PostGIS Raster build date */
#undef POSTGIS_RASTER_BUILD_DATE
/* WKTRaster library version */
/* PostGIS Raster library version */
#undef POSTGIS_RASTER_LIB_VERSION
/* WKTRaster major version */
/* PostGIS Raster major version */
#undef POSTGIS_RASTER_MAJOR_VERSION
/* WKTRaster micro version */
/* PostGIS Raster micro version */
#undef POSTGIS_RASTER_MICRO_VERSION
/* WKTRaster minor version */
/* PostGIS Raster minor version */
#undef POSTGIS_RASTER_MINOR_VERSION
/* PostgreSQL server version */
#undef POSTGIS_RASTER_PGSQL_VERSION
/* debug PostGIS RASTER memory activity */
#undef POSTGIS_RASTER_PG_DEBUG_MEM
/* WKTRaster scripts version */
/* PostGIS Raster scripts version */
#undef POSTGIS_RASTER_SCRIPTS_VERSION
/* WKTRaster version */
/* PostGIS Raster version */
#undef POSTGIS_RASTER_VERSION
/* debug PostGIS RASTER activity */
#undef POSTGIS_RASTER_PG_DEBUG
/* Enable development variable */
#undef ENABLE_DEVELOPMENT
......
......@@ -15,7 +15,7 @@ LIBLWGEOM_CFLAGS=@LIBLWGEOM_CFLAGS@
LIBGDAL_CFLAGS=@LIBGDAL_CFLAGS@
LIBGDAL_LDFLAGS=@LIBGDAL_LDFLAGS@
LDFLAGS=$(LIBLWGEOM_LDFLAGS) $(LIBGDAL_LDFLAGS)
CFLAGS=@CFLAGS@ @PICFLAGS@ @WARNFLAGS@ @POSTGIS_RASTER_API_DEBUG_CFLAGS@ $(LIBLWGEOM_CFLAGS) $(LIBGDAL_CFLAGS)
CFLAGS=@CFLAGS@ @PICFLAGS@ @WARNFLAGS@ $(LIBLWGEOM_CFLAGS) $(LIBGDAL_CFLAGS)
# Standalone RTCORE objects
RT_OBJS=rt_api.o
......
......@@ -32,10 +32,6 @@
#include "rt_api.h"
/* Define this to debug low-level RASTER API activity */
/* Alternative, use ./configure --enable-rtapi-debug */
/*#define POSTGIS_RASTER_API_DEBUG*/
#define POSTGIS_RASTER_WARN_ON_TRUNCATION
/*--- Utilities -------------------------------------------------*/
......@@ -268,7 +264,7 @@ d_binptr_to_pos(const uint8_t* const ptr, const uint8_t* const end, size_t size)
#define CHECK_BINPTR_POSITION(ptr, end, size, pos) ((void)0);
#endif /* ifndef POSTGIS_RASTER_API_DEBUG */
#endif /* ifndef POSTGIS_DEBUG_LEVEL > 3 */
/*- rt_pixeltype -----------------------------------------------------*/
......@@ -1123,7 +1119,7 @@ rt_raster_new(rt_context ctx, uint16_t width, uint16_t height)
void
rt_raster_destroy(rt_context ctx, rt_raster raster)
{
RASTER_DEBUGF(3, "Destroying rt_raster @ %p", ret);
RASTER_DEBUGF(3, "Destroying rt_raster @ %p", ctx);
if ( raster->bands )
{
......@@ -1352,7 +1348,8 @@ rt_raster_cell_to_geopoint(rt_context ctx, rt_raster raster,
RASTER_DEBUGF(3, "rt_raster_cell_to_geopoint(%g,%g)", x, y);
RASTER_DEBUGF(3, " ipx/y:%g/%g", raster->ipX, raster->ipY);
RASTER_DEBUGF(3, "cell_to_geopoint: ipX:%g, ipY:%g, %g,%g -> %g,%g",);
RASTER_DEBUGF(3, "cell_to_geopoint: ipX:%g, ipY:%g, %g,%g -> %g,%g",
raster->ipX, raster->ipY, x, y, *x1, *y1);
}
......@@ -1421,7 +1418,7 @@ rt_raster_dump_as_wktpolygons(rt_context ctx, rt_raster raster, int nband,
*****************************/
OGRRegisterAll();
RASTER_DEBUG(3, "rt_raster_dump_as_polygons: creating OGR MEM vector");
RASTER_DEBUG(3, "creating OGR MEM vector");
/*****************************************************
......@@ -1447,7 +1444,7 @@ rt_raster_dump_as_wktpolygons(rt_context ctx, rt_raster raster, int nband,
return 0;
}
RASTER_DEBUG(3, "rt_raster_dump_as_polygons: creating GDAL MEM raster");
RASTER_DEBUG(3, "creating GDAL MEM raster");
/****************************************************************
......@@ -1484,7 +1481,7 @@ rt_raster_dump_as_wktpolygons(rt_context ctx, rt_raster raster, int nband,
adfGeoTransform[5] = rt_raster_get_pixel_height(ctx, raster);
GDALSetGeoTransform(memdataset, adfGeoTransform);
RASTER_DEBUG(3, "rt_raster_dump_as_polygons: Adding GDAL MEM raster band");
RASTER_DEBUG(3, "Adding GDAL MEM raster band");
/**
* Now, add the raster band
......@@ -1525,7 +1522,7 @@ rt_raster_dump_as_wktpolygons(rt_context ctx, rt_raster raster, int nband,
void * pVoid = rt_band_get_data(ctx, band);
RASTER_DEBUGF(4, "rt_raster_dump_as_polygons: Band data is at pos %p", pVoid);
RASTER_DEBUGF(4, "Band data is at pos %p", pVoid);
/**
* Be careful!! If this pointer is defined as szDataPointer[20]
......@@ -1545,8 +1542,7 @@ rt_raster_dump_as_wktpolygons(rt_context ctx, rt_raster raster, int nband,
else
sprintf(szGdalOption, "DATAPOINTER=0x%s", pszDataPointer);
RASTER_DEBUG(3, "rt_raster_dump_as_wktpolygons: Storing info for GDAL MEM raster \
band");
RASTER_DEBUG(3, "Storing info for GDAL MEM raster band");
apszOptions[0] = szGdalOption;
apszOptions[1] = NULL; // pixel offset, not needed
......@@ -1582,7 +1578,7 @@ rt_raster_dump_as_wktpolygons(rt_context ctx, rt_raster raster, int nband,
}
RASTER_DEBUG(3, "rt_raster_dump_as_polygons: polygonizying GDAL MEM raster band");
RASTER_DEBUG(3, "polygonizying GDAL MEM raster band");
/*****************************
* Polygonize the raster band
......@@ -1688,7 +1684,7 @@ rt_raster_dump_as_wktpolygons(rt_context ctx, rt_raster raster, int nband,
* I choose a), for this reason
*********************************************************************/
RASTER_DEBUG(3, "rt_raster_dump_as_polygons: counting valid polygons");
RASTER_DEBUG(3, "counting valid polygons");
/*********************************************************************
* Count the "valid" polygons. This is, the polygons with the "Pixel
......@@ -1744,8 +1740,7 @@ rt_raster_dump_as_wktpolygons(rt_context ctx, rt_raster raster, int nband,
return 0;
}
RASTER_DEBUGF(3, "rt_raster_dump_as_polygons: storing polygons (%d)",
nFeatureCount);
RASTER_DEBUGF(3, "storing polygons (%d)", nFeatureCount);
nCont = 0;
if (pnElements)
......@@ -1792,13 +1787,13 @@ rt_raster_dump_as_wktpolygons(rt_context ctx, rt_raster raster, int nband,
if (pnElements)
*pnElements = nCont;
RASTER_DEBUG(3, "rt_raster_dump_as_polygons: destroying GDAL MEM raster");
RASTER_DEBUG(3, "destroying GDAL MEM raster");
GDALClose(memdataset);
GDALDeregisterDriver(gdal_drv);
GDALDestroyDriver(gdal_drv);
RASTER_DEBUG(3, "rt_raster_dump_as_polygons: destroying OGR MEM vector");
RASTER_DEBUG(3, "destroying OGR MEM vector");
OGR_Fld_Destroy(hFldDfn);
OGR_DS_DeleteLayer(memdatasource, 0);
......@@ -2847,7 +2842,7 @@ rt_raster_to_hexwkb(rt_context ctx, rt_raster raster, uint32_t *hexwkbsize)
wkb = rt_raster_to_wkb(ctx, raster, &wkbsize);
RASTER_DEBUGF(3, "rt_raster_to_hexwkb: rt_raster_to_wkb returned");
RASTER_DEBUG(3, "rt_raster_to_hexwkb: rt_raster_to_wkb returned");
*hexwkbsize = wkbsize * 2; /* hex is 2 times bytes */
hexwkb = (char*)ctx->alloc( (*hexwkbsize)+1);
......
......@@ -93,6 +93,20 @@
#include "../../postgis_config.h"
typedef struct rt_context_t* rt_context;
typedef struct rt_raster_t* rt_raster;
typedef struct rt_band_t* rt_band;
typedef struct rt_geomval_t* rt_geomval;
/*- rt_context -------------------------------------------------------*/
typedef void* (*rt_allocator)(size_t size);
typedef void* (*rt_reallocator)(void *mem, size_t size);
typedef void (*rt_deallocator)(void *mem);
typedef void (*rt_message_handler)(const char* string, ...);
/* Debugging macros */
#if POSTGIS_DEBUG_LEVEL > 0
......@@ -100,14 +114,14 @@
#define RASTER_DEBUG(level, msg) \
do { \
if (POSTGIS_DEBUG_LEVEL >= level) \
ereport(NOTICE, (errmsg_internal("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__))); \
default_info_handler("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__); \
} while (0);
/* Display a formatted message at NOTICE level (like printf, with variadic arguments) */
#define RASTER_DEBUGF(level, msg, ...) \
do { \
if (POSTGIS_DEBUG_LEVEL >= level) \
ereport(NOTICE, (errmsg_internal("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__, __VA_ARGS__))); \
default_info_handler("[%s:%s:%d] " msg, __FILE__, __func__, __LINE__, __VA_ARGS__); \
} while (0);
#else
......@@ -122,18 +136,7 @@
#endif
typedef struct rt_context_t* rt_context;
typedef struct rt_raster_t* rt_raster;
typedef struct rt_band_t* rt_band;
typedef struct rt_geomval_t* rt_geomval;
/*- rt_context -------------------------------------------------------*/
typedef void* (*rt_allocator)(size_t size);
typedef void* (*rt_reallocator)(void *mem, size_t size);
typedef void (*rt_deallocator)(void *mem);
typedef void (*rt_message_handler)(const char* string, ...);
/* Initialize a context object
* @param allocator memory allocator to use, 0 to use malloc
......
......@@ -35,7 +35,7 @@ LIBLWGEOM_CFLAGS=@LIBLWGEOM_CFLAGS@
LIBGDAL_CFLAGS=@LIBGDAL_CFLAGS@
LIBGDAL_LDFLAGS=@LIBGDAL_LDFLAGS@
PG_CPPFLAGS+=@CPPFLAGS@ @POSTGIS_RASTER_PG_DEBUG_CFLAGS@ $(LIBLWGEOM_CFLAGS) $(LIBGDAL_CFLAGS) -I../rt_core
PG_CPPFLAGS+=@CPPFLAGS@ $(LIBLWGEOM_CFLAGS) $(LIBGDAL_CFLAGS) -I../rt_core
SHLIB_LINK+=@SHLIB_LINK@ ../rt_core/librtcore.a $(LIBLWGEOM_LDFLAGS) $(LIBGDAL_LDFLAGS)
# Extra files to remove during 'make clean'
EXTRA_CLEAN=$(SQL_OBJS) rtpostgis.sql
......
......@@ -44,14 +44,6 @@
#include "rt_api.h"
#include "../raster_config.h"
/* Define this to debug pgsql RASTER activity */
/* Alternative, use ./configure --enable-rtpg-debug */
/*#define POSTGIS_RASTER_PG_DEBUG 1*/
/* Define this to debug pgsql RASTER memory activity */
/* Alternative, use ./configure --enable-rtpgmem-debug */
/*#define POSTGIS_RASTER_PG_DEBUG_MEM 1*/
#define POSTGIS_RASTER_WARN_ON_TRUNCATION
/*
......@@ -481,7 +473,7 @@ Datum RASTER_dumpAsWKTPolygons(PG_FUNCTION_ARGS)
else
nband = 1; /* By default, first band */
POSTGIS_RT_DEBUGF(3, "RASTER_dumpAsWKTPolygons: band %d", nband);
POSTGIS_RT_DEBUGF(3, "band %d", nband);
/* Polygonize raster */
......@@ -497,7 +489,7 @@ Datum RASTER_dumpAsWKTPolygons(PG_FUNCTION_ARGS)
PG_RETURN_NULL();
}
POSTGIS_RT_DEBUGF(3, "RASTER_dumpAsWKTPolygons: raster dump, %d elements returned", nElements);
POSTGIS_RT_DEBUGF(3, "raster dump, %d elements returned", nElements);
/**
* Not needed to check geomval. It was allocated by the new
......@@ -542,7 +534,7 @@ Datum RASTER_dumpAsWKTPolygons(PG_FUNCTION_ARGS)
HeapTuple tuple;
Datum result;
POSTGIS_RT_DEBUGF(3, "RASTER_dumpAsWKTPolygons: call number %d", call_cntr);
POSTGIS_RT_DEBUGF(3, "call number %d", call_cntr);
/*
* Prepare a values array for building the returned tuple.
......
......@@ -19,7 +19,7 @@ RTCORE_CFLAGS=-I$(RT_CORE)
RTCORE_LDFLAGS=$(RT_CORE)/librtcore.a
CFLAGS = \
@CFLAGS@ @PICFLAGS@ @WARNFLAGS@ @POSTGIS_RASTER_API_DEBUG_CFLAGS@ \
@CFLAGS@ @PICFLAGS@ @WARNFLAGS@ \
$(RTCORE_CFLAGS) \
$(LIBLWGEOM_CFLAGS) \
$(LIBGDAL_CFLAGS)
......
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