pleasures and pitfalls of profiling primož gabrijelčič
TRANSCRIPT
![Page 1: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/1.jpg)
Pleasures and Pitfalls of ProfilingPrimož Gabrijelčič
![Page 2: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/2.jpg)
What? When? How?
![Page 3: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/3.jpg)
What Is profiling?
• A form of dynamic analysis that measures some aspect of the program execution, typically:– Memory usage– Resource usage– Frequency and duration of function calls
![Page 4: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/4.jpg)
When to profile?
“We should forget about small efficiencies, say about 97% of the
time: premature optimization is the root of all evil.
Yet we should not pass up our opportunities in that critical 3%.”
-Donald Knuth
![Page 5: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/5.jpg)
Tools
• “Optimization by guesswork” – bad!
• Hardcoded time measurement and logging
• Profilers
![Page 6: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/6.jpg)
Profilers
• Sampling (statistical)
• Instrumenting– Source instrumenting– Code instrumenting
• (Event based)
• (Hypervisor)
![Page 7: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/7.jpg)
Tools
![Page 8: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/8.jpg)
AQTime
• smartbear.com/products/development-tools/performance-profiling/
• Delphi, C++ Builder, .NET (incl. Silverlight), Java …
• Integration with RAD Studio and Visual Studio – D2006 and newer
• 32- and 64- bit• Comes with XE and XE2 (limited version)• $ 599
![Page 9: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/9.jpg)
AQTime
• Performance profiler
• Allocation (memory) profiler
• Coverage profiler
• Static analysis profiler
• Load library tracer profiler
• More …
![Page 10: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/10.jpg)
ProDelphi
• www.prodelphi.de• Delphi 5 – XE2• 32- and 64- bit• Very precise profiling• Free version (20 procedures)• Separate Ansi and Unicode version• Separate 32- and 64- bit version• 50 – 90 €
![Page 11: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/11.jpg)
Sampling Profiler
• delphitools.info/samplingprofiler
• Delphi 5 – XE (officially), works with XE2
• Measures time spent in OS DLLs
• Works at line level
• Real-time monitor
• Free
![Page 12: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/12.jpg)
DIY
![Page 13: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/13.jpg)
Fixing performance problems
![Page 14: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/14.jpg)
Fixing performance problems
• Better algorithm – Less memory allocations– Less string manipulations– Using different Windows controls
• Faster code – Code optimization– Handcrafted assembler; using MMX/SSE
• Assembler tricks will not make up for bad design, however, they can make good design go faster.
![Page 15: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/15.jpg)
Profiler FAIL
• Distributed algorithms (GUI, messaging) are hard to profile
• Optimizing the inner code of an infinite loop doesn’t help
• If time is spent in kernel, reason may be hard to find
![Page 16: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/16.jpg)
Hands-on!
![Page 17: Pleasures and Pitfalls of Profiling Primož Gabrijelčič](https://reader035.vdocuments.net/reader035/viewer/2022062407/56649dc55503460f94ab8fd1/html5/thumbnails/17.jpg)
Questions?