| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
| <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"> | |
| <head> | |
| <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> | |
| <meta http-equiv="X-UA-Compatible" content="IE=11"/> | |
| <meta name="generator" content="Doxygen 1.18.0"/> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"/> | |
| <title>mi-malloc: Tools</title> | |
| <link href="tabs.css" rel="stylesheet" type="text/css"/> | |
| <script type="text/javascript" src="codefolding.js"></script> | |
| <script type="text/javascript" src="clipboard.js"></script> | |
| <link href="navtree.css" rel="stylesheet" type="text/css"/> | |
| <script type="text/javascript" src="navtreedata.js"></script> | |
| <script type="text/javascript" src="navtree.js"></script> | |
| <script type="text/javascript" src="cookie.js"></script> | |
| <link href="search/search.css" rel="stylesheet" type="text/css"/> | |
| <script type="text/javascript" src="search/searchdata.js"></script> | |
| <script type="text/javascript" src="search/search.js"></script> | |
| <link href="doxygen.css" rel="stylesheet" type="text/css" /> | |
| <link href="mimalloc-doxygen.css" rel="stylesheet" type="text/css"/> | |
| </head> | |
| <body> | |
| <div id="top"><!-- do not remove this div, it is closed by doxygen! --> | |
| <div id="titlearea"> | |
| <table cellspacing="0" cellpadding="0"> | |
| <tbody> | |
| <tr id="projectrow"> | |
| <td id="projectlogo"><img alt="Logo" src="mimalloc-logo.svg"/></td> | |
| <td id="projectalign"> | |
| <div id="projectname">mi-malloc<span id="projectnumber"> 3.5/2.5/1.15</span> | |
| </div> | |
| </td> | |
| <td> <div id="MSearchBox" class="MSearchBoxInactive"> | |
| <span class="left"> | |
| <span id="MSearchSelect" class="search-icon"><span class="search-icon-dropdown"></span></span> | |
| <input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"/> | |
| </span><span class="right"> | |
| <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><div id="MSearchCloseImg" class="close-icon"></div></a> | |
| </span> | |
| </div> | |
| </td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| </div> | |
| <!-- end header part --> | |
| <!-- Generated by Doxygen 1.18.0 --> | |
| <script type="text/javascript"> | |
| let searchBox = new SearchBox("searchBox", "search/",'.html'); | |
| </script> | |
| <script type="text/javascript"> | |
| document.addEventListener('DOMContentLoaded', codefold.init); | |
| </script> | |
| </div><!-- top --> | |
| <div id="side-nav" class="ui-resizable side-nav-resizable"> | |
| <div id="nav-tree"> | |
| <div id="nav-tree-contents"> | |
| <div id="nav-sync" class="sync"></div> | |
| </div> | |
| </div> | |
| <div id="splitbar" class="ui-resizable-handle"> | |
| </div> | |
| </div> | |
| <script type="text/javascript"> | |
| document.addEventListener('DOMContentLoaded',() => { initNavTree('tools.html','',''); }); | |
| </script> | |
| <div id="container"> | |
| <div id="doc-content"> | |
| <!-- window showing the filter options --> | |
| <div id="MSearchSelectWindow"> | |
| </div> | |
| <!-- iframe showing the search results (closed by default) --> | |
| <div id="MSearchResultsWindow"> | |
| <div id="MSearchResults"> | |
| <div class="SRPage"> | |
| <div id="SRIndex"> | |
| <div id="SRResults"></div> | |
| <div class="SRStatus" id="Loading">Loading...</div> | |
| <div class="SRStatus" id="Searching">Searching...</div> | |
| <div class="SRStatus" id="NoMatches">No Matches</div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div><div class="header"> | |
| <div class="headertitle"><div class="title">Tools </div></div> | |
| </div><!--header--> | |
| <div class="contents"> | |
| <div class="textblock"><p>Generally, we recommend using the standard allocator with memory tracking tools, but mimalloc can also be build to support the <a href="https://github.com/google/sanitizers/wiki/AddressSanitizer">address sanitizer</a> or the excellent <a href="https://valgrind.org/">Valgrind</a> tool. Moreover, it can be build to support Windows event tracing (<a href="https://learn.microsoft.com/en-us/windows-hardware/test/wpt/event-tracing-for-windows">ETW</a>). This has a small performance overhead but does allow detecting memory leaks and byte-precise buffer overflows directly on final executables. See also the <span class="tt">test/test-wrong.c</span> file to test with various tools.</p> | |
| <h2>Valgrind</h2> | |
| <p>To build with <a href="https://valgrind.org/">valgrind</a> support, use the <span class="tt">MI_TRACK_VALGRIND=ON</span> cmake option:</p> | |
| <div class="fragment"><div class="line">> cmake ../.. -DMI_TRACK_VALGRIND=ON</div> | |
| </div><!-- fragment --><p>This can also be combined with secure mode or debug mode. You can then run your programs directly under valgrind:</p> | |
| <div class="fragment"><div class="line">> valgrind <myprogram></div> | |
| </div><!-- fragment --><p>If you rely on overriding <span class="tt"><a class="el" href="group__malloc.html" title="The basic allocation interface.">Basic Allocation</a></span>/<span class="tt">free</span> by mimalloc (instead of using the <span class="tt"><a class="el" href="group__malloc.html#gae1dd97b542420c87ae085e822b1229e8" title="Allocate size bytes.">mi_malloc</a></span>/<span class="tt"><a class="el" href="group__malloc.html#gaf2c7b89c327d1f60f59e68b9ea644d95" title="Free previously allocated memory.">mi_free</a></span> API directly), you also need to tell <span class="tt">valgrind</span> to not intercept those calls itself, and use:</p> | |
| <div class="fragment"><div class="line">> MIMALLOC_SHOW_STATS=1 valgrind --soname-synonyms=somalloc=*mimalloc* -- <myprogram></div> | |
| </div><!-- fragment --><p>By setting the <span class="tt">MIMALLOC_SHOW_STATS</span> environment variable you can check that mimalloc is indeed used and not the standard allocator. Even though the <a href="https://valgrind.org/docs/manual/manual-core.html#opt.soname-synonyms">Valgrind option</a> is called <span class="tt">--soname-synonyms</span>, this also works when overriding with a static library or object file. To dynamically override mimalloc using <span class="tt">LD_PRELOAD</span> together with <span class="tt">valgrind</span>, use:</p> | |
| <div class="fragment"><div class="line">> valgrind --trace-children=yes --soname-synonyms=somalloc=*mimalloc* /usr/bin/env LD_PRELOAD=/usr/lib/libmimalloc.so -- <myprogram></div> | |
| </div><!-- fragment --><p>See also the <span class="tt">test/test-wrong.c</span> file to test with <span class="tt">valgrind</span>.</p> | |
| <p>Valgrind support is in its initial development – please report any issues.</p> | |
| <h2>ASAN</h2> | |
| <p>To build with the address sanitizer, use the <span class="tt">-DMI_TRACK_ASAN=ON</span> cmake option:</p> | |
| <div class="fragment"><div class="line">> cmake ../.. -DMI_TRACK_ASAN=ON</div> | |
| </div><!-- fragment --><p>This can also be combined with secure mode or debug mode. You can then run your programs as:'</p> | |
| <div class="fragment"><div class="line">> ASAN_OPTIONS=verbosity=1 <myprogram></div> | |
| </div><!-- fragment --><p>When you link a program with an address sanitizer build of mimalloc, you should generally compile that program too with the address sanitizer enabled. For example, assuming you build mimalloc in <span class="tt">out/debug</span>:</p> | |
| <div class="fragment"><div class="line">clang -g -o test-wrong -Iinclude test/test-wrong.c out/debug/libmimalloc-asan-debug.a -lpthread -fsanitize=address -fsanitize-recover=address</div> | |
| </div><!-- fragment --><p>Since the address sanitizer redirects the standard allocation functions, on some platforms (macOSX for example) it is required to compile mimalloc with <span class="tt">-DMI_OVERRIDE=OFF</span>. Address sanitizer support is in its initial development – please report any issues.</p> | |
| <h2>ETW</h2> | |
| <p>Event tracing for Windows (<a href="https://learn.microsoft.com/en-us/windows-hardware/test/wpt/event-tracing-for-windows">ETW</a>) provides a high performance way to capture all allocations though mimalloc and analyze them later. To build with ETW support, use the <span class="tt">-DMI_TRACK_ETW=ON</span> cmake option.</p> | |
| <p>You can then capture an allocation trace using the Windows performance recorder (WPR), using the <span class="tt">src/prim/windows/etw-mimalloc.wprp</span> profile. In an admin prompt, you can use: </p><div class="fragment"><div class="line">> wpr -start src\prim\windows\etw-mimalloc.wprp -filemode</div> | |
| <div class="line">> <my_mimalloc_program></div> | |
| <div class="line">> wpr -stop <my_mimalloc_program>.etl</div> | |
| </div><!-- fragment --><p> and then open <span class="tt"><my_mimalloc_program>.etl</span> in the Windows Performance Analyzer (WPA), or use a tool like <a href="https://github.com/xinglonghe/TraceControl">TraceControl</a> that is specialized for analyzing mimalloc traces. </p> | |
| </div></div><!-- contents --> | |
| </div><!-- PageDoc --> | |
| </div><!-- doc-content --> | |
| </div><!-- container --> | |
| <!-- start footer part --> | |
| <div id="nav-path" class="navpath"><!-- id is needed for treeview function! --> | |
| <ul> | |
| <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.18.0 </li> | |
| </ul> | |
| </div> | |
| </body> | |
| </html> |