{"id":268,"date":"2014-05-13T20:18:33","date_gmt":"2014-05-13T19:18:33","guid":{"rendered":"http:\/\/blog.mozilla.org\/jseward\/?p=268"},"modified":"2014-05-13T20:18:33","modified_gmt":"2014-05-13T19:18:33","slug":"lul-a-lightweight-unwinder-library-for-profiling-gecko","status":"publish","type":"post","link":"https:\/\/blog.mozilla.org\/jseward\/2014\/05\/13\/lul-a-lightweight-unwinder-library-for-profiling-gecko\/","title":{"rendered":"LUL: A Lightweight Unwinder Library for profiling Gecko"},"content":{"rendered":"<p>Last August I asked the question &#8220;<a href=\"https:\/\/blog.mozilla.org\/jseward\/2013\/08\/29\/how-fast-can-cfiexidx-based-stack-unwinding-be\/\">How fast can CFI\/EXIDX-based stack unwinding be?<\/a>&#8221; At the time I was experimenting with native unwinding using our in-tree Breakpad copy, but getting dismal performance results. The posting observed that Breakpad&#8217;s CFI unwinder is around 30 times slower than Valgrind&#8217;s CFI unwinder, and looked in detail at the reasons for this slowness.<\/p>\n<p>Based on that analysis, I wrote a new lightweight unwinder library.\u00a0 LUL &#8212; as it became known &#8212; is aimed directly at doing unwinding for profiling. It is fast, robust, fairly accurate, and designed to allow a pool of worker threads to do unwinding, if that&#8217;s somewhere we want to go. It is also set up to facilitate the space-saving schemes discussed in &#8220;<a href=\"https:\/\/blog.mozilla.org\/jseward\/2013\/09\/03\/how-compactly-can-cfiexidx-stack-unwinding-info-be-represented\/\">How compactly can CFI\/EXIDX stack unwinding info be represented?<\/a>&#8221; although those have not been implemented as yet. LUL stores unwind information in a simple, quick-to-use format, which could conceivably be generated by the Javascript JITs so as to facilitate transparent unwinding through Javascript as well as C++.<\/p>\n<p>LUL has been integrated into the SPS profiler, and landed a couple of weeks back.<\/p>\n<p>It currently provides unwinding on x86_64-linux, x86_32-linux and arm-android, using the Dwarf CFI and ARM EXIDX unwind formats.\u00a0 Unwinding by stack scanning is also supported, although that should rarely be needed. Compared to the Breakpad unwinder, there is a very substantial performance increase, achieving a cost of about 40% of a 1.2 GHz Cortex A9 for 1000 unwinds\/second from leaf frames all the way back to XRE_Main().<\/p>\n<p>To use LUL, build with &#8211;enable-profiling &#8211;enable-optimize=&#8221;-g -O2&#8243;.\u00a0 I then start the desktop builds with the following environment variable settings:<\/p>\n<pre>  MOZ_PROFILER_INTERVAL=1 MOZ_PROFILER_NEW=1\r\n  MOZ_PROFILER_VERBOSE=1 MOZ_PROFILER_MODE=native<\/pre>\n<p>In particular, setting MOZ_PROFILER_MODE=help gives more details.<\/p>\n<p>On Android, a suitable magic incantation is:<\/p>\n<pre>  adb logcat -c ; \\\r\n  adb shell sh \/system\/bin\/am start -S -n \\\r\n    org.mozilla.fennec_sewardj\/.App \\\r\n      --es env0 MOZ_PROFILER_INTERVAL=1 \\\r\n      --es env1 MOZ_PROFILER_MODE=native \\\r\n      --es env2 MOZ_PROFILER_NEW=1 \\\r\n      --es env3 MOZ_PROFILER_VERBOSE=1 \\\r\n      --es env4 MOZ_PROFILER_STARTUP=1 ; \\\r\n  adb logcat 2&gt;&amp;1 | tee logfile.txt<\/pre>\n<p>What next for LUL? I&#8217;d like to implement the space-saving schemes mentioned earlier. But more important, it would be nice to have developers using the SPS\/LUL combination, so as to give real-use feedback. That will help to move it forward in the most immediately useful direction.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last August I asked the question &#8220;How fast can CFI\/EXIDX-based stack unwinding be?&#8221; At the time I was experimenting with native unwinding using our in-tree Breakpad copy, but getting dismal performance results. The posting observed that Breakpad&#8217;s CFI unwinder is &hellip; <a class=\"go\" href=\"https:\/\/blog.mozilla.org\/jseward\/2014\/05\/13\/lul-a-lightweight-unwinder-library-for-profiling-gecko\/\">Continue reading<\/a><\/p>\n","protected":false},"author":240,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.mozilla.org\/jseward\/wp-json\/wp\/v2\/posts\/268"}],"collection":[{"href":"https:\/\/blog.mozilla.org\/jseward\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mozilla.org\/jseward\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/jseward\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mozilla.org\/jseward\/wp-json\/wp\/v2\/comments?post=268"}],"version-history":[{"count":0,"href":"https:\/\/blog.mozilla.org\/jseward\/wp-json\/wp\/v2\/posts\/268\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mozilla.org\/jseward\/wp-json\/wp\/v2\/media?parent=268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mozilla.org\/jseward\/wp-json\/wp\/v2\/categories?post=268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mozilla.org\/jseward\/wp-json\/wp\/v2\/tags?post=268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}