mapnik / mapnik-support

Use the issues queue here to ask questions and offer help on using Mapnik (maybe if this works well we can retire the mailing list at http://mapnik.org/contact/?)
6 stars 6 forks source link

valgrind test #95

Open am2222 opened 7 years ago

am2222 commented 7 years ago

Hi, It is for a while that I am working with mapnik, one of my problems is how to integrate valgrind test for memory leak analyses into mapnik input plugins. As far as I am concerned I have to integrate valgrind into scons system, for example in gdal plugin a dependency is deffined in PLUGINS variable in sconstract file should I add valgrinds headers too? thanks

talaj commented 7 years ago

Hi, valgrind should be able to detect memory leaks in dynamically loaded plugins. I have tried it now by creating a memory leak in GDAL plugin.

If there is some system limitation in using valgrind with dynamically loaded libraries, it should be possible to statically link all plugins by PLUGIN_LINKING.

am2222 commented 7 years ago

@talaj Thanks for your help, Can you please explain its procedure? for example in GDAL plugin?

talaj commented 7 years ago

I make a memory leak:

diff --git a/plugins/input/gdal/gdal_datasource.cpp b/plugins/input/gdal/gdal_datasource.cpp
index 1ac6557fe..9cc11878b 100644
--- a/plugins/input/gdal/gdal_datasource.cpp
+++ b/plugins/input/gdal/gdal_datasource.cpp
@@ -61,6 +61,7 @@ gdal_datasource::gdal_datasource(parameters const& params)
       nodata_value_(params.get<double>("nodata")),
       nodata_tolerance_(*params.get<double>("nodata_tolerance",1e-12))
 {
+    new char[123];
     MAPNIK_LOG_DEBUG(gdal) << "gdal_datasource: Initializing...";

 #ifdef MAPNIK_STATS

Complile Mapnik from sources. When compiled, I use the visual test runner test/visual/run to run Mapnik against this style.

 $ valgrind test/visual/run --agg -s 1 raster-color-to-alpha1
==16387== Memcheck, a memory error detector
==16387== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==16387== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==16387== Command: test/visual/run --agg -s 1 raster-color-to-alpha1
==16387==
.
Visual rendering: 0 failed / 1 passed / 0 overwritten / 0 errors
==16387==
==16387== HEAP SUMMARY:
==16387==     in use at exit: 178,819 bytes in 413 blocks
==16387==   total heap usage: 22,056 allocs, 21,643 frees, 7,643,454 bytes allocated
==16387==
==16387== LEAK SUMMARY:
==16387==    definitely lost: 123 bytes in 1 blocks
==16387==    indirectly lost: 0 bytes in 0 blocks
==16387==      possibly lost: 0 bytes in 0 blocks
==16387==    still reachable: 178,696 bytes in 412 blocks
==16387==         suppressed: 0 bytes in 0 blocks
==16387== Rerun with --leak-check=full to see details of leaked memory
==16387==
==16387== For counts of detected and suppressed errors, rerun with: -v
==16387== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
talaj commented 7 years ago

But you don't have to build Mapnik yourself. Just run your program through valgrind.

am2222 commented 7 years ago

@talaj thanks for your help,I'll check it and report the results .thanks

talaj commented 7 years ago

If you have memory leaks with Mapnik and GDAL, check your GDAL version. I have fixed leaks with GDAL version 1.x by upgrading to GDAL 2.x.

talaj commented 7 years ago

@am2222 Concerning GDAL memory usage it is also good to know that libtiff allocates memory for tile or strip positions and lengths. Having TIFF with 4000 x 4000 tiles will take 256 MB of memory.

am2222 commented 7 years ago

@talaj thanks for your information, I noticed a grind option in mapnik build system, Does it have any relations to valgrind tests?

talaj commented 7 years ago

There is grind target in the makefile which should run valgrind on Mapnik's tests but I don't know if anyone is using it. It doesn't work for me neither.

am2222 commented 7 years ago

@talaj yes it did not work for me too. I have no idea about its usage, thanks very much.