{"id":3337,"date":"2014-12-03T03:22:57","date_gmt":"2014-12-03T02:22:57","guid":{"rendered":"http:\/\/glandium.org\/blog\/?p=3337"},"modified":"2014-12-03T03:22:57","modified_gmt":"2014-12-03T02:22:57","slug":"logging-firefox-memory-allocations","status":"publish","type":"post","link":"https:\/\/glandium.org\/blog\/?p=3337","title":{"rendered":"Logging Firefox memory allocations"},"content":{"rendered":"<p>A couple years ago, when I was actively <a href=\"\/blog\/?p=2581\">working on integrating jemalloc 3<\/a> in the Firefox build, and started investigating some <a href=\"https:\/\/bugzilla.mozilla.org\/show_bug.cgi?id=762448\">memory usage regression<\/a> compared to our old fork, I came up with a <a href=\"\/blog\/?p=2848\">replace-malloc<\/a> library for Firefox that would log all the allocations, and allow to replay them in a more consistent (and faster) way in a separate program, such that testing different configurations of jemalloc with the same workload can be streamlined.<\/p>\n<p>A couple weeks ago, I refreshed that work, and made it work on all the tier-1 Firefox desktop platforms. That work is now in the tree instead of on my hard drive, and will allow us to test the effects of jemalloc changes in a better way.<\/p>\n<p>The bulk of how to use this feature is the following:<\/p>\n<ul>\n<li>Start Firefox with the following environment variables:\n<ul>\n<li>on Linux:<br \/>\n<blockquote><p><code>LD_PRELOAD=\/path\/to\/memory\/replace\/logalloc\/liblogalloc.so<\/code><\/p><\/blockquote>\n<\/li>\n<li>on Mac OSX:<br \/>\n<blockquote><p><code>DYLD_INSERT_LIBRARIES=\/path\/to\/memory\/replace\/logalloc\/liblogalloc.dylib<\/code><\/p><\/blockquote>\n<\/li>\n<li>on Windows:<br \/>\n<blockquote><p><code>MOZ_REPLACE_MALLOC_LIB=\/path\/to\/memory\/replace\/logalloc\/logalloc.dll<\/code><\/p><\/blockquote>\n<\/li>\n<li>on all the above:<br \/>\n<blockquote><p><code>MALLOC_LOG=\/path\/to\/log-file<\/code><\/p><\/blockquote>\n<\/li>\n<\/ul>\n<\/li>\n<li>Play your workload in Firefox, then close it.<\/li>\n<li>Run the following command to prepare the log file for replay:<br \/>\n<blockquote><p><code>python \/source\/path\/to\/memory\/replace\/logalloc\/replay\/logalloc_munge.py &lt; \/path\/to\/log-file &gt; \/path\/to\/replay.log<\/code><\/p><\/blockquote>\n<\/li>\n<li>Replay the logged allocations with the following command:<br \/>\n<blockquote><p><code>\/path\/to\/memory\/replace\/logalloc\/replay\/logalloc-replay &lt; \/path\/to\/replay.log<\/code><\/p><\/blockquote>\n<\/li>\n<\/ul>\n<p>More information and implementation details can be found in the <a href=\"http:\/\/dxr.mozilla.org\/mozilla-central\/source\/memory\/replace\/logalloc\/README\">README accompanying the code for that functionality<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A couple years ago, when I was actively working on integrating jemalloc 3 in the Firefox build, and started investigating some memory usage regression compared to our old fork, I came up with a replace-malloc library for Firefox that would log all the allocations, and allow to replay them in a more consistent (and faster) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[23],"class_list":["post-3337","post","type-post","status-publish","format-standard","hentry","category-planet-mozilla","tag-en"],"_links":{"self":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3337"}],"version-history":[{"count":4,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3337\/revisions"}],"predecessor-version":[{"id":3374,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3337\/revisions\/3374"}],"wp:attachment":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}