blob: b88f1ba96536521e9b051edeadfc9e65e0fbeb5c [file] [log] [blame]
<!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">
<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.9.3"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Direct3D 12 Memory Allocator: Statistics</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.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" />
</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="projectalign">
<div id="projectname">Direct3D 12 Memory Allocator
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.3 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search",'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="index.html">D3D12 Memory Allocator</a></li> </ul>
</div>
</div><!-- top -->
<div><div class="header">
<div class="headertitle"><div class="title">Statistics </div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p >This library contains several functions that return information about its internal state, especially the amount of memory allocated from D3D12.</p>
<h1><a class="anchor" id="statistics_numeric_statistics"></a>
Numeric statistics</h1>
<p >If you need to obtain basic statistics about memory usage per memory segment group, together with current budget, you can call function <a class="el" href="class_d3_d12_m_a_1_1_allocator.html#a1ac113daec5f6ef28ecb1786cf544144" title="Retrieves information about current memory usage and budget.">D3D12MA::Allocator::GetBudget()</a> and inspect structure <a class="el" href="struct_d3_d12_m_a_1_1_budget.html" title="Statistics of current memory usage and available budget for a specific memory segment group.">D3D12MA::Budget</a>. This is useful to keep track of memory usage and stay withing budget. Example:</p>
<div class="fragment"><div class="line"><a class="code hl_struct" href="struct_d3_d12_m_a_1_1_budget.html">D3D12MA::Budget</a> localBudget;</div>
<div class="line">allocator-&gt;GetBudget(&amp;localBudget, NULL);</div>
<div class="line"> </div>
<div class="line">printf(<span class="stringliteral">&quot;My GPU memory currently has %u allocations taking %llu B,\n&quot;</span>,</div>
<div class="line"> localBudget.Statistics.AllocationCount,</div>
<div class="line"> localBudget.Statistics.AllocationBytes);</div>
<div class="line">printf(<span class="stringliteral">&quot;allocated out of %u D3D12 memory heaps taking %llu B,\n&quot;</span>,</div>
<div class="line"> localBudget.Statistics.BlockCount,</div>
<div class="line"> localBudget.Statistics.BlockBytes);</div>
<div class="line">printf(<span class="stringliteral">&quot;D3D12 reports total usage %llu B with budget %llu B.\n&quot;</span>,</div>
<div class="line"> localBudget.<a class="code hl_variable" href="struct_d3_d12_m_a_1_1_budget.html#a77a8c9e32d6602f95b7d1c285cddd253">UsageBytes</a>,</div>
<div class="line"> localBudget.<a class="code hl_variable" href="struct_d3_d12_m_a_1_1_budget.html#a326515f08d89ee2e31dcfdd5c1e8ac71">BudgetBytes</a>);</div>
<div class="ttc" id="astruct_d3_d12_m_a_1_1_budget_html"><div class="ttname"><a href="struct_d3_d12_m_a_1_1_budget.html">D3D12MA::Budget</a></div><div class="ttdoc">Statistics of current memory usage and available budget for a specific memory segment group.</div><div class="ttdef"><b>Definition:</b> D3D12MemAlloc.h:412</div></div>
<div class="ttc" id="astruct_d3_d12_m_a_1_1_budget_html_a326515f08d89ee2e31dcfdd5c1e8ac71"><div class="ttname"><a href="struct_d3_d12_m_a_1_1_budget.html#a326515f08d89ee2e31dcfdd5c1e8ac71">D3D12MA::Budget::BudgetBytes</a></div><div class="ttdeci">UINT64 BudgetBytes</div><div class="ttdoc">Estimated amount of memory available to the program.</div><div class="ttdef"><b>Definition:</b> D3D12MemAlloc.h:435</div></div>
<div class="ttc" id="astruct_d3_d12_m_a_1_1_budget_html_a77a8c9e32d6602f95b7d1c285cddd253"><div class="ttname"><a href="struct_d3_d12_m_a_1_1_budget.html#a77a8c9e32d6602f95b7d1c285cddd253">D3D12MA::Budget::UsageBytes</a></div><div class="ttdeci">UINT64 UsageBytes</div><div class="ttdoc">Estimated current memory usage of the program.</div><div class="ttdef"><b>Definition:</b> D3D12MemAlloc.h:424</div></div>
</div><!-- fragment --><p >You can query for more detailed statistics per heap type, memory segment group, and totals, including minimum and maximum allocation size and unused range size, by calling function <a class="el" href="class_d3_d12_m_a_1_1_allocator.html#a99db00df909963573a976c203b107d22" title="Retrieves statistics from current state of the allocator.">D3D12MA::Allocator::CalculateStatistics()</a> and inspecting structure <a class="el" href="struct_d3_d12_m_a_1_1_total_statistics.html" title="General statistics from current state of the allocator - total memory usage across all memory heaps a...">D3D12MA::TotalStatistics</a>. This function is slower though, as it has to traverse all the internal data structures, so it should be used only for debugging purposes.</p>
<p >You can query for statistics of a custom pool using function <a class="el" href="class_d3_d12_m_a_1_1_pool.html#aa9d849dc4667314b2a53eddf02f5af91" title="Retrieves basic statistics of the custom pool that are fast to calculate.">D3D12MA::Pool::GetStatistics()</a> or <a class="el" href="class_d3_d12_m_a_1_1_pool.html#ad07999ac5dc8f0c63187afd45d551910" title="Retrieves detailed statistics of the custom pool that are slower to calculate.">D3D12MA::Pool::CalculateStatistics()</a>.</p>
<p >You can query for information about a specific allocation using functions of the <a class="el" href="class_d3_d12_m_a_1_1_allocation.html" title="Represents single memory allocation.">D3D12MA::Allocation</a> class, e.g. <code>GetSize()</code>, <code>GetOffset()</code>, <code>GetHeap()</code>.</p>
<h1><a class="anchor" id="statistics_json_dump"></a>
JSON dump</h1>
<p >You can dump internal state of the allocator to a string in JSON format using function <a class="el" href="class_d3_d12_m_a_1_1_allocator.html#a29716b3084916abed7793bf2ec4b65db" title="Builds and returns statistics as a string in JSON format.">D3D12MA::Allocator::BuildStatsString()</a>. The result is guaranteed to be correct JSON. It uses Windows Unicode (UTF-16) encoding. Any strings provided by user (see <a class="el" href="class_d3_d12_m_a_1_1_allocation.html#af9e643276b577aa7f21937f75d4b82ac" title="Associates a name with the allocation object. This name is for use in debug diagnostics and tools.">D3D12MA::Allocation::SetName()</a>) are copied as-is and properly escaped for JSON. It must be freed using function <a class="el" href="class_d3_d12_m_a_1_1_allocator.html#a8392663494384c16d8bfa12b827b4f9c" title="Frees memory of a string returned from Allocator::BuildStatsString.">D3D12MA::Allocator::FreeStatsString()</a>.</p>
<p >The format of this JSON string is not part of official documentation of the library, but it will not change in backward-incompatible way without increasing library major version number and appropriate mention in changelog.</p>
<p >The JSON string contains all the data that can be obtained using <a class="el" href="class_d3_d12_m_a_1_1_allocator.html#a99db00df909963573a976c203b107d22" title="Retrieves statistics from current state of the allocator.">D3D12MA::Allocator::CalculateStatistics()</a>. It can also contain detailed map of allocated memory blocks and their regions - free and occupied by allocations. This allows e.g. to visualize the memory or assess fragmentation. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.3
</small></address>
</body>
</html>