CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 12/6/2006 Lecture 24 – Profilers.

Slides:



Advertisements
Similar presentations
Yaser Zhian Dead Mage IGDI, Workshop 10, May 30 th -31 st, 2013.
Advertisements

Code Tuning Strategies and Techniques
Brown Bag #2 Advanced C++. Topics  Templates  Standard Template Library (STL)  Pointers and Smart Pointers  Exceptions  Lambda Expressions  Tips.
Java Review Interface, Casting, Generics, Iterator.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
1 Lecture 6 Performance Measurement and Improvement.
Reasons to study concepts of PL
B-1 Lecture 2: Problems, Algorithms, and Programs © 2000 UW CSE University of Washington Computer Programming I.
1 Generics and Using a Collection Generics / Parameterized Classes Using a Collection Customizing a Collection using Inheritance Inner Classes Use of Exceptions.
Performance Improvement
Guide To UNIX Using Linux Third Edition
CSE373 Optional Section Java Collections 11/12/2013 Luyi Lu.
1 1 Profiling & Optimization David Geldreich (DREAM)
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
Chocolate Bar! luqili. Milestone 3 Speed 11% of final mark 7%: path quality and speed –Some cleverness required for full marks –Implement some A* techniques.
Review for Midterm Chapter 1-9 CSc 212 Data Structures.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 12/8/2006 Lecture 25 – Closing Words.
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
1 Defensive Programming and Debugging (Chapters 8 and 23 of Code Complete) Tori Bowman CSSE 375, Rose-Hulman September 21, 2007.
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Software Engineering 2003 Jyrki Nummenmaa 1 CASE Tools CASE = Computer-Aided Software Engineering A set of tools to (optimally) assist in each.
Lecture 8. Profiling - for Performance Analysis - Prof. Taeweon Suh Computer Science Education Korea University COM503 Parallel Computer Architecture &
Files COP3275 – PROGRAMMING USING C DIEGO J. RIVERA-GUTIERREZ.
By – Tanvir Alam.  This tutorial offers several things.  You’ll see some neat features of the language.  You’ll learn the right things to google. 
Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice:
Netprog: Java Intro1 Crash Course in Java. Netprog: Java Intro2 Why Java? Network Programming in Java is very different than in C/C++ –much more language.
1 Components of the Virtual Memory System  Arrows indicate what happens on a lw virtual address data physical address TLB page table memory cache disk.
Application Profiling Using gprof. What is profiling? Allows you to learn:  where your program is spending its time  what functions called what other.
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
Timing Programs and Performance Analysis Tools for Analysing and Optimising advanced Simulations.
CS 3500 L Performance l Code Complete 2 – Chapters 25/26 and Chapter 7 of K&P l Compare today to 44 years ago – The Burroughs B1700 – circa 1974.
1 Homework HW5 due today Review a lot of things about allocation of storage that may not have been clear when we covered them in our initial pass Introduction.
Dynamic Data Structures and Generics Chapter 10. Outline Vectors Linked Data Structures Introduction to Generics.
Standard Template Library The Standard Template Library was recently added to standard C++. –The STL contains generic template classes. –The STL permits.
CSE 332: C++ template examples Concepts and Models Templates impose requirements on type parameters –Types that are plugged in must meet those requirements.
Performance Analysis & Code Profiling It’s 2:00AM -- do you know where your program counter is?
Outline Announcements: –HW III due Friday! –HW II returned soon Software performance Architecture & performance Measuring performance.
Topic 3: C Basics CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 11 – gdb and Debugging.
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 12 – C: structs, linked lists, and casts.
Copyright 2014 – Noah Mendelsohn Performance Analysis Tools Noah Mendelsohn Tufts University Web:
File Systems - Part I CS Introduction to Operating Systems.
Week 4 - Friday.  What did we talk about last time?  Some extra systems programming stuff  Scope.
Software Engineering Prof. Dr. Bertrand Meyer March 2007 – June 2007 Chair of Software Engineering Lecture #20: Profiling NetBeans Profiler 6.0.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
Announcements Assignment 2 Out Today Quiz today - so I need to shut up at 4:25 1.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 20 – C++ Subclasses and Inheritance.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Duke CPS Iterators: Patterns and STL l Access a container without knowing how it’s implemented ä libtapestry: first, isDone, next, current iterators.
Beyond Application Profiling to System Aware Analysis Elena Laskavaia, QNX Bill Graham, QNX.
July 10, 2016ISA's, Compilers, and Assembly1 CS232 roadmap In the first 3 quarters of the class, we have covered 1.Understanding the relationship between.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 18 – Linking and Libraries.
Jim Fawcett CSE 691 – Software Modeling and Analysis Fall 2000
CSE 374 Programming Concepts & Tools
CSE 374 Programming Concepts & Tools
CSE 303 Concepts and Tools for Software Development
CSE 374 Programming Concepts & Tools
CS703 - Advanced Operating Systems
CSE 303 Concepts and Tools for Software Development
CSE 303 Concepts and Tools for Software Development
CSE 303 Lecture 25 Loose Ends and Random Topics
CSE 303 Concepts and Tools for Software Development
CSE 303 Concepts and Tools for Software Development
Min Heap Update E.g. remove smallest item 1. Pop off top (smallest) 3
CSE 303 Concepts and Tools for Software Development
CSE 303 Concepts and Tools for Software Development
CSE 303 Concepts and Tools for Software Development
CSE 303 Concepts and Tools for Software Development
Chapter 11 Introduction to Programming in C
Presentation transcript:

CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 12/6/2006 Lecture 24 – Profilers

12/6/2006CSE 303 Lecture 242 Administravia HW7 is due today Short Papers are due Friday

12/6/2006CSE 303 Lecture 243 Last Time Wrap-up software engineering –Readability –Robustness

12/6/2006CSE 303 Lecture 244 Today Wrap-up C++ –Generic Programming –Templates –The Standard Template Library Wrap up Tools –Profilers

12/6/2006CSE 303 Lecture 245 Java Generics Java without generics: less type checking ArrayList l = new ArrayList(); l.add(new Foo()); Foo f = (Foo)l.get(0); Generics add type check and remove cast ArrayList l = new ArrayList (); l.add(new Foo()); Foo f = l.get(0);

12/6/2006CSE 303 Lecture 246 C++ Templates Similar to Java generics in purpose Can be used for: –Functions –Classes –Methods of classes (on newer compilers) Question: How to cope without templates? –Answer: Use void pointers

12/6/2006CSE 303 Lecture 247 Template Syntax For function declaration –Definitions similar –Class declarations/definitions similar template Comparable &findMax( vector &a);

12/6/2006CSE 303 Lecture 248 Templates Are a Giant Hairball! Details vary from compiler to compiler –Standard is very hard to implement –Leaves some questions unanswered Problems with separate compilation –Compiler creates implementation when needed –Should it go in a.cpp or a.h file? Not clear. Warning: C++ templates vs. Java generics –Don't expect them to work the same way –They have rather different semantics

12/6/2006CSE 303 Lecture 249 Standard Template Library (STL) Equivalent of Java Collections API –But uses templates –Strives for flexibility and speed –STL stores copies instead of references Drawbacks –Same drawbacks as templates –Can really obfuscate your code Note long compiler error messages

12/6/2006CSE 303 Lecture 2410 That's all for Templates/STL Want to learn more? –Your book is a good place to start –Practice!

12/6/2006CSE 303 Lecture 2411 Profilers Monitors running program Reports detailed performance information See where program uses most time/space "90/10 rule of programs" –90% of time spent in 10% of the code –Profilers help you find the 10% (bottlenecks) Warning! Profilers can be misleading!

12/6/2006CSE 303 Lecture 2412 Basic Features Different profilers monitor different things gprof : profiler for code produced by gcc gprof is fairly typical and reports –# times each function was called –# times function "A" called function "B" –% time spent in each function Estimated based on samples Profiler periodically checks where program is

12/6/2006CSE 303 Lecture 2413 Profiler Implementation Basics Call counts –Add code to every function-call Updates a table indexed by function pairs –The profiler instruments your code Time samples –Use the processor's timer –Wake-up periodically –Check the value of the program counter

12/6/2006CSE 303 Lecture 2414 Using gprof Call gcc / g++ with option -pg –Both when compiling and linking Compiler will add code for storing call count info Linker will add functions for getting time samples Execute the program to get file gmon.out Run gprof to analyze results gprof profile-me gmon.out > results.txt Examples: –primes-gprof.txt –polytest-gprof.txt & polytest-gprof-abbrev.txt

12/6/2006CSE 303 Lecture 2415 Getting line-by-line results Compile with option -g -pg Run gprof with -l option gprof -l profile-me gmon.out > results.txt

12/6/2006CSE 303 Lecture 2416 Profiler Gotchas Profiler is sampling –Make sure there are enough samples –Program must run for a sufficiently long time Results depend on your inputs –For instance, imagine array is already sorted Programs will run very slow (~1/10 as fast) –Profiler won't report these times –The clock will! Cumulative times based on estimation

12/6/2006CSE 303 Lecture 2417 gprof Estimation Problem Example int g = 0; void c(int i) { if (i) return; for(; i< ; ++i) g++; } void a() { c(0); } void b() { c(1); } int main() { a(); b(); return 0; } See misleading.c & misleading-gprof.txt

12/6/2006CSE 303 Lecture 2418 Poor man's Profiling with "time" Use to measure whole program time –Usage example: time program args Three types of time reported –real: roughly "wall clock" Includes time used by other programs Includes disk access time –user: time spent running code in the program –system: time the O/S spent doing stuff Includes I/O (Note: gprof doesn't measure this)

12/6/2006CSE 303 Lecture 2419 Performance Tuning "First make it work, then make it fast" Steps in performance tuning 1.Get things to work well, write clean code 2.Locate bottlenecks and performance issues –Sometimes they are obvious –Otherwise, profiler can help 3.Optimize your overall program 4.Use low-level tricks if you need to Try compiling with "optimization flags" –gcc / g++ uses -O1, -O2, -O3

12/6/2006CSE 303 Lecture 2420 Summary Profilers help us understand –Where program spends most time –What parts of code are executed most often We use gprof, but many profilers exist –Visual Studio 2005 includes one –Similar goals and similar basic functionality Implementation –Instrument the code –Perform extra work as program runs

12/6/2006CSE 303 Lecture 2421 Reading Optional readings –C++ for Java Programmers Chapter 7: Templates Chapter 10: STL –gprof manual /gprof.html

12/6/2006CSE 303 Lecture 2422 Next Time Concurrency? Wrap-up