From abc989069a0fef5c18cbbc7615728f729e97aeb3 Mon Sep 17 00:00:00 2001 From: Dominic Kempf <dominic.kempf@iwr.uni-heidelberg.de> Date: Wed, 6 Feb 2019 13:23:57 +0100 Subject: [PATCH] [cmake] Allow wrapping a statistic profiler around the code generation tool chain Enable with the cmake variable DUNE_CODEGEN_PROFILING. For each generated header, a profile is written out. These can be visualized with tools like snakeviz. --- cmake/modules/DuneCodegenMacros.cmake | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/cmake/modules/DuneCodegenMacros.cmake b/cmake/modules/DuneCodegenMacros.cmake index 69de840c..6a02c016 100644 --- a/cmake/modules/DuneCodegenMacros.cmake +++ b/cmake/modules/DuneCodegenMacros.cmake @@ -71,6 +71,13 @@ # Regeneration is triggered correctly if the UFL file or the # form compiler changed. # +# .. cmake_variable:: DUNE_CODEGEN_PROFILING +# +# Set this variable from your opts file to enable statistic profiling of +# the code generation process. This usually introduces additional cost. +# A cProfile file for post processing will be written whenever the code +# generator is run. +# add_custom_target(generation) @@ -163,11 +170,25 @@ function(add_generated_executable) ) parse_python_data(PREFIX depdata INPUT ${depdata}) + if(DUNE_CODEGEN_PROFILING) + # This is a bit silly, but cProfile only finds entry point scripts + # if their full path is provided. So we resort to using which. + dune_execute_process(COMMAND which generate_operators + OUTPUT_VARIABLE fullcommand + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + endif() + # Define build rules for all operator header files and gather a list of them set(header_deps) foreach(op ${depdata___operators}) + set(GENERATION_COMMAND generate_operators) + if(DUNE_CODEGEN_PROFILING) + set(GENERATION_COMMAND python -m cProfile -o ${depdata___${op}}.prof ${fullcommand}) + endif() + add_custom_command(OUTPUT ${depdata___${op}} - COMMAND ${CMAKE_BINARY_DIR}/run-in-dune-env generate_operators + COMMAND ${CMAKE_BINARY_DIR}/run-in-dune-env ${GENERATION_COMMAND} --project-basedir ${CMAKE_BINARY_DIR} ${GEN_FORM_COMPILER_ARGS} --uflfile ${GEN_UFLFILE} -- GitLab