10
SDD/DFS Jonas M. Larsen VLT 2 nd Generation Instrumentation Pipelines, 19 Apr 2007 - 1 Jonas M. Larsen Memory debugging Recipe profiling

SDD/DFS Jonas M. Larsen VLT 2 nd Generation Instrumentation Pipelines, 19 Apr 2007 - 1 Jonas M. Larsen Memory debugging Recipe profiling

Embed Size (px)

Citation preview

Page 1: SDD/DFS Jonas M. Larsen VLT 2 nd Generation Instrumentation Pipelines, 19 Apr 2007 - 1 Jonas M. Larsen Memory debugging Recipe profiling

SDD/DFS Jonas M. Larsen VLT 2nd Generation Instrumentation Pipelines, 19 Apr 2007 - 1

Jonas M. Larsen

Memory debuggingRecipe profiling

Page 2: SDD/DFS Jonas M. Larsen VLT 2 nd Generation Instrumentation Pipelines, 19 Apr 2007 - 1 Jonas M. Larsen Memory debugging Recipe profiling

SDD/DFS Jonas M. Larsen VLT 2nd Generation Instrumentation Pipelines, 19 Apr 2007 - 2

Memory debuggingvalgrind

• > valgrind a.out

Page 3: SDD/DFS Jonas M. Larsen VLT 2 nd Generation Instrumentation Pipelines, 19 Apr 2007 - 1 Jonas M. Larsen Memory debugging Recipe profiling

SDD/DFS Jonas M. Larsen VLT 2nd Generation Instrumentation Pipelines, 19 Apr 2007 - 3

Memory debuggingvalgrind

• Memory errors sometimes make programs crash. Other times they don't!

Use a memory debugger regularly (valgrind, gdb, ...)

Page 4: SDD/DFS Jonas M. Larsen VLT 2 nd Generation Instrumentation Pipelines, 19 Apr 2007 - 1 Jonas M. Larsen Memory debugging Recipe profiling

SDD/DFS Jonas M. Larsen VLT 2nd Generation Instrumentation Pipelines, 19 Apr 2007 - 4

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!

Page 5: SDD/DFS Jonas M. Larsen VLT 2 nd Generation Instrumentation Pipelines, 19 Apr 2007 - 1 Jonas M. Larsen Memory debugging Recipe profiling

SDD/DFS Jonas M. Larsen VLT 2nd Generation Instrumentation Pipelines, 19 Apr 2007 - 5

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

Page 6: SDD/DFS Jonas M. Larsen VLT 2 nd Generation Instrumentation Pipelines, 19 Apr 2007 - 1 Jonas M. Larsen Memory debugging Recipe profiling

SDD/DFS Jonas M. Larsen VLT 2nd Generation Instrumentation Pipelines, 19 Apr 2007 - 6

ProfilingGCC gprof

• GCC gprof

Page 7: SDD/DFS Jonas M. Larsen VLT 2 nd Generation Instrumentation Pipelines, 19 Apr 2007 - 1 Jonas M. Larsen Memory debugging Recipe profiling

SDD/DFS Jonas M. Larsen VLT 2nd Generation Instrumentation Pipelines, 19 Apr 2007 - 7

ProfilingGCC gcov

Use profiling tools (gprof, gcov, Shark, ...)

• GCC gcov

Page 8: SDD/DFS Jonas M. Larsen VLT 2 nd Generation Instrumentation Pipelines, 19 Apr 2007 - 1 Jonas M. Larsen Memory debugging Recipe profiling

SDD/DFS Jonas M. Larsen VLT 2nd Generation Instrumentation Pipelines, 19 Apr 2007 - 8

ProfilingAsymptotic time complexity

• Example: Looping through a FITS header

O(n^3)

O(n^2)

O(n)

Page 9: SDD/DFS Jonas M. Larsen VLT 2 nd Generation Instrumentation Pipelines, 19 Apr 2007 - 1 Jonas M. Larsen Memory debugging Recipe profiling

SDD/DFS Jonas M. Larsen VLT 2nd Generation Instrumentation Pipelines, 19 Apr 2007 - 9

Profiling

• Constant factor optimization

• Measure before you optimize!

Page 10: SDD/DFS Jonas M. Larsen VLT 2 nd Generation Instrumentation Pipelines, 19 Apr 2007 - 1 Jonas M. Larsen Memory debugging Recipe profiling

SDD/DFS Jonas M. Larsen VLT 2nd Generation Instrumentation Pipelines, 19 Apr 2007 - 10

Profiling

• If n is large, be careful about...

• Reference: http://www.eso.org/~jmlarsen/pipeline