add CLI args for new cache stuff
cache params now have CLI controls
This commit is contained in:
parent
ed73e8cf08
commit
ea84ce8ed0
15
TODO
15
TODO
@ -1,4 +1,17 @@
|
||||
- hook up cache sizes to CLI args
|
||||
- get rid of useless DMALLOC stuff
|
||||
|
||||
#ifdef WITH_DMALLOC
|
||||
#include <dmalloc.h>
|
||||
#endif /*WITH_DMALLOC*/
|
||||
|
||||
|
||||
- (header -f height file.v) seems to segv?
|
||||
|
||||
|
||||
|
||||
- do clip/embed etc. in new style, good to get everything that VipsAdd uses in
|
||||
the new stack
|
||||
|
||||
|
||||
|
||||
- im_csv2vips() gets confused by quotes and commas, eg.
|
||||
|
@ -75,6 +75,11 @@ extern int vips__progress;
|
||||
*/
|
||||
extern char *vips__disc_threshold;
|
||||
|
||||
/* Cache size settings.
|
||||
*/
|
||||
extern char *vips__cache_max;
|
||||
extern char *vips__cache_max_mem;
|
||||
|
||||
typedef int (*im__fftproc_fn)( VipsImage *, VipsImage *, VipsImage * );
|
||||
|
||||
/* iofuncs
|
||||
@ -265,6 +270,8 @@ void vips__interpolate_init( void );
|
||||
*/
|
||||
void vips__init_wrap7_classes( void );
|
||||
|
||||
size_t vips__parse_size( const char *size_string );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus*/
|
||||
|
@ -70,6 +70,11 @@
|
||||
#include <dmalloc.h>
|
||||
#endif /*WITH_DMALLOC*/
|
||||
|
||||
/* Set by GOption from the command line, eg. "12m".
|
||||
*/
|
||||
char *vips__cache_max = NULL;
|
||||
char *vips__cache_max_mem = NULL;
|
||||
|
||||
/* Max number of cached operations.
|
||||
*/
|
||||
static int vips_cache_max = 10000;
|
||||
@ -395,45 +400,22 @@ vips_operation_equal( VipsOperation *a, VipsOperation *b )
|
||||
return( FALSE );
|
||||
}
|
||||
|
||||
static void *
|
||||
vips_object_ref_arg( VipsObject *object,
|
||||
GParamSpec *pspec,
|
||||
VipsArgumentClass *argument_class,
|
||||
VipsArgumentInstance *argument_instance,
|
||||
void *a, void *b )
|
||||
static void
|
||||
vips_cache_init( void )
|
||||
{
|
||||
if( (argument_class->flags & VIPS_ARGUMENT_CONSTRUCT) &&
|
||||
(argument_class->flags & VIPS_ARGUMENT_OUTPUT) &&
|
||||
argument_instance->assigned &&
|
||||
G_IS_PARAM_SPEC_OBJECT( pspec ) ) {
|
||||
GObject *value;
|
||||
if( !vips_cache_table ) {
|
||||
vips_cache_table = g_hash_table_new(
|
||||
(GHashFunc) vips_operation_hash,
|
||||
(GEqualFunc) vips_operation_equal );
|
||||
|
||||
/* This will up the ref count for us.
|
||||
*/
|
||||
g_object_get( G_OBJECT( object ),
|
||||
g_param_spec_get_name( pspec ), &value, NULL );
|
||||
if( vips__cache_max )
|
||||
vips_cache_max =
|
||||
vips__parse_size( vips__cache_max );
|
||||
|
||||
if( vips__cache_max_mem )
|
||||
vips_cache_max_mem =
|
||||
vips__parse_size( vips__cache_max_mem );
|
||||
}
|
||||
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
static void
|
||||
vips_operation_touch( VipsOperation *operation )
|
||||
{
|
||||
vips_cache_time += 1;
|
||||
operation->time = vips_cache_time;
|
||||
}
|
||||
|
||||
/* Ref an operation for the cache. The operation itself, plus all the output
|
||||
* objects it makes.
|
||||
*/
|
||||
static void
|
||||
vips_cache_ref( VipsOperation *operation )
|
||||
{
|
||||
g_object_ref( operation );
|
||||
(void) vips_argument_map( VIPS_OBJECT( operation ),
|
||||
vips_object_ref_arg, NULL, NULL );
|
||||
vips_operation_touch( operation );
|
||||
}
|
||||
|
||||
static void *
|
||||
@ -543,6 +525,47 @@ vips_cache_trim( void )
|
||||
vips_cache_drop( operation );
|
||||
}
|
||||
|
||||
static void *
|
||||
vips_object_ref_arg( VipsObject *object,
|
||||
GParamSpec *pspec,
|
||||
VipsArgumentClass *argument_class,
|
||||
VipsArgumentInstance *argument_instance,
|
||||
void *a, void *b )
|
||||
{
|
||||
if( (argument_class->flags & VIPS_ARGUMENT_CONSTRUCT) &&
|
||||
(argument_class->flags & VIPS_ARGUMENT_OUTPUT) &&
|
||||
argument_instance->assigned &&
|
||||
G_IS_PARAM_SPEC_OBJECT( pspec ) ) {
|
||||
GObject *value;
|
||||
|
||||
/* This will up the ref count for us.
|
||||
*/
|
||||
g_object_get( G_OBJECT( object ),
|
||||
g_param_spec_get_name( pspec ), &value, NULL );
|
||||
}
|
||||
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
static void
|
||||
vips_operation_touch( VipsOperation *operation )
|
||||
{
|
||||
vips_cache_time += 1;
|
||||
operation->time = vips_cache_time;
|
||||
}
|
||||
|
||||
/* Ref an operation for the cache. The operation itself, plus all the output
|
||||
* objects it makes.
|
||||
*/
|
||||
static void
|
||||
vips_cache_ref( VipsOperation *operation )
|
||||
{
|
||||
g_object_ref( operation );
|
||||
(void) vips_argument_map( VIPS_OBJECT( operation ),
|
||||
vips_object_ref_arg, NULL, NULL );
|
||||
vips_operation_touch( operation );
|
||||
}
|
||||
|
||||
/**
|
||||
* vips_cache_operation_build:
|
||||
* @operation: pointer to operation to lookup
|
||||
@ -561,10 +584,7 @@ vips_cache_operation_build( VipsOperation **operation )
|
||||
|
||||
VIPS_DEBUG_MSG( "vips_operation_build_cache: %p\n", *object );
|
||||
|
||||
if( !vips_cache_table )
|
||||
vips_cache_table = g_hash_table_new(
|
||||
(GHashFunc) vips_operation_hash,
|
||||
(GEqualFunc) vips_operation_equal );
|
||||
vips_cache_init();
|
||||
|
||||
vips_cache_trim();
|
||||
|
||||
|
@ -511,46 +511,6 @@ lazy_new( VipsImage *image,
|
||||
return( lazy );
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
const char unit;
|
||||
int multiplier;
|
||||
} Unit;
|
||||
|
||||
static size_t
|
||||
parse_size( const char *size_string )
|
||||
{
|
||||
static Unit units[] = {
|
||||
{ 'k', 1024 },
|
||||
{ 'm', 1024 * 1024 },
|
||||
{ 'g', 1024 * 1024 * 1024 }
|
||||
};
|
||||
|
||||
size_t size;
|
||||
int n;
|
||||
int i, j;
|
||||
char *unit;
|
||||
|
||||
/* An easy way to alloc a buffer large enough.
|
||||
*/
|
||||
unit = g_strdup( size_string );
|
||||
n = sscanf( size_string, "%d %s", &i, unit );
|
||||
if( n > 0 )
|
||||
size = i;
|
||||
if( n > 1 ) {
|
||||
for( j = 0; j < VIPS_NUMBER( units ); j++ )
|
||||
if( tolower( unit[0] ) == units[j].unit ) {
|
||||
size *= units[j].multiplier;
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_free( unit );
|
||||
|
||||
VIPS_DEBUG_MSG( "parse_size: parsed \"%s\" as %zd\n",
|
||||
size_string, size );
|
||||
|
||||
return( size );
|
||||
}
|
||||
|
||||
static size_t
|
||||
disc_threshold( void )
|
||||
{
|
||||
@ -567,10 +527,10 @@ disc_threshold( void )
|
||||
threshold = 100 * 1024 * 1024;
|
||||
|
||||
if( (env = g_getenv( "IM_DISC_THRESHOLD" )) )
|
||||
threshold = parse_size( env );
|
||||
threshold = vips__parse_size( env );
|
||||
|
||||
if( vips__disc_threshold )
|
||||
threshold = parse_size( vips__disc_threshold );
|
||||
threshold = vips__parse_size( vips__disc_threshold );
|
||||
|
||||
VIPS_DEBUG_MSG( "disc_threshold: %zd bytes\n", threshold );
|
||||
}
|
||||
|
@ -295,11 +295,14 @@ vips__ngettext( const char *msgid, const char *plural, unsigned long int n )
|
||||
}
|
||||
|
||||
static GOptionEntry option_entries[] = {
|
||||
{ "vips-concurrency", 'c', 0, G_OPTION_ARG_INT, &vips__concurrency,
|
||||
{ "vips-concurrency", 'c', 0,
|
||||
G_OPTION_ARG_INT, &vips__concurrency,
|
||||
N_( "evaluate with N concurrent threads" ), "N" },
|
||||
{ "vips-tile-width", 'w', 0, G_OPTION_ARG_INT, &vips__tile_width,
|
||||
{ "vips-tile-width", 'w', 0,
|
||||
G_OPTION_ARG_INT, &vips__tile_width,
|
||||
N_( "set tile width to N (DEBUG)" ), "N" },
|
||||
{ "vips-tile-height", 'h', 0, G_OPTION_ARG_INT, &vips__tile_height,
|
||||
{ "vips-tile-height", 'h', 0,
|
||||
G_OPTION_ARG_INT, &vips__tile_height,
|
||||
N_( "set tile height to N (DEBUG)" ), "N" },
|
||||
{ "vips-thinstrip-height", 't', 0,
|
||||
G_OPTION_ARG_INT, &vips__thinstrip_height,
|
||||
@ -307,14 +310,21 @@ static GOptionEntry option_entries[] = {
|
||||
{ "vips-fatstrip-height", 'f', 0,
|
||||
G_OPTION_ARG_INT, &vips__fatstrip_height,
|
||||
N_( "set fatstrip height to N (DEBUG)" ), "N" },
|
||||
{ "vips-progress", 'p', 0, G_OPTION_ARG_NONE, &vips__progress,
|
||||
{ "vips-progress", 'p', 0,
|
||||
G_OPTION_ARG_NONE, &vips__progress,
|
||||
N_( "show progress feedback" ), NULL },
|
||||
{ "vips-disc-threshold", 'd', 0, G_OPTION_ARG_STRING,
|
||||
&vips__disc_threshold,
|
||||
N_( "image size above which to decompress to disc" ), NULL },
|
||||
{ "vips-novector", 't', G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE,
|
||||
&vips__vector_enabled,
|
||||
{ "vips-disc-threshold", 'd', 0,
|
||||
G_OPTION_ARG_STRING, &vips__disc_threshold,
|
||||
N_( "images larger than N are decompressed to disc" ), "N" },
|
||||
{ "vips-novector", 't', G_OPTION_FLAG_REVERSE,
|
||||
G_OPTION_ARG_NONE, &vips__vector_enabled,
|
||||
N_( "disable vectorised versions of operations" ), NULL },
|
||||
{ "vips-cache-max", 'x', 0,
|
||||
G_OPTION_ARG_STRING, &vips__cache_max,
|
||||
N_( "cache at most N operations" ), "N" },
|
||||
{ "vips-cache-max-memory", 'm', 0,
|
||||
G_OPTION_ARG_STRING, &vips__cache_max_mem,
|
||||
N_( "cache at most N bytes in memory" ), "N" },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
|
@ -55,6 +55,7 @@
|
||||
|
||||
#include <vips/vips.h>
|
||||
#include <vips/internal.h>
|
||||
#include <vips/debug.h>
|
||||
|
||||
#ifdef WITH_DMALLOC
|
||||
#include <dmalloc.h>
|
||||
@ -1455,3 +1456,43 @@ vips__change_suffix( const char *name, char *out, int mx,
|
||||
vips_strncpy( out + len, new, mx - len );
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
const char unit;
|
||||
int multiplier;
|
||||
} Unit;
|
||||
|
||||
size_t
|
||||
vips__parse_size( const char *size_string )
|
||||
{
|
||||
static Unit units[] = {
|
||||
{ 'k', 1024 },
|
||||
{ 'm', 1024 * 1024 },
|
||||
{ 'g', 1024 * 1024 * 1024 }
|
||||
};
|
||||
|
||||
size_t size;
|
||||
int n;
|
||||
int i, j;
|
||||
char *unit;
|
||||
|
||||
/* An easy way to alloc a buffer large enough.
|
||||
*/
|
||||
unit = g_strdup( size_string );
|
||||
n = sscanf( size_string, "%d %s", &i, unit );
|
||||
if( n > 0 )
|
||||
size = i;
|
||||
if( n > 1 ) {
|
||||
for( j = 0; j < VIPS_NUMBER( units ); j++ )
|
||||
if( tolower( unit[0] ) == units[j].unit ) {
|
||||
size *= units[j].multiplier;
|
||||
break;
|
||||
}
|
||||
}
|
||||
g_free( unit );
|
||||
|
||||
VIPS_DEBUG_MSG( "parse_size: parsed \"%s\" as %zd\n",
|
||||
size_string, size );
|
||||
|
||||
return( size );
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user