cs510 software engineering
play

CS510 Software Engineering Program Profiling Asst. Prof. Mathias - PowerPoint PPT Presentation

CS510 Software Engineering Program Profiling Asst. Prof. Mathias Payer Department of Computer Science Purdue University TA: Scott A. Carr Slides inspired by Xiangyu Zhang http://nebelwelt.net/teaching/15-CS510-SE Spring 2015 Definition of


  1. CS510 Software Engineering Program Profiling Asst. Prof. Mathias Payer Department of Computer Science Purdue University TA: Scott A. Carr Slides inspired by Xiangyu Zhang http://nebelwelt.net/teaching/15-CS510-SE Spring 2015

  2. Definition of profiling Table of Contents Definition of profiling 1 Use-cases for profiling 2 GNU gprof Profiler 3 Path Profiling 4 Profiling Applications 5 Mathias Payer (Purdue University) CS510 Software Engineering 2015 2 / 28

  3. Definition of profiling Definition of Profiling Profiling Profiling is a lossy technique that aggregates execution information to finite entries. While tracing is lossless (i.e., records every detail of the execution), profiling is lossy. Think: counting versus sampling. Examples: control-flow profiling based on instruction/edge/function frequency or value profiling based on value frequency. Mathias Payer (Purdue University) CS510 Software Engineering 2015 3 / 28

  4. Use-cases for profiling Table of Contents Definition of profiling 1 Use-cases for profiling 2 GNU gprof Profiler 3 Path Profiling 4 Profiling Applications 5 Mathias Payer (Purdue University) CS510 Software Engineering 2015 4 / 28

  5. Use-cases for profiling Use-cases for profiling Optimization: identify hot program paths; Optimization: data compression; Optimization: value speculation; Optimization: data locality detection (for caching); Optimization: performance tuning; Testing: code coverage; Debugging: check execution frequencies. Mathias Payer (Purdue University) CS510 Software Engineering 2015 5 / 28

  6. GNU gprof Profiler Table of Contents Definition of profiling 1 Use-cases for profiling 2 GNU gprof Profiler 3 Path Profiling 4 Profiling Applications 5 Mathias Payer (Purdue University) CS510 Software Engineering 2015 6 / 28

  7. GNU gprof Profiler GNU gprof Profiler gprof is a profiler for C programs, profiling execution times for functions and procedures with frequency-annotated call edges. Compile a program with -g -pg to enable profiling and debug information. gcc then instruments function entry and exit of each function to record per-function calling frequencies. Per-function execution time is sampled (leading to imprecision). After execution a gmon.out file is created which can be viewed using gprof ./exec . Mathias Payer (Purdue University) CS510 Software Engineering 2015 7 / 28

  8. GNU gprof Profiler gprof Example Switch to demo. Mathias Payer (Purdue University) CS510 Software Engineering 2015 8 / 28

  9. GNU gprof Profiler grpof Example 2 Switch to demo 2. Mathias Payer (Purdue University) CS510 Software Engineering 2015 9 / 28

  10. GNU gprof Profiler Address Sanitizer: Quick look The run-time library replaces the malloc and free functions. The memory around malloc-ed regions (red zones) is poisoned. The free-ed memory is placed in quarantine and also poisoned. Every memory access in the program is transformed by the compiler in the following way: if (isPoisoned(address)) { error(); } stmt; . Mathias Payer (Purdue University) CS510 Software Engineering 2015 10 / 28

  11. GNU gprof Profiler ASan Example Switch to demo 3. Mathias Payer (Purdue University) CS510 Software Engineering 2015 11 / 28

  12. Path Profiling Table of Contents Definition of profiling 1 Use-cases for profiling 2 GNU gprof Profiler 3 Path Profiling 4 Profiling Applications 5 Mathias Payer (Purdue University) CS510 Software Engineering 2015 12 / 28

  13. Path Profiling Path Profiling How often is a certain control-flow path executed? A Naive solution: record B C sequence of executed basic blocks, then increment D frequency for given path. E F Mathias Payer (Purdue University) CS510 Software Engineering 2015 13 / 28

  14. Path Profiling Efficient Path Profiling Path Encoding A r += 4 ABDEF 0 r += 2 ABDF 1 B C ABCDEF 2 ABCDF 3 D r += 1 ACDEF 4 ACDF 5 count[r]++ E F Mathias Payer (Purdue University) CS510 Software Engineering 2015 14 / 28

  15. Path Profiling Efficient Path Profiling A 6 Each node is annotated with 4 B C 2 the number of paths from that node to the end: D 2 num ( n ) = � child i num ( i ) 1 E F 1 Mathias Payer (Purdue University) CS510 Software Engineering 2015 15 / 28

  16. Path Profiling Efficient Path Profiling (EPP) Given path sums, encode A 6 r += 4 edge increments as follows: r += 2 V 4 B C 2 (n1+n2) n1 0 n1 X Z n3 D 2 r += 1 Y 1 E F 1 n2 Mathias Payer (Purdue University) CS510 Software Engineering 2015 16 / 28

  17. Path Profiling Path Regeneration Start at the top of the graph with count P. Follow highest possible path so that P does not become negative. Repeat until you reach the bottom with P = 0. Mathias Payer (Purdue University) CS510 Software Engineering 2015 17 / 28

  18. Path Profiling Handling Loops How could loops be handled in this approach? Some part of the graph is executed multiple times, we need to define a way to capture this behavior. add extra nodes that capture entry and exit of a function; 1 connect entry to loop beginnings; 2 connect loop endings to exit; 3 remove loop edge; 4 store each loop iteration as its own path. 5 Mathias Payer (Purdue University) CS510 Software Engineering 2015 18 / 28

  19. Path Profiling Handling Loops Entry 6 A B 2 A B 1 4 A B 2 C C 1 C 2 D D 1 D 1 Exit 1 Mathias Payer (Purdue University) CS510 Software Engineering 2015 19 / 28

  20. Path Profiling Handling Loops (2) Entry Entry 6 6 r + = 4 r + = 4 r + = 2 r + = 2 4 A B 2 4 A B 2 C C 2 2 r + = 1 r + = 1 1 D 1 D Exit Exit 1 1 Mathias Payer (Purdue University) CS510 Software Engineering 2015 20 / 28

  21. Path Profiling Handling Loops (3) r + = 2 A B r + = 1 count [ r ] + + r = 4 C D Mathias Payer (Purdue University) CS510 Software Engineering 2015 21 / 28

  22. Path Profiling EPP Characteristics EPP causes 40% overhead on average. Problem of path explosion: number of paths becomes too large to enumerate for complex functions, resort to hash maps. Allows efficient tracing (compared to alternatives). Reading assignment: Efficient Path Profiling, by T. Ball and J. Larus, Micro 1996. Mathias Payer (Purdue University) CS510 Software Engineering 2015 22 / 28

  23. Profiling Applications Table of Contents Definition of profiling 1 Use-cases for profiling 2 GNU gprof Profiler 3 Path Profiling 4 Profiling Applications 5 Mathias Payer (Purdue University) CS510 Software Engineering 2015 23 / 28

  24. Profiling Applications Optimization: Object Equality Profiling Observation: object creation and destruction are expensive. 1 Observation: some (many?) objects are equal. Idea: merge equivalent objects into single object. Requires: all objects have the same field values. Requires: all references are redirected to a single object. Requires: updates are synchronized/valid (safe: for read-only objects only). Merging objects reduces memory usage, improves cache locality, reduces GC overhead, and reduces allocation cost. 1 Reading assignment: Darko Marinov and Robert O’Callahan, Object Equality Profiling, OOPSLA’03 Mathias Payer (Purdue University) CS510 Software Engineering 2015 24 / 28

  25. Profiling Applications Mergeability requirements Both objects are of the same class. Each pair of corresponding field values is either identical or are references to objects that are mergeable themselves (recursive definition). Neither object is mutated in the future. The objects have (partially) overlapping lifetimes. Mathias Payer (Purdue University) CS510 Software Engineering 2015 25 / 28

  26. Profiling Applications Mergeability Profiling Profiler produces triplets: ( class , allocation site , estimated saving ) Information needed: allocation times, last references, field values. All memory allocation must be traced. Results: memory footprint reduction of 37% and 47% for two SpecJVM programs. Only small program changes needed (1 line for DB). Mathias Payer (Purdue University) CS510 Software Engineering 2015 26 / 28

  27. Profiling Applications OO Best Practices The following best practices are loosely based on IBM WebSphere Application Server best practices 2 . Don’t allocate large objects too frequently. Reuse { datasources , connections , objects } Release objects when done. Avoid string concatenation ( x + = y ). Minimize cross-thread synchronization. 2 https://www-01.ibm.com/software/webservers/appserv/ws_ bestpractices.pdf Mathias Payer (Purdue University) CS510 Software Engineering 2015 27 / 28

  28. Profiling Applications Questions? ? Mathias Payer (Purdue University) CS510 Software Engineering 2015 28 / 28

Recommend


More recommend