100 likes | 213 Views
Memory debugging Recipe profiling. Jonas M. Larsen. Memory debugging valgrind. > valgrind a.out. Memory debugging valgrind. Memory errors sometimes make programs crash. Other times they don't!. Use a memory debugger regularly (valgrind, gdb, ...). Profiling. Reasons to optimize
E N D
Memory debuggingRecipe profiling Jonas M. Larsen
Memory debuggingvalgrind • > valgrind a.out
Memory debuggingvalgrind • Memory errors sometimes make programs crash. Other times they don't! Use a memory debugger regularly (valgrind, gdb, ...)
Profiling • Reasons to optimize • The pipeline must process at about the same speed as observations are performed • Trade-off: Science quality vs. execution speed • Reasons not to optimize • “slow” can be “fast enough” • Trade-off: CPU cycles vs. human brain cycles • Trade-off: Design vs. speed • Measure before you optimize!
Profilingprofile_build • > profile_build -qfitssrc=~/qfits-6.2.0 -cplsrc=~/cpl-3.1.0 -esorexsrc=~/esorex-3.6.1 -iiinstrumentsrc=~/xshp -builddir=~/BUILD -iiinstrumentlib=xsh xsh_mbias • > ~/BUILD/bin/esorex xsh_mbias xsh_mbias.sof • > gprof ~/BUILD/bin/esorex • > gcov my_source_file.c
ProfilingGCC gprof • GCC gprof
ProfilingGCC gcov • GCC gcov Use profiling tools (gprof, gcov, Shark, ...)
ProfilingAsymptotic time complexity • Example: Looping through a FITS header O(n^3) O(n^2) O(n)
Profiling • Constant factor optimization • Measure before you optimize!
Profiling • If n is large, be careful about... • Reference: http://www.eso.org/~jmlarsen/pipeline