{"id":8904,"date":"2024-11-29T14:20:23","date_gmt":"2024-11-29T22:20:23","guid":{"rendered":"https:\/\/visualgdb.com\/w\/?p=8904"},"modified":"2024-11-29T14:20:23","modified_gmt":"2024-11-29T22:20:23","slug":"tracing-cheat-sheet-measuring-precise-intervals","status":"publish","type":"post","link":"https:\/\/visualgdb.com\/documentation\/cheatsheets\/tracing\/intervals\/","title":{"rendered":"Tracing Cheat Sheet: Measuring Precise Intervals"},"content":{"rendered":"<p>This page is a quick recap of how to measure the precise timing between events happening on the target (e.g. interrupts or thread switches) using VisualGDB&#8217;s software tracing.<\/p>\n<p>Tracing works by dynamically inserting recording code into the debugged program. It works very fast and introduces minimal overhead (~100 CPU cycles per event), so it can be used to accurately measure how long some code paths take. <a href=\"https:\/\/visualgdb.com\/tutorials\/tracing\/embedded\/bounce\/\">This tutorial<\/a> describes it in detail, while this page provides a quick recap on how to measure the time spent between 2 lines of code:<\/p>\n<ol>\n<li>Set tracepoints both lines.<\/li>\n<li>Configure them to capture the Cortex-M Cycle Counter:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/01-counter.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8905\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/01-counter.png\" alt=\"\" width=\"870\" height=\"275\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/01-counter.png 870w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/01-counter-300x95.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/01-counter-768x243.png 768w\" sizes=\"(max-width: 870px) 100vw, 870px\" \/><\/a><\/li>\n<li>Optionally,rename the tracepoints in the Tracepoints window to get more meaningful names:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/02-calls.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8906\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/02-calls.png\" alt=\"\" width=\"1144\" height=\"348\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/02-calls.png 1144w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/02-calls-300x91.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/02-calls-1024x311.png 1024w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/02-calls-768x234.png 768w\" sizes=\"(max-width: 1144px) 100vw, 1144px\" \/><\/a><\/li>\n<li>Start debugging. VisualGDB will begin collecting the trace data and the Tracepoints window will show it. Switch the view to either <strong>Events<\/strong> or <strong>Both<\/strong>:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/03-run.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8907\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/03-run.png\" alt=\"\" width=\"1144\" height=\"416\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/03-run.png 1144w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/03-run-300x109.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/03-run-1024x372.png 1024w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/03-run-768x279.png 768w\" sizes=\"(max-width: 1144px) 100vw, 1144px\" \/><\/a><\/li>\n<li>Now the Tracepoints window is showing the list of tracepoints <strong>(A)<\/strong>, the list of events from each one <strong>(B)<\/strong> and the data captured in each one <strong>(C)<\/strong>. However, the <strong>Trace Data<\/strong> view can only show data from one event at a time. To compare the timestamps from multiple events, you need to create a <strong>table view<\/strong>:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/04-table-1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8912\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/04-table-1.png\" alt=\"\" width=\"1144\" height=\"298\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/04-table-1.png 1144w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/04-table-1-300x78.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/04-table-1-1024x267.png 1024w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/04-table-1-768x200.png 768w\" sizes=\"(max-width: 1144px) 100vw, 1144px\" \/><\/a>Note that once you create a table view, you can always re-open it during subsequent tracing sessions by selecting it from the list.<\/li>\n<li>To build a table view showing the time, you would need to drag the <strong>Cycle Counter<\/strong> variable from the <strong>Trace Data<\/strong> view into the column setup area.<\/li>\n<li>As we have created 2 different tracepoints, you need to either drag the cycle counter for both of them, or drag the first one and use the &#8220;Add to index&#8221; button to automatically add the rest:<\/li>\n<li>After the values have been added, you can switch the view from <strong>Value<\/strong> to <strong>Time<\/strong>:<br \/>\n<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/05-add.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8909\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/05-add.png\" alt=\"\" width=\"1144\" height=\"536\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/05-add.png 1144w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/05-add-300x141.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/05-add-1024x480.png 1024w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/05-add-768x360.png 768w\" sizes=\"(max-width: 1144px) 100vw, 1144px\" \/><\/a><\/li>\n<li>Once you have selected the <strong>Time<\/strong> view and entered the clock frequency, you can see the exact time it took between 2 adjacent events in the table view:<a href=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/06-result.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-8910\" src=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/06-result.png\" alt=\"\" width=\"1144\" height=\"252\" srcset=\"https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/06-result.png 1144w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/06-result-300x66.png 300w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/06-result-1024x226.png 1024w, https:\/\/visualgdb.com\/w\/wp-content\/uploads\/2024\/11\/06-result-768x169.png 768w\" sizes=\"(max-width: 1144px) 100vw, 1144px\" \/><\/a><\/li>\n<\/ol>\n<p>If you want to learn more about the VisualGDB&#8217;s tracing features, see <a href=\"https:\/\/visualgdb.com\/documentation\/tracing\/\">this page<\/a> for a detailed description.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This page is a quick recap of how to measure the precise timing between events happening on the target (e.g.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[227],"tags":[],"_links":{"self":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/8904"}],"collection":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/comments?post=8904"}],"version-history":[{"count":2,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/8904\/revisions"}],"predecessor-version":[{"id":8914,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/posts\/8904\/revisions\/8914"}],"wp:attachment":[{"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/media?parent=8904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/categories?post=8904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/visualgdb.com\/w\/wp-json\/wp\/v2\/tags?post=8904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}