1 / 25

Profiling

Profiling. Chihao Li , Department of Mathematics, National Taiwan University 2011/7/7. What is Profiling?. A good program need?. Accuracy? Effeciency ? Readability? Rewritability ? Easy to debug?. When to Profile?. Time to use is “using time”!.

lenka
Download Presentation

Profiling

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Profiling Chihao Li, Department of Mathematics, National Taiwan University2011/7/7

  2. What is Profiling? Profiling

  3. A good program need? • Accuracy? • Effeciency? • Readability? • Rewritability? • Easy to debug? Profiling

  4. When to Profile? Profiling

  5. Time to use is “using time”! • To evaluate the difference of executing time. • Decide which step costs the most time. • Goal: improve the efficiency. Profiling

  6. Memory control and Debugging Profiling

  7. prof/gprof: Execution Profiling • Generate information of the detailed executing time on each function. • Use flags: -p/-pgfor prof/gprof. • $ gcc-pg *.c • $ time ./a.out • $ gprofa.outgmon.out -bp Profiling

  8. Assertion • Instead of using printffor debugging, we can use the macro assert: Profiling

  9. Assertion (conti.) • gcc -o assert assert.c -lm • ./assert Profiling

  10. Memory leak & Electric Fence • Memory leak: once you mallocthe memory but forget to free it, it is hard to debug but it is very important to find out. • Eletric Fence by Bruce Perens is a useful tool. Profiling

  11. Electric Fence Profiling

  12. Electric Fence (conti.) • $ gcc-o efenceefence.c • $ ./efence • $ gcc -o efenceefence.c -lefence • $ ./efence • $ gcc -g -o efenceefence.c -lefence Profiling

  13. valgrind • valgrind is another tool, you don’t need to recompile the code while using it. Profiling

  14. vargrind (conti.) Profiling

  15. valgrind (conti.) • $ valgrind --leak-check=yes -v ./checker Profiling

  16. Demo Profiling

  17. How to Profile in MATLAB? Profiling

  18. Outline • tic & toc • clock • etime • profile Profiling

  19. tic & toc • tic: Start a stopwatch timer. • toc: Read the stopwatch timer. • ticand tocfunction work together to measure elapsed time between the two. • Sample: Profiling

  20. clock • Returns current date and time as a vector. • The vector is in a decimal form containing 6 elements: • [year, month, day, hour, minute, second] • Sample: Profiling

  21. etime • etime(t1, t0)returns the time in seconds that has elapsed between vectors t1andt0. • t0andt1must be the format returned by clock. • Sample: Profiling

  22. profile • Returnssummaryoffunction calls and total time. Profiling

  23. profile - GUI • As an alternative to the profile function, • Select Desktop > Profiler to open the Profiler. • Click the “Profiler” button. • do not include “.m” in the “Run this code” field. Profiling

  24. Demo Profiling

  25. Reference • http://blogs.mathworks.com/videos/2006/10/19/profiler-to-find-code-bottlenecks/ • 鳥哥的Linux私房菜http://linux.vbird.org/ • http://www.cprogramming.com/debugging/valgrind.html • http://catchtest.pixnet.net/blog/post/22080405 • http://nixchun.pixnet.net/blog/post/12331954 Profiling

More Related