]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Do not initialize Cairo/Pango on export. 789/head
authorSven Panne <svenpanne@gmail.com>
Tue, 30 May 2017 06:11:24 +0000 (08:11 +0200)
committerSven Panne <svenpanne@gmail.com>
Tue, 30 May 2017 06:11:24 +0000 (08:11 +0200)
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.

src/rrd_graph.c
src/rrd_graph.h
src/rrd_xport.c

index a417fc6fbbe98093364430d575b394ff9871aaab..b3b6355d4e77822cc8ddc1e86c86b7321314680f 100644 (file)
@@ -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];
index 77dd2236d3452ab864fb1b88b4d7052c41651699..19c0494bd27b3b695223e0ba5d0a8fbed545ec87 100644 (file)
@@ -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,
index 2edc09e514991932dcd3cd2b70c5f965077c6294..e68cba5b2f3efe04c5b616d0139426d8fb91cbef 100644 (file)
@@ -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);