[mapserver-commits] r12162 - in trunk/mapserver/mapcache: . include
src
svn at osgeo.org
svn at osgeo.org
Fri Aug 26 07:03:23 EDT 2011
Author: tbonfort
Date: 2011-08-26 04:03:23 -0700 (Fri, 26 Aug 2011)
New Revision: 12162
Added:
trunk/mapserver/mapcache/src/geocache_seed.c
Modified:
trunk/mapserver/mapcache/Makefile.inc.in
trunk/mapserver/mapcache/include/geocache.h
trunk/mapserver/mapcache/src/Makefile
trunk/mapserver/mapcache/src/fastcgi_geocache.c
trunk/mapserver/mapcache/src/mod_geocache.c
trunk/mapserver/mapcache/src/util.c
Log:
add benchmarking script
thomas.bonfort | 2010-11-11 10:40:32 +0100 (Thu, 11 Nov 2010)
Modified: trunk/mapserver/mapcache/Makefile.inc.in
===================================================================
--- trunk/mapserver/mapcache/Makefile.inc.in 2011-08-26 11:03:16 UTC (rev 12161)
+++ trunk/mapserver/mapcache/Makefile.inc.in 2011-08-26 11:03:23 UTC (rev 12162)
@@ -1,4 +1,4 @@
-TARGETS=@TARGETS@
+TARGETS=@TARGETS@ geocache_seed
APXS=@APXS@
CC=@CC@
APACHECTL=@APACHECTL@
@@ -33,6 +33,6 @@
-OBJS=$(shell find . -regex '^.*\.c$$' -print | grep -v mod_geocache.c | grep -v fastcgi_geocache.c |sed "s/^\(.*\)\.c$$/\1.o/")
-LOBJS=$(shell find . -regex '^.*\.c$$' -print | grep -v mod_geocache.c | grep -v fastcgi_geocache.c | sed "s/^\(.*\)\.c$$/\1.lo/")
+OBJS=$(shell find . -regex '^.*\.c$$' -print | grep -v geocache_seed.c | grep -v mod_geocache.c | grep -v fastcgi_geocache.c |sed "s/^\(.*\)\.c$$/\1.o/")
+LOBJS=$(shell find . -regex '^.*\.c$$' -print | grep -v geocache_seed.c | grep -v mod_geocache.c | grep -v fastcgi_geocache.c | sed "s/^\(.*\)\.c$$/\1.lo/")
APXS_WCFLAGS=$(shell for flag in $(GC_CFLAGS); do echo "-Wc,$$flag "; done)
Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h 2011-08-26 11:03:16 UTC (rev 12161)
+++ trunk/mapserver/mapcache/include/geocache.h 2011-08-26 11:03:23 UTC (rev 12162)
@@ -89,7 +89,7 @@
* \brief query context to know if an error has occured
* \memberof geocache_context
*/
- int (*get_error)(geocache_context *ctx);
+ geocache_error_code (*get_error)(geocache_context *ctx);
/**
* \brief get human readable message for the error
@@ -131,9 +131,11 @@
apr_pool_t *pool;
char *_errmsg;
- int _errcode;
+ geocache_error_code _errcode;
};
+void geocache_context_init(geocache_context *ctx);
+
#define GC_CHECK_ERROR_RETURN(ctx) (if(((geocache_context*)ctx)->_errcode) return GEOCACHE_FAILURE;)
#define GC_CHECK_ERROR(ctx) if(((geocache_context*)ctx)->_errcode) return;
#define GC_HAS_ERROR(ctx) (((geocache_context*)ctx)->_errcode > 0)
Modified: trunk/mapserver/mapcache/src/Makefile
===================================================================
--- trunk/mapserver/mapcache/src/Makefile 2011-08-26 11:03:16 UTC (rev 12161)
+++ trunk/mapserver/mapcache/src/Makefile 2011-08-26 11:03:23 UTC (rev 12162)
@@ -22,8 +22,11 @@
geocache.fcgi: fastcgi_geocache.c $(OBJS)
$(LIBTOOL) --mode=link $(CC) -o geocache.fcgi $(GC_CFLAGS) $(APR_CFLAGS) $(FCGI_INC) fastcgi_geocache.c $(LOBJS) $(GC_LIBS) $(APR_LIBS) $(FCGI_LIB)
-
+geocache_seed: geocache_seed.c $(OBJS)
+ $(LIBTOOL) --mode=link $(CC) -o geocache_seed $(GC_CFLAGS) $(APR_CFLAGS) geocache_seed.c $(LOBJS) $(GC_LIBS) $(APR_LIBS)
+
+
clean:
rm -f *.o
rm -f *.so
Modified: trunk/mapserver/mapcache/src/fastcgi_geocache.c
===================================================================
--- trunk/mapserver/mapcache/src/fastcgi_geocache.c 2011-08-26 11:03:16 UTC (rev 12161)
+++ trunk/mapserver/mapcache/src/fastcgi_geocache.c 2011-08-26 11:03:23 UTC (rev 12162)
@@ -66,9 +66,7 @@
void init_fcgi_context(geocache_context_fcgi *ctx) {
- ctx->ctx.set_error = fcgi_context_set_error;
- ctx->ctx.get_error = fcgi_context_get_error;
- ctx->ctx.get_error_message = fcgi_context_get_error_message;
+ geocache_context_init((geocache_context*)ctx);
ctx->ctx.log = fcgi_context_log;
}
Added: trunk/mapserver/mapcache/src/geocache_seed.c
===================================================================
--- trunk/mapserver/mapcache/src/geocache_seed.c (rev 0)
+++ trunk/mapserver/mapcache/src/geocache_seed.c 2011-08-26 11:03:23 UTC (rev 12162)
@@ -0,0 +1,125 @@
+#include "geocache.h"
+#include <apr_thread_proc.h>
+#include <apr_getopt.h>
+
+static const apr_getopt_option_t seed_options[] = {
+ /* long-option, short-option, has-arg flag, description */
+ { "config", 'c', TRUE, "configuration file"},
+ { "tileset", 't', TRUE, "tileset to seed" },
+ { "zoom", 'z', TRUE, "min and max zoomlevels to seed" },
+ { "extent", 'e', TRUE, "extent" },
+ { "nthreads", 'n', TRUE, "number of parallel threads to use" },
+ { "help", 'h', FALSE, "show help" },
+ { NULL, 0, 0, NULL },
+};
+
+static void* APR_THREAD_FUNC doseed(apr_thread_t *thd, void *data) {
+ int thread_id = (int)data;
+ int i;
+ for(i=0;i<10;i++) {
+ printf("thread %d: %d\n",thread_id,i);
+ }
+ apr_thread_exit(thd,APR_SUCCESS);
+ return NULL;
+}
+
+
+int usage(const char *progname, char *msg) {
+ printf("%s\nusage: %s options\n"
+ "-c|--config conffile : configuration file to load\n"
+ "-t|--tileset tileset : name of the tileset to seed\n"
+ "[-z|--zoom minzoom,maxzoom] : zoomlevels to seed\n"
+ "[-e|--extent minx,miny,maxx,maxy] : extent to seed\n"
+ "[-n|--nthreads n] : number of parallel threads\n",
+ msg,progname);
+ return 1;
+}
+
+int main(int argc, const char **argv) {
+ /* initialize apr_getopt_t */
+ apr_getopt_t *opt;
+ const char *configfile=NULL;
+ geocache_cfg *cfg = NULL;
+ geocache_tileset *tileset;
+ geocache_context ctx;
+ apr_thread_t **threads;
+ apr_threadattr_t *thread_attrs;
+ const char *tileset_name=NULL;
+ int *zooms = NULL;//[2];
+ double *extent = NULL;//[4];
+ int nthreads=1;
+ int optch;
+ int rv,n;
+ const char *optarg;
+ apr_initialize();
+ apr_pool_create_core(&ctx.pool);
+ geocache_context_init(&ctx);
+ cfg = geocache_configuration_create(ctx.pool);
+ apr_getopt_init(&opt, ctx.pool, argc, argv);
+ /* parse the all options based on opt_option[] */
+ while ((rv = apr_getopt_long(opt, seed_options, &optch, &optarg)) == APR_SUCCESS) {
+ switch (optch) {
+ case 'h':
+ return usage(argv[0],NULL);
+ break;
+ case 'c':
+ configfile = optarg;
+ break;
+ case 't':
+ tileset_name = optarg;
+ break;
+ case 'n':
+ nthreads = (int)strtol(optarg, NULL, 10);
+ break;
+ case 'e':
+ if ( GEOCACHE_SUCCESS != geocache_util_extract_double_list(&ctx, (char*)optarg, ',', &extent, &n) ||
+ n != 4 || extent[0] >= extent[2] || extent[1] >= extent[3] ) {
+ return usage(argv[0], "failed to parse extent, expecting comma separated 4 doubles");
+ }
+ break;
+ case 'z':
+ if ( GEOCACHE_SUCCESS != geocache_util_extract_int_list(&ctx, (char*)optarg, ',', &zooms, &n) ||
+ n != 2 || zooms[0] >= zooms[1]) {
+ return usage(argv[0], "failed to parse zooms, expecting comma separated 2 ints");
+ }
+ break;
+ }
+ }
+ if (rv != APR_EOF) {
+ return usage(argv[0],"bad options");
+ }
+
+ if( ! configfile ) {
+ return usage(argv[0],"config not specified");
+ } else {
+ geocache_configuration_parse(&ctx,configfile,cfg);
+ if(ctx.get_error(&ctx))
+ return usage(argv[0],ctx.get_error_message(&ctx));
+ }
+
+ if( ! tileset_name ) {
+ return usage(argv[0],"tileset not specified");
+ } else {
+ tileset = geocache_configuration_get_tileset(cfg,tileset_name);
+ if(!tileset) {
+ return usage(argv[0], "tileset not found in configuration");
+ }
+ }
+
+ if( ! nthreads ) {
+ return usage(argv[0],"failed to parse nthreads, must be int");
+ } else {
+ apr_threadattr_create(&thread_attrs, ctx.pool);
+ threads = (apr_thread_t**)apr_pcalloc(ctx.pool, nthreads*sizeof(apr_thread_t*));
+ for(n=0;n<nthreads;n++) {
+ apr_thread_create(&threads[n], thread_attrs, doseed, (void*)n, ctx.pool);
+ }
+ for(n=0;n<nthreads;n++) {
+ apr_thread_join(&rv, threads[n]);
+ }
+
+ }
+
+
+ return 0;
+}
Modified: trunk/mapserver/mapcache/src/mod_geocache.c
===================================================================
--- trunk/mapserver/mapcache/src/mod_geocache.c 2011-08-26 11:03:16 UTC (rev 12161)
+++ trunk/mapserver/mapcache/src/mod_geocache.c 2011-08-26 11:03:23 UTC (rev 12162)
@@ -54,24 +54,6 @@
request_rec *request;
};
-
-void apache_context_set_error(geocache_context *c, geocache_error_code code, char *message, ...) {
- va_list args;
- va_start(args,message);
- c->_errmsg = apr_pvsprintf(c->pool,message,args);
- c->_errcode = code;
- va_end(args);
-}
-
-
-int apache_context_get_error(geocache_context *c) {
- return c->_errcode;
-}
-
-char* apache_context_get_error_message(geocache_context *c) {
- return c->_errmsg;
-}
-
void apache_context_server_log(geocache_context *c, geocache_log_level level, char *message, ...) {
geocache_context_apache_server *ctx = (geocache_context_apache_server*)c;
va_list args;
@@ -88,12 +70,6 @@
va_end(args);
}
-void init_apache_context(geocache_context_apache *ctx) {
- ctx->ctx.set_error = apache_context_set_error;
- ctx->ctx.get_error = apache_context_get_error;
- ctx->ctx.get_error_message = apache_context_get_error_message;
-}
-
int geocache_util_mutex_aquire(geocache_context *r, int nonblocking) {
int ret;
geocache_context_apache_request *ctx = (geocache_context_apache_request*)r;
@@ -121,14 +97,14 @@
}
void init_apache_request_context(geocache_context_apache_request *ctx) {
- init_apache_context((geocache_context_apache*)ctx);
+ geocache_context_init((geocache_context*)ctx);
ctx->ctx.ctx.log = apache_context_request_log;
ctx->ctx.ctx.global_lock_aquire = geocache_util_mutex_aquire;
ctx->ctx.ctx.global_lock_release = geocache_util_mutex_release;
}
void init_apache_server_context(geocache_context_apache_server *ctx) {
- init_apache_context((geocache_context_apache*)ctx);
+ geocache_context_init((geocache_context*)ctx);
ctx->ctx.ctx.log = apache_context_server_log;
ctx->ctx.ctx.global_lock_aquire = geocache_util_mutex_aquire;
ctx->ctx.ctx.global_lock_release = geocache_util_mutex_release;
Modified: trunk/mapserver/mapcache/src/util.c
===================================================================
--- trunk/mapserver/mapcache/src/util.c 2011-08-26 11:03:16 UTC (rev 12161)
+++ trunk/mapserver/mapcache/src/util.c 2011-08-26 11:03:23 UTC (rev 12162)
@@ -65,5 +65,37 @@
return GEOCACHE_SUCCESS;
}
+geocache_error_code _geocache_context_get_error_default(geocache_context *ctx) {
+ return ctx->_errcode;
+}
+char* _geocache_context_get_error_msg_default(geocache_context *ctx) {
+ return ctx->_errmsg;
+}
+void _geocache_context_set_error_default(geocache_context *ctx, geocache_error_code code, char *msg, ...) {
+ char *fmt;
+ va_list args;
+ va_start(args,msg);
+
+ if(ctx->_errmsg) {
+ fmt=apr_psprintf(ctx->pool,"%s\n%s",ctx->_errmsg,msg);
+ } else {
+ fmt=msg;
+ ctx->_errcode = code;
+ }
+ ctx->_errmsg = apr_pvsprintf(ctx->pool,fmt,args);
+ va_end(args);
+}
+
+
+void geocache_context_init(geocache_context *ctx) {
+ ctx->_errcode = GEOCACHE_NO_ERROR;
+ ctx->_errmsg = NULL;
+ ctx->get_error = _geocache_context_get_error_default;
+ ctx->get_error_message = _geocache_context_get_error_msg_default;
+ ctx->set_error = _geocache_context_set_error_default;
+}
+
+
+
More information about the mapserver-commits
mailing list