Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Paper Presentation: Efficient Path ProfilingPaper Author: Thomas Ball, James R. Larus
Aakriti Gupta
Topics in software bug detectionInstructor: Prof. M. K. Ramanathan
Indian Institute of Science
January 20, 2014
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Path Profiling
How often does a control flow path execute?
Used in program performance tuning, profile-directedcompilation and software test coverage etc.
Before this, basic block and control flow edge profiling wereused. Path profiling was assumed to be much more costly.
This paper shows that accurate path profiling overhead is onlytwice as compared to efficient edge profiling.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Path Profiling
How often does a control flow path execute?
Used in program performance tuning, profile-directedcompilation and software test coverage etc.
Before this, basic block and control flow edge profiling wereused. Path profiling was assumed to be much more costly.
This paper shows that accurate path profiling overhead is onlytwice as compared to efficient edge profiling.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Path Profiling
How often does a control flow path execute?
Used in program performance tuning, profile-directedcompilation and software test coverage etc.
Before this, basic block and control flow edge profiling wereused. Path profiling was assumed to be much more costly.
This paper shows that accurate path profiling overhead is onlytwice as compared to efficient edge profiling.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Path Profiling
How often does a control flow path execute?
Used in program performance tuning, profile-directedcompilation and software test coverage etc.
Before this, basic block and control flow edge profiling wereused. Path profiling was assumed to be much more costly.
This paper shows that accurate path profiling overhead is onlytwice as compared to efficient edge profiling.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Path Profiling vs. Edge Profiling
A
B C
D
E F
120
150
100
20
250
160
110
160
270
Path Prof1 Prof2
ACDF 90 110ACDEF 60 40ABCDF 0 0ABCDEF 100 100ABDF 20 0ABDEF 0 20
Can’t uniquely identify path profile using edge profile
Vice versa is possible.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Edge Profiling Instrumentation
A
B C
D
E F
v++
u++
t++
w++
Edge Value
AC vBC uBD tDE wAB u+tCD u+vDF u+v+t-wEF wFA u+v+t
Many variables need to be stored; causes increased memoryaccesses.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Path Profiling Instrumentation
A
B C
D
E F
r=0
r=2
r=4
r+=1count[r]++
Path Encoding
ACDF 0ACDEF 1ABCDF 2ABCDEF 3ABDF 4ABDEF 5
Each path from A to F produces a unique state in register r, whichhave been used as an index into an array of counters in block F.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Optimal Path Profiling
A
B C
D
E F
0
2
4
+1
Optimal
4 instrumentededges
Max 2 along apath
A
B C
D
E F
5
1
-2
-1
4 instrumentededges
Max along apath can bemore than 2(ABCDF)
A
B C
D
E F
1
0
+1
+3
+1
5 instrumentededges
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Step 1: Edge Assignment
Assign a non-negative constant value to each edge, such thatthe sum of values along any path from ENTRY to EXIT isunique.
Path sums should lie in the range 0 to (number of paths - 1).
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Edge Assignment Algorithm
Algorithm 1 for assigning values toedges in a DAG.
1: for each vertex v in reverse topolog-ical order do
2: if v is a leaf vertex then3: NPaths[v ] = 14: else5: NPaths[v ] = 06: for each edge e from v to w do7: val(e) = NPaths[v ]8: NPaths[v ]+ = NPaths[w ]9: end for
10: end if11: end for
A
B C
D
E F
2
0
0
2
0
1
0
0
Edge Assignment Output
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Step 2: Edge Selection (Maximal Spanning Tree)
Weigh edges byexecution frequency(Edge Profiling is apre-requisite?)
Find maximal costspanning tree
This gives minimalcost set of the chords
Maximal spanningtree instruments leasttraveled edges
A
B C
D
E F
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Step 2: Edge Selection (Event Counting Algorithm)
In the tree found, put the edge assignments as per step 1. Nowone by one add a chord and note the weight of the cycle thusformed. This will serve as the given chord’s instrumentation value.
A
B C
D
E F
2
0
0
2
0
1
0
0
Graph from step 1
A
B
D
F
2
2
0
Cycle weight = 4,therefore BD isinstrumented withvalue 4
A
B C
D
E F
0
2
4
1
Final result afterstep 2
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Step 3: Instrumentation
PRELUDE :- Array of counters allocated and initialized to 0
POSTLUDE :- Array is written out to permanent storage
ENTRY node :- Initialize r := 0
CHORDS :- Update r += Inc(chord)
EXIT node :- Increment path counter count[r]++
To avoid ENTRY node initialization
A chord ’c’ may initialize iff it is the first chord in every path fromENTRY to EXIT containing ’c’.
To avoid EXIT node updation
A chord ’c’ may update count[r+Inc(c)]++ iff it is the last chordin every path from ENTRY to EXIT containing ’c’.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Step 3: Instrumentation
PRELUDE :- Array of counters allocated and initialized to 0
POSTLUDE :- Array is written out to permanent storage
ENTRY node :- Initialize r := 0
CHORDS :- Update r += Inc(chord)
EXIT node :- Increment path counter count[r]++
To avoid ENTRY node initialization
A chord ’c’ may initialize iff it is the first chord in every path fromENTRY to EXIT containing ’c’.
To avoid EXIT node updation
A chord ’c’ may update count[r+Inc(c)]++ iff it is the last chordin every path from ENTRY to EXIT containing ’c’.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Step 3: Instrumentation
PRELUDE :- Array of counters allocated and initialized to 0
POSTLUDE :- Array is written out to permanent storage
ENTRY node :- Initialize r := 0
CHORDS :- Update r += Inc(chord)
EXIT node :- Increment path counter count[r]++
To avoid ENTRY node initialization
A chord ’c’ may initialize iff it is the first chord in every path fromENTRY to EXIT containing ’c’.
To avoid EXIT node updation
A chord ’c’ may update count[r+Inc(c)]++ iff it is the last chordin every path from ENTRY to EXIT containing ’c’.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Step 3: Instrumentation
PRELUDE :- Array of counters allocated and initialized to 0
POSTLUDE :- Array is written out to permanent storage
ENTRY node :- Initialize r := 0
CHORDS :- Update r += Inc(chord)
EXIT node :- Increment path counter count[r]++
To avoid ENTRY node initialization
A chord ’c’ may initialize iff it is the first chord in every path fromENTRY to EXIT containing ’c’.
To avoid EXIT node updation
A chord ’c’ may update count[r+Inc(c)]++ iff it is the last chordin every path from ENTRY to EXIT containing ’c’.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Step 3: Instrumentation
PRELUDE :- Array of counters allocated and initialized to 0
POSTLUDE :- Array is written out to permanent storage
ENTRY node :- Initialize r := 0
CHORDS :- Update r += Inc(chord)
EXIT node :- Increment path counter count[r]++
To avoid ENTRY node initialization
A chord ’c’ may initialize iff it is the first chord in every path fromENTRY to EXIT containing ’c’.
To avoid EXIT node updation
A chord ’c’ may update count[r+Inc(c)]++ iff it is the last chordin every path from ENTRY to EXIT containing ’c’.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Step 3: Instrumentation
PRELUDE :- Array of counters allocated and initialized to 0
POSTLUDE :- Array is written out to permanent storage
ENTRY node :- Initialize r := 0
CHORDS :- Update r += Inc(chord)
EXIT node :- Increment path counter count[r]++
To avoid ENTRY node initialization
A chord ’c’ may initialize iff it is the first chord in every path fromENTRY to EXIT containing ’c’.
To avoid EXIT node updation
A chord ’c’ may update count[r+Inc(c)]++ iff it is the last chordin every path from ENTRY to EXIT containing ’c’.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Step 3: Instrumentation
PRELUDE :- Array of counters allocated and initialized to 0
POSTLUDE :- Array is written out to permanent storage
ENTRY node :- Initialize r := 0
CHORDS :- Update r += Inc(chord)
EXIT node :- Increment path counter count[r]++
To avoid ENTRY node initialization
A chord ’c’ may initialize iff it is the first chord in every path fromENTRY to EXIT containing ’c’.
To avoid EXIT node updation
A chord ’c’ may update count[r+Inc(c)]++ iff it is the last chordin every path from ENTRY to EXIT containing ’c’.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Step 3: Instrumentation Output
A
B C
D
E F
r=0
r=2
r=4
count[r+1]++
count[r]++
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Step 4: Path Generation
Given ’r’ and the control flow graph from step 1, start from entryvertex and choose the next edge ’e’ such that largest val(e) is lessthan or equal to r. Make r = r - val(e) and proceed.
A
B C
D
E F
2
0
0
2
0
1
0
0
Suppose r = 3.
AB: r = 3-2 = 1
AB: r = 1
CD: r = 1
DE: r = 1-1 = 0
EF: r = 0
Hence, path corresponding to r=3 isABCDEF.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Dealing with Arbitrary Control Flow Graphs
The algorithm discussed is capabale of dealing only withDAGs (Directed Acyclic Graphs)
But control flow graphs generally contains cycles
With unbounded number of paths, which path to track?
Approach: Break cycles at loop backedge.
Instrument each backedge with [count[r]++; r=0], whichrecords the path upto the backedge and prepares to record thepath after the backedge.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Dealing with Arbitrary Control Flow Graphs
The algorithm discussed is capabale of dealing only withDAGs (Directed Acyclic Graphs)
But control flow graphs generally contains cycles
With unbounded number of paths, which path to track?
Approach: Break cycles at loop backedge.
Instrument each backedge with [count[r]++; r=0], whichrecords the path upto the backedge and prepares to record thepath after the backedge.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Dealing with Arbitrary Control Flow Graphs
The algorithm discussed is capabale of dealing only withDAGs (Directed Acyclic Graphs)
But control flow graphs generally contains cycles
With unbounded number of paths, which path to track?
Approach: Break cycles at loop backedge.
Instrument each backedge with [count[r]++; r=0], whichrecords the path upto the backedge and prepares to record thepath after the backedge.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Dealing with Arbitrary Control Flow Graphs
The algorithm discussed is capabale of dealing only withDAGs (Directed Acyclic Graphs)
But control flow graphs generally contains cycles
With unbounded number of paths, which path to track?
Approach: Break cycles at loop backedge.
Instrument each backedge with [count[r]++; r=0], whichrecords the path upto the backedge and prepares to record thepath after the backedge.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Dealing with Arbitrary Control Flow Graphs
The algorithm discussed is capabale of dealing only withDAGs (Directed Acyclic Graphs)
But control flow graphs generally contains cycles
With unbounded number of paths, which path to track?
Approach: Break cycles at loop backedge.
Instrument each backedge with [count[r]++; r=0], whichrecords the path upto the backedge and prepares to record thepath after the backedge.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Possible Paths
ENTRY
EXIT
ENTRY toEXIT
ENTRY
LOOPHEAD(w)
v
ENTRY to v,thenbackedge vto w.
LOOPHEAD(w)
LOOPHEAD(y)
x
w to x, thenbackedge xto y.
LOOPHEAD(w)
EXIT
v to w, thenw to EXIT.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Instrumenting Backedges: Example
A
B
C D
E
F
G H
I
r=0
2
4
count[r]++; r=0
1
count[r]++
This assignmentdoes not ensureunique path values.Example: BCE,ABCE, ABCEFGIand BCEFGI allhave value 2.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Solution
For each vertex v that is a target of any backedge, add adummy edge ENTRY to v.
For each vertex w that is a source of any backedge, add adummy edge w to EXIT.
Eliminate all backedges except EXIT to ENTRY.
Apply first two steps of Path Profiling Algo (Edge valueassignment and chord increment).
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Solution
For each vertex v that is a target of any backedge, add adummy edge ENTRY to v.
For each vertex w that is a source of any backedge, add adummy edge w to EXIT.
Eliminate all backedges except EXIT to ENTRY.
Apply first two steps of Path Profiling Algo (Edge valueassignment and chord increment).
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Solution
For each vertex v that is a target of any backedge, add adummy edge ENTRY to v.
For each vertex w that is a source of any backedge, add adummy edge w to EXIT.
Eliminate all backedges except EXIT to ENTRY.
Apply first two steps of Path Profiling Algo (Edge valueassignment and chord increment).
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Solution
For each vertex v that is a target of any backedge, add adummy edge ENTRY to v.
For each vertex w that is a source of any backedge, add adummy edge w to EXIT.
Eliminate all backedges except EXIT to ENTRY.
Apply first two steps of Path Profiling Algo (Edge valueassignment and chord increment).
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
After applying transformation and Edge value assignment
A
B
C D
E
F
G H
I
2
0
8
0
3
0
2
0
1
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
After computing chord increments
A(r = 0)
B
C D
E
F
G H
I
-6
2
10
13
r=0; count[r]++
-2
-1
count[r]++
’r’ uniquelydetermines apath now.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Dealing with Self Loops
Self loops are backedges with same source and target vertex.
We can’t just remove them as it leaves nothing forinstrumentation.
Approach: Add a counter along them to record the number oftimes they execute.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Dealing with Self Loops
Self loops are backedges with same source and target vertex.
We can’t just remove them as it leaves nothing forinstrumentation.
Approach: Add a counter along them to record the number oftimes they execute.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Dealing with Self Loops
Self loops are backedges with same source and target vertex.
We can’t just remove them as it leaves nothing forinstrumentation.
Approach: Add a counter along them to record the number oftimes they execute.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Optimizations
Instead of storing r as index into the count array, make it apointer. (saves 2 instructions per path)
Initialize r with base address of the array and do pointerarithmetic when r is updated.
This optimization, however reduces the range of increments.
In step 1, we can choose edges (v,w) such that NumPath[w] ismax of the set to reduce the range of increments.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Optimizations
Instead of storing r as index into the count array, make it apointer. (saves 2 instructions per path)
Initialize r with base address of the array and do pointerarithmetic when r is updated.
This optimization, however reduces the range of increments.
In step 1, we can choose edges (v,w) such that NumPath[w] ismax of the set to reduce the range of increments.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Optimizations
Instead of storing r as index into the count array, make it apointer. (saves 2 instructions per path)
Initialize r with base address of the array and do pointerarithmetic when r is updated.
This optimization, however reduces the range of increments.
In step 1, we can choose edges (v,w) such that NumPath[w] ismax of the set to reduce the range of increments.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Optimizations
Instead of storing r as index into the count array, make it apointer. (saves 2 instructions per path)
Initialize r with base address of the array and do pointerarithmetic when r is updated.
This optimization, however reduces the range of increments.
In step 1, we can choose edges (v,w) such that NumPath[w] ismax of the set to reduce the range of increments.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Example
A
B
C
D
54
0
A
B
C
D
01
2
numPaths[B] = 1; numPaths[C] = 1; numPaths[D] = 4.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Experimental Results
Path profiling overhead - 30.9% (5.5 to 96.9%).
Edge profiling overhead - 16.1% (-2.6 to 52.8%).
Programs with litte hashing have comparable or loweroverhead.
Programs with considerable hashing have lower overheads ifthey have large blocks or longer paths and infrequentexecution of path increments.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Experimental Results
Path profiling overhead - 30.9% (5.5 to 96.9%).
Edge profiling overhead - 16.1% (-2.6 to 52.8%).
Programs with litte hashing have comparable or loweroverhead.
Programs with considerable hashing have lower overheads ifthey have large blocks or longer paths and infrequentexecution of path increments.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Experimental Results
Path profiling overhead - 30.9% (5.5 to 96.9%).
Edge profiling overhead - 16.1% (-2.6 to 52.8%).
Programs with litte hashing have comparable or loweroverhead.
Programs with considerable hashing have lower overheads ifthey have large blocks or longer paths and infrequentexecution of path increments.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Experimental Results
Path profiling overhead - 30.9% (5.5 to 96.9%).
Edge profiling overhead - 16.1% (-2.6 to 52.8%).
Programs with litte hashing have comparable or loweroverhead.
Programs with considerable hashing have lower overheads ifthey have large blocks or longer paths and infrequentexecution of path increments.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Experimental Results
Results of comparing path predicted from edge profilingagainst measured paths.
Prediction approach: Use the most frequently executed edgeout of a block.
On average 37.9% (4.3-57.1%) paths correctly predicted.
Also computed the length of the predicted path upto firstmispredicted edge.
Weighted by the execution frequency, predicted paths werenearly as good as measured paths (5.1 vs 6.9) but containedfewer instructions (33.6 vs 88.4).
Result is attributed to simple nature of benchmarks.Consistent with: branches typically follow one direction withhigh probability which remains same for different input.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Experimental Results
Results of comparing path predicted from edge profilingagainst measured paths.
Prediction approach: Use the most frequently executed edgeout of a block.
On average 37.9% (4.3-57.1%) paths correctly predicted.
Also computed the length of the predicted path upto firstmispredicted edge.
Weighted by the execution frequency, predicted paths werenearly as good as measured paths (5.1 vs 6.9) but containedfewer instructions (33.6 vs 88.4).
Result is attributed to simple nature of benchmarks.Consistent with: branches typically follow one direction withhigh probability which remains same for different input.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Experimental Results
Results of comparing path predicted from edge profilingagainst measured paths.
Prediction approach: Use the most frequently executed edgeout of a block.
On average 37.9% (4.3-57.1%) paths correctly predicted.
Also computed the length of the predicted path upto firstmispredicted edge.
Weighted by the execution frequency, predicted paths werenearly as good as measured paths (5.1 vs 6.9) but containedfewer instructions (33.6 vs 88.4).
Result is attributed to simple nature of benchmarks.Consistent with: branches typically follow one direction withhigh probability which remains same for different input.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Experimental Results
Results of comparing path predicted from edge profilingagainst measured paths.
Prediction approach: Use the most frequently executed edgeout of a block.
On average 37.9% (4.3-57.1%) paths correctly predicted.
Also computed the length of the predicted path upto firstmispredicted edge.
Weighted by the execution frequency, predicted paths werenearly as good as measured paths (5.1 vs 6.9) but containedfewer instructions (33.6 vs 88.4).
Result is attributed to simple nature of benchmarks.Consistent with: branches typically follow one direction withhigh probability which remains same for different input.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Experimental Results
Results of comparing path predicted from edge profilingagainst measured paths.
Prediction approach: Use the most frequently executed edgeout of a block.
On average 37.9% (4.3-57.1%) paths correctly predicted.
Also computed the length of the predicted path upto firstmispredicted edge.
Weighted by the execution frequency, predicted paths werenearly as good as measured paths (5.1 vs 6.9) but containedfewer instructions (33.6 vs 88.4).
Result is attributed to simple nature of benchmarks.Consistent with: branches typically follow one direction withhigh probability which remains same for different input.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Experimental Results
Results of comparing path predicted from edge profilingagainst measured paths.
Prediction approach: Use the most frequently executed edgeout of a block.
On average 37.9% (4.3-57.1%) paths correctly predicted.
Also computed the length of the predicted path upto firstmispredicted edge.
Weighted by the execution frequency, predicted paths werenearly as good as measured paths (5.1 vs 6.9) but containedfewer instructions (33.6 vs 88.4).
Result is attributed to simple nature of benchmarks.Consistent with: branches typically follow one direction withhigh probability which remains same for different input.
Path Profiling Path Profiling Algorithm Arbitrary Control Flow Graph Optimizations Experimental Results
Thank you.
Top Related