<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Check RAM usage during runtime of my application</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/117640/check-ram-usage-during-runtime-of-my-application</link><description>Using the nRF Connect Desktop application and the nRF Connect SDK for my nRF9160dk. 
 I would like to monitor RAM usage during runtime of my program. In particular I am interested in the peak memory usage of certain parts of my code. 
 Is there a way</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 02 Jan 2025 14:58:36 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/117640/check-ram-usage-during-runtime-of-my-application" /><item><title>RE: Check RAM usage during runtime of my application</title><link>https://devzone.nordicsemi.com/thread/516668?ContentTypeID=1</link><pubDate>Thu, 02 Jan 2025 14:58:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:db333da3-d172-4d45-8eb8-92e50ba7d88a</guid><dc:creator>Charlie</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Thanks for reaching us for this inqury. There are two&amp;nbsp;tools you may used for RAM usage monitoring.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Heap Listener:&lt;/strong&gt;&amp;nbsp;You can set up a heap listener for the Zephyr kernel heap. This allows you to manually check heap usage.&amp;nbsp;&lt;a href="https://docs.zephyrproject.org/latest/kernel/memory_management/heap.html#heap-listener" rel="noopener noreferrer" target="_blank"&gt;Zephyr Heap Listener&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;See discussion&amp;nbsp;here&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/93660/default-system-heap-listener"&gt;(99+) Default system heap listener - Nordic Q&amp;amp;A - Nordic DevZone - Nordic DevZone&lt;/a&gt;. and&amp;nbsp;&lt;a href="https://docs.zephyrproject.org/latest/kernel/memory_management/heap.html#heap-listener" rel="noopener noreferrer" target="_blank"&gt;Zephyr Heap Listener&lt;/a&gt;&amp;nbsp;API.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Thread Analyzer:&lt;/strong&gt; You can also use the Thread Analyzer module to monitor stack usage for individual threads. To enable this, add the following to your&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code dir="ltr"&gt;prj.conf&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;file:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_THREAD_ANALYZER=y
CONFIG_THREAD_ANALYZER_USE_PRINTK=y
CONFIG_THREAD_ANALYZER_AUTO=y
CONFIG_THREAD_ANALYZER_AUTO_INTERVAL=5&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Then use the UART shell command&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code dir="ltr"&gt;kernel stacks&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;to see statistics for each running thread, including peak usage. This can help you set proper stack sizes and optimize RAM usage.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have used both of them in&amp;nbsp;&lt;a href="https://github.com/charlieshao5189/nordic_wifi_opus_audio_demo/tree/main"&gt;charlieshao5189/nordic_wifi_opus_audio_demo: A demo for Wi-Fi Audio based on nRF5340 Audio DK + nRF7002 EK&lt;/a&gt;, you can check how they are used in a NCS project.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Charlie&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>