History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
Efficient path profiling
1. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
Paper Presentation: Efficient Path Profiling
Paper Author: Thomas Ball, James R. Larus
Aakriti Gupta
Topics in software bug detection
Instructor: Prof. M. K. Ramanathan
Indian Institute of Science
aakriti@cadl.iisc.ernet.in
January 20, 2014
2. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Path Profiling
How often does a control flow path execute?
Experimental Results
3. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Path Profiling
How often does a control flow path execute?
Used in program performance tuning, profile-directed
compilation and software test coverage etc.
Experimental Results
4. 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-directed
compilation and software test coverage etc.
Before this, basic block and control flow edge profiling were
used. Path profiling was assumed to be much more costly.
5. 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-directed
compilation and software test coverage etc.
Before this, basic block and control flow edge profiling were
used. Path profiling was assumed to be much more costly.
This paper shows that accurate path profiling overhead is only
twice as compared to efficient edge profiling.
6. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
Path Profiling vs. Edge Profiling
A
150
120
Path
100
B
C
20
250
D
270
110
160
E
160
Prof1
Prof2
ACDF
ACDEF
ABCDF
ABCDEF
ABDF
ABDEF
90
60
0
100
20
0
110
40
0
100
0
20
F
Can’t uniquely identify path profile using edge profile
Vice versa is possible.
7. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
Edge Profiling Instrumentation
A
Edge
Value
AC
BC
BD
DE
AB
CD
DF
EF
FA
v
u
t
w
u+t
u+v
u+v+t-w
w
u+v+t
v++
u++
B
C
t++
D
w++
E
F
Many variables need to be stored; causes increased memory
accesses.
8. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
Path Profiling Instrumentation
A
r=0
Path
r=2
B
C
r=4
D
count[r]++
r+=1
E
Encoding
ACDF
ACDEF
ABCDF
ABCDEF
ABDF
ABDEF
0
1
2
3
4
5
F
Each path from A to F produces a unique state in register r, which
have been used as an index into an array of counters in block F.
9. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
Optimal Path Profiling
A
A
1
0
2
B
5
B
-2
A
C
C
0
1
4
+1
B
D
D
C
+3
-1
+1
E
E
D
F
F
+1
Optimal
4 instrumented
edges
Max 2 along a
path
4 instrumented
edges
Max along a
path can be
more than 2
(ABCDF)
E
F
5 instrumented
edges
10. 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 that
the sum of values along any path from ENTRY to EXIT is
unique.
Path sums should lie in the range 0 to (number of paths - 1).
11. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
Edge Assignment Algorithm
Algorithm 1 for assigning values to
edges in a DAG.
1: for each vertex v in reverse topological order do
2:
if v is a leaf vertex then
3:
NPaths[v ] = 1
4:
else
5:
NPaths[v ] = 0
6:
for each edge e from v to w do
7:
val(e) = NPaths[v ]
8:
NPaths[v ]+ = NPaths[w ]
9:
end for
10:
end if
11: end for
A
0
2
0
B
C
2
0
D
0
1
E
0
F
Edge Assignment Output
12. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Step 2: Edge Selection (Maximal Spanning Tree)
Weigh edges by
execution frequency
(Edge Profiling is a
pre-requisite?)
A
B
C
Find maximal cost
spanning tree
D
This gives minimal
cost set of the chords
Maximal spanning
tree instruments least
traveled edges
E
F
Experimental Results
13. 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. Now
one by one add a chord and note the weight of the cycle thus
formed. This will serve as the given chord’s instrumentation value.
A
A
A
0
2
0
B
2
2
B
2
0
B
C
C
4
D
2
0
0
D
F
D
0
1
E
0
F
Graph from step 1
Cycle weight = 4,
therefore BD is
instrumented with
value 4
1
E
F
Final result after
step 2
14. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
Step 3: Instrumentation
PRELUDE :- Array of counters allocated and initialized to 0
15. 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
16. 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
17. 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)
18. 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]++
19. 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 from
ENTRY to EXIT containing ’c’.
20. 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 from
ENTRY to EXIT containing ’c’.
To avoid EXIT node updation
A chord ’c’ may update count[r+Inc(c)]++ iff it is the last chord
in every path from ENTRY to EXIT containing ’c’.
21. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Step 3: Instrumentation Output
A
r=0
r=2
B
C
r=4
D
count[r]++
count[r+1]++
E
F
Experimental Results
22. 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 entry
vertex and choose the next edge ’e’ such that largest val(e) is less
than or equal to r. Make r = r - val(e) and proceed.
Suppose r = 3.
A
AB: r = 3-2 = 1
0
2
0
B
C
CD: r = 1
2
0
DE: r = 1-1 = 0
D
EF: r = 0
0
1
E
AB: r = 1
0
F
Hence, path corresponding to r=3 is
ABCDEF.
23. 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 with
DAGs (Directed Acyclic Graphs)
24. 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 with
DAGs (Directed Acyclic Graphs)
But control flow graphs generally contains cycles
25. 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 with
DAGs (Directed Acyclic Graphs)
But control flow graphs generally contains cycles
With unbounded number of paths, which path to track?
26. 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 with
DAGs (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.
27. 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 with
DAGs (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], which
records the path upto the backedge and prepares to record the
path after the backedge.
28. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
Possible Paths
ENTRY
LOOPHEAD(w )
ENTRY
LOOPHEAD(w )
LOOPHEAD(w )
LOOPHEAD(y )
EXIT
EXIT
v
ENTRY to
EXIT
x
ENTRY to v,
then
backedge v
to w.
w to x, then
backedge x
to y.
v to w, then
w to EXIT.
29. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
Instrumenting Backedges: Example
A
r=0
B
4
2
C
D
count[r]++; r=0
E
F
1
count[r]++
G
H
I
This assignment
does not ensure
unique path values.
Example: BCE,
ABCE, ABCEFGI
and BCEFGI all
have value 2.
30. 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 a
dummy edge ENTRY to v.
31. 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 a
dummy edge ENTRY to v.
For each vertex w that is a source of any backedge, add a
dummy edge w to EXIT.
32. 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 a
dummy edge ENTRY to v.
For each vertex w that is a source of any backedge, add a
dummy edge w to EXIT.
Eliminate all backedges except EXIT to ENTRY.
33. 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 a
dummy edge ENTRY to v.
For each vertex w that is a source of any backedge, add a
dummy edge w to EXIT.
Eliminate all backedges except EXIT to ENTRY.
Apply first two steps of Path Profiling Algo (Edge value
assignment and chord increment).
34. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
After applying transformation and Edge value assignment
A
8
2
B
3
0
0
C
D
E
0
F
1
0
G
H
I
2
35. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
After computing chord increments
A(r = 0)
-6
B
13
10
C
2
D
r=0; count[r]++
E
F
-1
-2
count[r]++
G
H
I
’r’ uniquely
determines a
path now.
36. 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.
37. 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 for
instrumentation.
38. 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 for
instrumentation.
Approach: Add a counter along them to record the number of
times they execute.
39. 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 a
pointer. (saves 2 instructions per path)
40. 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 a
pointer. (saves 2 instructions per path)
Initialize r with base address of the array and do pointer
arithmetic when r is updated.
41. 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 a
pointer. (saves 2 instructions per path)
Initialize r with base address of the array and do pointer
arithmetic when r is updated.
This optimization, however reduces the range of increments.
42. 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 a
pointer. (saves 2 instructions per path)
Initialize r with base address of the array and do pointer
arithmetic 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] is
max of the set to reduce the range of increments.
43. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Example
A
A
2
0
5
0
4
B
D
C
1
B
D
C
numPaths[B] = 1; numPaths[C] = 1; numPaths[D] = 4.
Experimental Results
46. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
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 lower
overhead.
Experimental Results
47. 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 lower
overhead.
Programs with considerable hashing have lower overheads if
they have large blocks or longer paths and infrequent
execution of path increments.
48. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
Experimental Results
Results of comparing path predicted from edge profiling
against measured paths.
49. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
Experimental Results
Results of comparing path predicted from edge profiling
against measured paths.
Prediction approach: Use the most frequently executed edge
out of a block.
50. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
Experimental Results
Results of comparing path predicted from edge profiling
against measured paths.
Prediction approach: Use the most frequently executed edge
out of a block.
On average 37.9% (4.3-57.1%) paths correctly predicted.
51. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
Experimental Results
Results of comparing path predicted from edge profiling
against measured paths.
Prediction approach: Use the most frequently executed edge
out of a block.
On average 37.9% (4.3-57.1%) paths correctly predicted.
Also computed the length of the predicted path upto first
mispredicted edge.
52. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
Experimental Results
Results of comparing path predicted from edge profiling
against measured paths.
Prediction approach: Use the most frequently executed edge
out of a block.
On average 37.9% (4.3-57.1%) paths correctly predicted.
Also computed the length of the predicted path upto first
mispredicted edge.
Weighted by the execution frequency, predicted paths were
nearly as good as measured paths (5.1 vs 6.9) but contained
fewer instructions (33.6 vs 88.4).
53. Path Profiling
Path Profiling Algorithm
Arbitrary Control Flow Graph
Optimizations
Experimental Results
Experimental Results
Results of comparing path predicted from edge profiling
against measured paths.
Prediction approach: Use the most frequently executed edge
out of a block.
On average 37.9% (4.3-57.1%) paths correctly predicted.
Also computed the length of the predicted path upto first
mispredicted edge.
Weighted by the execution frequency, predicted paths were
nearly as good as measured paths (5.1 vs 6.9) but contained
fewer instructions (33.6 vs 88.4).
Result is attributed to simple nature of benchmarks.
Consistent with: branches typically follow one direction with
high probability which remains same for different input.