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

cs510 software engineering
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 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

slide-2
SLIDE 2

Definition of profiling

Table of Contents

1

Definition of profiling

2

Use-cases for profiling

3

GNU gprof Profiler

4

Path Profiling

5

Profiling Applications

Mathias Payer (Purdue University) CS510 Software Engineering 2015 2 / 28

slide-3
SLIDE 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

slide-4
SLIDE 4

Use-cases for profiling

Table of Contents

1

Definition of profiling

2

Use-cases for profiling

3

GNU gprof Profiler

4

Path Profiling

5

Profiling Applications

Mathias Payer (Purdue University) CS510 Software Engineering 2015 4 / 28

slide-5
SLIDE 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

slide-6
SLIDE 6

GNU gprof Profiler

Table of Contents

1

Definition of profiling

2

Use-cases for profiling

3

GNU gprof Profiler

4

Path Profiling

5

Profiling Applications

Mathias Payer (Purdue University) CS510 Software Engineering 2015 6 / 28

slide-7
SLIDE 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

slide-8
SLIDE 8

GNU gprof Profiler

gprof Example

Switch to demo.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 8 / 28

slide-9
SLIDE 9

GNU gprof Profiler

grpof Example 2

Switch to demo 2.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 9 / 28

slide-10
SLIDE 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

slide-11
SLIDE 11

GNU gprof Profiler

ASan Example

Switch to demo 3.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 11 / 28

slide-12
SLIDE 12

Path Profiling

Table of Contents

1

Definition of profiling

2

Use-cases for profiling

3

GNU gprof Profiler

4

Path Profiling

5

Profiling Applications

Mathias Payer (Purdue University) CS510 Software Engineering 2015 12 / 28

slide-13
SLIDE 13

Path Profiling

Path Profiling

How often is a certain control-flow path executed?

A B C D E F

Naive solution: record sequence of executed basic blocks, then increment frequency for given path.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 13 / 28

slide-14
SLIDE 14

Path Profiling

Efficient Path Profiling

A B C D E F

count[r]++ r += 4 r += 2 r += 1

Path Encoding ABDEF ABDF 1 ABCDEF 2 ABCDF 3 ACDEF 4 ACDF 5

Mathias Payer (Purdue University) CS510 Software Engineering 2015 14 / 28

slide-15
SLIDE 15

Path Profiling

Efficient Path Profiling

A

6

B

4

C

2

D

2

E

1

F

1

Each node is annotated with the number of paths from that node to the end: num(n) =

child i num(i)

Mathias Payer (Purdue University) CS510 Software Engineering 2015 15 / 28

slide-16
SLIDE 16

Path Profiling

Efficient Path Profiling (EPP)

A

6

B

4

C

2

D

2

E

1

F

1 r += 4 r += 2 r += 1

Given path sums, encode edge increments as follows:

V X

n1

Y

n2

Z

n3 n1 (n1+n2)

Mathias Payer (Purdue University) CS510 Software Engineering 2015 16 / 28

slide-17
SLIDE 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

slide-18
SLIDE 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.

1

add extra nodes that capture entry and exit of a function;

2

connect entry to loop beginnings;

3

connect loop endings to exit;

4

remove loop edge;

5

store each loop iteration as its own path.

Mathias Payer (Purdue University) CS510 Software Engineering 2015 18 / 28

slide-19
SLIDE 19

Path Profiling

Handling Loops

A B C D A

2

B

1

C

1

D

1

Entry

6

A

4

B

2

C

2

D

1

Exit

1

Mathias Payer (Purdue University) CS510 Software Engineering 2015 19 / 28

slide-20
SLIDE 20

Path Profiling

Handling Loops (2)

Entry

6

A

4

B

2

C

2

D

1

Exit

1 r+ = 4 r+ = 2 r+ = 1

Entry

6

A

4

B

2

C

2

D

1

Exit

1 r+ = 4 r+ = 2 r+ = 1

Mathias Payer (Purdue University) CS510 Software Engineering 2015 20 / 28

slide-21
SLIDE 21

Path Profiling

Handling Loops (3)

A B C D

r+ = 1 count[r] + + r = 4 r+ = 2

Mathias Payer (Purdue University) CS510 Software Engineering 2015 21 / 28

slide-22
SLIDE 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

slide-23
SLIDE 23

Profiling Applications

Table of Contents

1

Definition of profiling

2

Use-cases for profiling

3

GNU gprof Profiler

4

Path Profiling

5

Profiling Applications

Mathias Payer (Purdue University) CS510 Software Engineering 2015 23 / 28

slide-24
SLIDE 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

  • bjects only).

Merging objects reduces memory usage, improves cache locality, reduces GC overhead, and reduces allocation cost.

1Reading assignment: Darko Marinov and Robert O’Callahan, Object Equality

Profiling, OOPSLA’03

Mathias Payer (Purdue University) CS510 Software Engineering 2015 24 / 28

slide-25
SLIDE 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

slide-26
SLIDE 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

slide-27
SLIDE 27

Profiling Applications

OO Best Practices

The following best practices are loosely based on IBM WebSphere Application Server best practices2. Don’t allocate large objects too frequently. Reuse {datasources, connections, objects} Release objects when done. Avoid string concatenation (x+ = y). Minimize cross-thread synchronization.

2https://www-01.ibm.com/software/webservers/appserv/ws_

bestpractices.pdf

Mathias Payer (Purdue University) CS510 Software Engineering 2015 27 / 28

slide-28
SLIDE 28

Profiling Applications

Questions?

?

Mathias Payer (Purdue University) CS510 Software Engineering 2015 28 / 28