{"id":1226,"date":"2008-10-13T10:13:35","date_gmt":"2008-10-13T10:13:35","guid":{"rendered":"http:\/\/coalface.mcslp.com\/?p=113"},"modified":"2008-10-13T10:13:35","modified_gmt":"2008-10-13T10:13:35","slug":"how-to-analyze-memory-leaks-on-windows","status":"publish","type":"post","link":"https:\/\/planet.mcb.guru\/?p=1226","title":{"rendered":"How to analyze memory leaks on Windows"},"content":{"rendered":"<p>We use <a href=\"http:\/\/valgrind.org\">valgrind<\/a> to find memory leaks in MySQL on Linux. The tool is a convenient, and often enlightening way of finding out where the real and potential problems are location. <\/p>\n<p>On Windows, you dont have valgrind, but Microsoft do provide a free native debugging tool, called the user-mode dump heap (UMDH) tool. This performs a similar function to valgrind to determine memory leaks.  <\/p>\n<p>Vladislav Vaintroub, who works on the Falcon team and is one of our resident Windows experts provides the following how-to for using UMDH:<\/p>\n<ol>\n<li>\n<p>Download and install debugging tools for Windows from here<br \/>\n<a href=\"http:\/\/www.microsoft.com\/whdc\/DevTools\/Debugging\/default.mspx\">MS Debugging Tools<\/a><br \/>\nInstall 64 bit version if you&#8217;re on 64 bit Windows and 32 bit version<br \/>\notherwise.<\/p>\n<\/li>\n<li>\n<p>Change the <code>PATH<\/code> environment variable to include bin directory of Debugging tools.<br \/>\nOn my system, I added<br \/>\n<code>C:\\Program Files\\Debugging Tools for Windows 64-bit<\/code> to the <code>PATH<\/code>.<\/p>\n<\/li>\n<li>\n<p>Instruct OS to collect  allocation stack for mysqld with <code>gflags -i<br \/>\nmysqld.exe +ust<\/code>.<br \/>\nOn Vista and later, this should be done in &#8220;elevated&#8221; command prompt,<br \/>\nit requires admin privileges.\n<\/p>\n<p>\nNow collect the leak information. The mode of operation is that: take the<br \/>\nheap snapshot once, and after some load take it once again. Compare<br \/>\nsnapshots and output leak info.<\/p>\n<\/li>\n<li>\n<p>Preparation : setup debug symbol path.<br \/>\nIn the command prompt window, do<\/p>\n<p><code>set _NT_SYMBOL_PATH= srv*C:\\websymbols*http:\/\/msdl.microsoft.com\/download\/symbols;G:\\bzr\\mysql-6.0\\sql\\Debug<\/code><\/p>\n<p>Adjust second path component for your needs, it should include directory<br \/>\nwhere mysqld.exe is.<\/p>\n<\/li>\n<li>Start mysqld and run it for some minutes<\/li>\n<li>\n<p>Take first heap snapshot<\/p>\n<p><code>umdh -p:6768 -f:dump1<\/code><\/p>\n<p>Where -p:<br \/>\n actually, PID of my mysqld was 6768.\n<\/p>\n<\/li>\n<li>Let mysqld run for another some minutes<\/li>\n<li>\n<p>Take second heap snapshot<\/p>\n<p><code>umdh -p:6768 -f:dump2<\/code><\/p>\n<\/li>\n<li>\n<p>Compare snapshots<\/p>\n<p><code>umdh -v dump1 dump2 &gt; dump.compare.txt<\/code><\/p>\n<\/li>\n<li>Examine the result output file. It is human readable, but all numbers are<br \/>\nin hex, to scare everyone except  geeks.<\/li>\n<li>\n<p><code>gflags -i mysqld.exe -ust<\/code><\/p>\n<p>Instruct OS  not to collect mysqld user mode stacks for allocations<br \/>\nanymore.<\/p>\n<\/li>\n<\/ol>\n<p>These are 10 steps and it sounds like much work, but in reality it takes 15<br \/>\nminutes first time you do it and 5 minutes next time.<\/p>\n<p>Additional information is given in Microsoft KB article about UMDH<br \/>\n<a href=\"http:\/\/support.microsoft.com\/kb\/268343\">KB 268343<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We use valgrind to find memory leaks in MySQL on Linux. The tool is a convenient, and often enlightening way of finding out where the real and potential problems are location.<br \/>\nOn Windows, you dont have valgrind, but Microsoft do provide a free native debugging tool, called the user-mode dump heap (UMDH) tool. This performs [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[36],"_links":{"self":[{"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=\/wp\/v2\/posts\/1226"}],"collection":[{"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1226"}],"version-history":[{"count":0,"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=\/wp\/v2\/posts\/1226\/revisions"}],"wp:attachment":[{"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1226"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1226"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/planet.mcb.guru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1226"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}