From: Sven Panne Date: Tue, 30 May 2017 06:11:24 +0000 (+0200) Subject: Do not initialize Cairo/Pango on export. X-Git-Tag: v1.7.1~131^2~1^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F789%2Fhead;p=thirdparty%2Frrdtool-1.x.git Do not initialize Cairo/Pango on export. On a heavily loaded rrdcached, initializing lots of unnecessary Cairo/Pango data structures (surfaces, font-related structures, etc.) is not a good idea. Do this only when we really want to draw something. --- diff --git a/src/rrd_graph.c b/src/rrd_graph.c index a417fc6f..b3b6355d 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -437,6 +437,7 @@ int im_free( } free(im->gdes); + if (im->init_mode == IMAGE_INIT_CAIRO) { for (i = 0; i < DIM(text_prop);i++){ pango_font_description_free(im->text_prop[i].font_desc); im->text_prop[i].font_desc = NULL; @@ -467,6 +468,7 @@ int im_free( g_object_unref(im->layout); } mutex_unlock(im->fontmap_mutex); + } if (im->ylegend) free(im->ylegend); @@ -4590,7 +4592,7 @@ rrd_info_t *rrd_graph_v( rrd_info_t *grinfo; struct optparse options; rrd_thread_init(); - rrd_graph_init(&im); + rrd_graph_init(&im, IMAGE_INIT_CAIRO); /* a dummy surface so that we can measure text sizes for placements */ rrd_graph_options(argc, argv, &options, &im); if (rrd_test_error()) { @@ -4691,8 +4693,8 @@ rrd_set_font_desc ( } void rrd_graph_init( - image_desc_t - *im) + image_desc_t *im, + enum image_init_en init_mode) { unsigned int i; char *deffont = getenv("RRD_DEFAULT_FONT"); @@ -4717,7 +4719,6 @@ void rrd_graph_init( im->draw_3d_border = 2; im->dynamic_labels = 0; im->extra_flags = 0; - im->font_options = cairo_font_options_create(); im->forceleftspace = 0; im->gdes_c = 0; im->gdes = NULL; @@ -4779,7 +4780,10 @@ void rrd_graph_init( im->yOriginTitle = 0; im->ysize = 100; im->zoom = 1; + im->init_mode = init_mode; + if (init_mode == IMAGE_INIT_CAIRO) { + im->font_options = cairo_font_options_create(); im->surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 10, 10); im->cr = cairo_create(im->surface); im->fontmap_mutex = &fontmap_mutex; @@ -4818,6 +4822,7 @@ void rrd_graph_init( cairo_font_options_set_antialias(im->font_options, CAIRO_ANTIALIAS_GRAY); mutex_unlock(im->fontmap_mutex); + } for (i = 0; i < DIM(graph_col); i++) im->graph_col[i] = graph_col[i]; diff --git a/src/rrd_graph.h b/src/rrd_graph.h index 77dd2236..19c0494b 100644 --- a/src/rrd_graph.h +++ b/src/rrd_graph.h @@ -262,6 +262,8 @@ typedef struct graph_desc_t { int yaxisidx; } graph_desc_t; +enum image_init_en { IMAGE_INIT_NO_CAIRO, IMAGE_INIT_CAIRO }; + typedef struct image_desc_t { /* configuration of graph */ @@ -348,6 +350,7 @@ typedef struct image_desc_t { GHashTable* gdef_map; /* a map of all *def gdef entries for quick access */ GHashTable* rrd_map; /* a map of all rrd files in use for gdef entries */ mutex_t *fontmap_mutex; /* Mutex for locking the global fontmap */ + enum image_init_en init_mode; /* do we need Cairo/Pango? */ } image_desc_t; /* Prototypes */ @@ -446,7 +449,8 @@ int scan_for_col( int, char *const); void rrd_graph_init( - image_desc_t *); + image_desc_t *, + enum image_init_en); void time_clean( char *result, diff --git a/src/rrd_xport.c b/src/rrd_xport.c index 2edc09e5..e68cba5b 100644 --- a/src/rrd_xport.c +++ b/src/rrd_xport.c @@ -77,7 +77,7 @@ int rrd_xport( }; rrd_thread_init(); - rrd_graph_init(&im); + rrd_graph_init(&im, IMAGE_INIT_NO_CAIRO); rrd_parsetime("end-24h", &start_tv); rrd_parsetime("now", &end_tv);