500 likes | 617 Views
Online Subpath Profiling. Yossi Matias David Oren Mooly Sagiv School of Computer Science Tel-Aviv University. Motivation for Profiling. Feedback on dynamic program behavior The 80-20 rule Can be used by: Computer Architects Compiler Writers Programmers Better program performance.
E N D
Online Subpath Profiling Yossi Matias David Oren Mooly Sagiv School of Computer Science Tel-Aviv University
Motivation for Profiling • Feedback on dynamic program behavior • The 80-20 rule • Can be used by: • Computer Architects • Compiler Writers • Programmers • Better program performance
Types of Profiling • Vertex profiling • No context, just count of instructions • Edge profiling • Branch-transition • Profile-directed optimization • Path profiling • Multiple branch-transition • Intra- or inter-procedural
Types of Profiling • Offline • Results are collected and then displayed • User in the loop • Online • Results are collected and acted upon • JIT compilation • Display to user
if (condition1) doA () doB () doCommon () doMore () if (condition2) doC () doD () Motivation for Subpath Profiling • Programs may have hot subpaths • which are part of cold paths
Challenges • Large number of subpaths • >4M distinct subpaths of length 2,4,...,64k in JLex • >35M total subpaths • Counting all subpaths is prohibitively expensive • Memory • Time • non linear
Online Subpath Profiler • Based on an adaptive sampling technique • Identifies arbitrary hot subpaths • Low memory overhead • Low runtime overhead • Online • Appropriate for JIT-like compilers • Can be adapted to different requirements
Outline • Algorithm overview • Adaptive sampling • Issues • The OSP algorithm • Reference implementation • Experimental results • Related work • Conclusion
Algorithm Overview • Select on-the-fly a random sample of subpaths • Count the popularity of sampled subpaths and obtain estimation by scaling • Achieve high accuracy using limited memory
Adaptive Sampling • Based on a hot-list algorithm by Gibbons and Matias (SIGMOD 1998) • Sample elements from the input set • Frequently occurring elements will be sampled more often • Sampling probability determined at runtime, according to the allowed memory usage • Tradeoff between overhead and accuracy • Give an estimate of the sample’s accuracy
Concise Samples • Uniform random sampling • Maintain an <id, count> pair for each element • The sample size can be much larger than the memory size • For skewed input sets the gain is much larger • Sampling is not applied at every block • Vitter’s reservoir sampling
Issues • Encoding • Generating a unique ID for paths • Path length bias • Longer or shorter paths? • Path representation
Sampled path Sampled path Basic blocks skipped Basic blocks skipped The OSP Algorithm void enterBlock (BasicBlock b) { if (sampling) sampleBlock (b); else if (--skip == 0) { length = choosePathLength (); sampling = true; } } void sampleBlock (BasicBlock b) { subpath.appendBlock (b); if (--length == 0) { updateHotList (subpath.id); skip = chooseSkipValue (); subpath = new subPath (); sampling = false; } }
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 5 sampling = false void enterBlock (BasicBlock b) { if (sampling) sampleBlock (b); else if (--skip == 0) { length = choosePathLength (); sampling = true; } } Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 4 sampling = false Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 3 sampling = false Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 2 sampling = false Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 1 sampling = false Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 0 length = 2 sampling = true void enterBlock (BasicBlock b) { if (sampling) sampleBlock (b); else if (--skip == 0) { length = choosePathLength (); sampling = true; } } Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 0 length = 1 sampling = true Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 4 length = 0 sampling = false doA-doCommon: 1 void sampleBlock (BasicBlock b) { subpath.appendBlock (b); if (--length == 0) { updateHotList (subpath.id); skip = chooseSkipValue (); subpath = new subPath (); sampling = false; } } Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 3 sampling = false doA-doCommon: 1 Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 2 sampling = false doA-doCommon: 1 Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 1 sampling = false doA-doCommon: 1 Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 0 length = 2 sampling = true doA-doCommon: 1 Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 0 length = 1 sampling = true doA-doCommon: 1 Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 8 sampling = false doA-doCommon: 1 doCommon-if2: 1 Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 7 sampling = false doA-doCommon: 1 doCommon-if2: 1 Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 6 sampling = false doA-doCommon: 1 doCommon-if2: 1 Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 5 sampling = false doA-doCommon: 1 doCommon-if2: 1 Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 4 sampling = false doA-doCommon: 1 doCommon-if2: 1 Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 3 sampling = false doA-doCommon: 1 doCommon-if2: 1 Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 2 sampling = false doA-doCommon: 1 doCommon-if2: 1 Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 1 sampling = false doA-doCommon: 1 doCommon-if2: 1 Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 0 length = 2 sampling = true doA-doCommon: 1 doCommon-if2: 1 Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 0 length = 1 sampling = true doA-doCommon: 1 doCommon-if2: 1 Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () OSP Algorithm Walkthrough skip = 6 sampling = false doA-doCommon: 1 doCommon-if2: 2 Skipping Sampling
if (condition1) doA () doB () doCommon () if (condition2) doC () doD () After 1000 Iterations doCommon-if2: 253 If1-doA: 130 If2-doD: 127 if1-doB: 122 if2-doC: 118 if1-doA-..-if2: 65 …
Prototype Implementation • Written in Java, using the Soot Framework • Handles full Java • Low memory overhead (~50kB) • Low sampling overhead (5%-50%) • Sampling + Skipping overhead (current implementation): 30%-360% • High accuracy on tested benchmarks
Prototype Implementation • Limited to paths of length 2n • Favorable tradeoff • Simple encoding • Tested for practical performance • Gives more weight to shorter paths • Only implementation details!
Related Work • Ball, Larus: Efficient path profiling (MICRO 1996) • Larus: Whole program paths (PLDI 1999) • Melski, Reps: Interprocedural path profiling (CC 1999) • Taub, Schechter, Smith: Ephemeral instrumentation for lightweight program profiling (2000) • Sastry, Bodik, Smith: Rapid profiling via stratified sampling (Computer Architecture 2001) • Bala, Duesterwald, Banerjia: Dynamo: a transparent dynamic optimization system (PLDI 2001)
Related Work • Ball-Larus path profiler (MICRO 1996) and extensions • Only Acyclic paths • Whole Program Path (Larus, PLDI 1999) • Uses an alphabet representing acyclic paths • Compact image of a whole program trace • Not online
Related Work • Dynamo (PLDI 2000) • A dynamic compiler for native code • Locates “hot traces” and optimizes them • Limits places where hot traces may start • It would be interesting to integrate OSP into Dynamo
Limitations • Results are only an approximation • Other methods are approximations as well • Guaranteed confidence and accuracy as function of hotness • Context not taken into account • Robust, works for arbitrary subpaths • Stand alone tool • Integrate into existing tools
Conclusions • We have presented a framework for online subpath profiling • We have a reference implementation • Simple • Efficient • Accurate