blob: 7c98d44e5f72498bdab50c707368f38629c18c8e [file]
<!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.17.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Vulkan Memory Allocator: Statistics</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>
<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>
<script type="module">
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
const theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'default';
mermaid.initialize({ startOnLoad: true, theme: theme });
</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">Vulkan Memory Allocator
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.17.0 -->
<script type="text/javascript">
let searchBox = new SearchBox("searchBox", "search/",'.html');
</script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', codefold.init);
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', () => {
initMenu('',false);
init_search();
});
</script>
<div id="main-nav-mobile">
<div class="sm sm-dox"><input id="main-menu-state" type="checkbox"/>
<label class="main-menu-btn" for="main-menu-state">
<span class="main-menu-btn-icon"></span> Toggle main menu visibility</label>
<span id="searchBoxPos1" style="position:absolute;right:8px;top:8px;height:36px;"></span>
</div>
</div><!-- main-nav-mobile -->
<div id="main-nav">
<ul class="sm sm-dox" id="main-menu">
<li id="searchBoxPos2" style="float:right">
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<span id="MSearchSelect" class="search-icon" onmouseover="return searchBox.OnSearchSelectShow()" onmouseout="return searchBox.OnSearchSelectHide()"><span class="search-icon-dropdown"></span></span>
<input type="text" id="MSearchField" value="" placeholder="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><div id="MSearchCloseImg" class="close-icon"></div></a>
</span>
</div>
</li>
</ul>
</div><!-- main-nav -->
<!-- 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">
<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 id="nav-path" class="navpath">
<ul>
<li class="navelem"><a href="index.html">Vulkan Memory Allocator</a></li> </ul>
</div>
</div><!-- top -->
<div id="doc-content">
<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 Vulkan.</p>
<h1 class="doxsection"><a class="anchor" id="statistics_numeric_statistics"></a>
Numeric statistics</h1>
<p>If you need to obtain basic statistics about memory usage per heap, together with current budget, you can call function <a class="el" href="group__group__stats.html#ga9f88db9d46a432c0ad7278cecbc5eaa7" title="Retrieves information about current memory usage and budget for all memory heaps.">vmaGetHeapBudgets()</a> and inspect structure <a class="el" href="struct_vma_budget.html" title="Statistics of current memory usage and available budget for a specific memory heap.">VmaBudget</a>. This is useful to keep track of memory usage and stay within budget (see also <a class="el" href="staying_within_budget.html" title="Staying within budget">Staying within budget</a>). Example:</p>
<div class="fragment"><div class="line">uint32_t heapIndex = ...</div>
<div class="line"> </div>
<div class="line">VmaBudget budgets[VK_MAX_MEMORY_HEAPS];</div>
<div class="line"><a class="code hl_function" href="group__group__stats.html#ga9f88db9d46a432c0ad7278cecbc5eaa7">vmaGetHeapBudgets</a>(allocator, budgets);</div>
<div class="line"> </div>
<div class="line">printf(<span class="stringliteral">&quot;My heap currently has %u allocations taking %llu B,\n&quot;</span>,</div>
<div class="line"> budgets[heapIndex].statistics.allocationCount,</div>
<div class="line"> budgets[heapIndex].statistics.allocationBytes);</div>
<div class="line">printf(<span class="stringliteral">&quot;allocated out of %u Vulkan device memory blocks taking %llu B,\n&quot;</span>,</div>
<div class="line"> budgets[heapIndex].statistics.blockCount,</div>
<div class="line"> budgets[heapIndex].statistics.blockBytes);</div>
<div class="line">printf(<span class="stringliteral">&quot;Vulkan reports total usage %llu B with budget %llu B.\n&quot;</span>,</div>
<div class="line"> budgets[heapIndex].usage,</div>
<div class="line"> budgets[heapIndex].budget);</div>
<div class="ttc" id="agroup__group__stats_html_ga9f88db9d46a432c0ad7278cecbc5eaa7"><div class="ttname"><a href="group__group__stats.html#ga9f88db9d46a432c0ad7278cecbc5eaa7">vmaGetHeapBudgets</a></div><div class="ttdeci">void vmaGetHeapBudgets(VmaAllocator allocator, VmaBudget *pBudgets)</div><div class="ttdoc">Retrieves information about current memory usage and budget for all memory heaps.</div></div>
</div><!-- fragment --><p>You can query for more detailed statistics per memory heap, type, and totals, including minimum and maximum allocation size and unused range size, by calling function <a class="el" href="group__group__stats.html#ga36f3484de7aa6cd6edc4de9edfa0ff59" title="Retrieves statistics from current state of the Allocator.">vmaCalculateStatistics()</a> and inspecting structure <a class="el" href="struct_vma_total_statistics.html" title="General statistics from current state of the Allocator - total memory usage across all memory heaps a...">VmaTotalStatistics</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="group__group__stats.html#ga34d8e7d83774eed0caee5c5ae88e217d" title="Retrieves statistics of existing VmaPool object.">vmaGetPoolStatistics()</a> or <a class="el" href="group__group__stats.html#ga50ba0eb25d2b363b792be4645ca7a380" title="Retrieves detailed statistics of existing VmaPool object.">vmaCalculatePoolStatistics()</a>.</p>
<p>You can query for information about a specific allocation using function <a class="el" href="group__group__alloc.html#ga86dd08aba8633bfa4ad0df2e76481d8b" title="Returns current information about specified allocation.">vmaGetAllocationInfo()</a>. It fill structure <a class="el" href="struct_vma_allocation_info.html">VmaAllocationInfo</a>.</p>
<h1 class="doxsection"><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="group__group__stats.html#gaa4fee7eb5253377599ef4fd38c93c2a0" title="Builds and returns statistics as a null-terminated string in JSON format.">vmaBuildStatsString()</a>. The result is guaranteed to be correct JSON. It uses ANSI encoding. Any strings provided by user (see <a class="el" href="allocation_annotation.html#allocation_names" title="Allocation names">Allocation names</a>) are copied as-is and properly escaped for JSON, so if they use UTF-8, ISO-8859-2 or any other encoding, this JSON string can be treated as using this encoding. It must be freed using function <a class="el" href="group__group__stats.html#ga3104eb30d8122c84dd8541063f145288">vmaFreeStatsString()</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="group__group__stats.html#ga36f3484de7aa6cd6edc4de9edfa0ff59" title="Retrieves statistics from current state of the Allocator.">vmaCalculateStatistics()</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.17.0
</small></address>
</div><!-- doc-content -->
</body>
</html>