# HG changeset patch
# User Sebastien Jodogne <s.jodogne@gmail.com>
# Date 1564755159 -7200
# Node ID 01db33301c3d049ba7433d545d28376ce2c69489
# Parent  16a5e79accff826d3e346fb6c24352a0afc7cf90
valgrind

diff -r 16a5e79accff -r 01db33301c3d Plugins/WSI/Run.py
--- a/Plugins/WSI/Run.py	Fri Aug 02 16:04:41 2019 +0200
+++ b/Plugins/WSI/Run.py	Fri Aug 02 16:12:39 2019 +0200
@@ -60,6 +60,8 @@
 parser.add_argument('--to-tiff',
                     default = '/home/jodogne/Subversion/orthanc-wsi/Applications/i/OrthancWSIDicomToTiff',
                     help = 'Password to the REST API')
+parser.add_argument('--valgrind', help = 'Use valgrind while running the DICOM-izer',
+                    action = 'store_true')
 parser.add_argument('--force', help = 'Do not warn the user',
                     action = 'store_true')
 parser.add_argument('options', metavar = 'N', nargs = '*',
@@ -90,11 +92,20 @@
                         password = args.password,
                         restPort = args.rest)
 
-def CallDicomizer(p):
-    subprocess.check_output([ args.dicomizer,
-                              '--username=%s' % args.username,
-                              '--password=%s' % args.password ] + p,
-                            stderr=subprocess.STDOUT)
+def CallDicomizer(suffix):
+    prefix = []
+    if args.valgrind:
+        prefix = [ 'valgrind' ]
+    
+    log = subprocess.check_output(prefix + [ args.dicomizer,
+                                             '--username=%s' % args.username,
+                                             '--password=%s' % args.password ] + suffix,
+                                  stderr=subprocess.STDOUT)
+
+    # If using valgrind, only print the lines from the log starting
+    # with '==' (they contain the report from valgrind)
+    if args.valgrind:
+        print('\n'.join(filter(lambda x: x.startswith('=='), log.splitlines())))
 
 
 class Orthanc(unittest.TestCase):