ZealOS/docs/System/Utils/HeapLog.html
2021-07-03 02:51:43 -04:00

276 lines
32 KiB
HTML
Executable file

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=US-ASCII">
<meta name="generator" content="ZealOS V0.05">
<style type="text/css">
body {background-color:#000000;}
.cF0{color:#ffffff;background-color:#000000;}
.cF1{color:#3465a4;background-color:#000000;}
.cF2{color:#4e9a06;background-color:#000000;}
.cF3{color:#06989a;background-color:#000000;}
.cF4{color:#a24444;background-color:#000000;}
.cF5{color:#75507b;background-color:#000000;}
.cF6{color:#ce982f;background-color:#000000;}
.cF7{color:#bcc0b9;background-color:#000000;}
.cF8{color:#555753;background-color:#000000;}
.cF9{color:#729fcf;background-color:#000000;}
.cFA{color:#82bc49;background-color:#000000;}
.cFB{color:#34e2e2;background-color:#000000;}
.cFC{color:#ac3535;background-color:#000000;}
.cFD{color:#ad7fa8;background-color:#000000;}
.cFE{color:#fce94f;background-color:#000000;}
.cFF{color:#000000;background-color:#000000;}
</style>
</head>
<body>
<pre style="font-family:courier;font-size:10pt">
<a name="l1"></a><span class=cF0>#</span><span class=cF1>help_index</span><span class=cF0> </span><span class=cF6>&quot;Debugging/Heap;Memory/Debugging&quot;</span><span class=cF0>
<a name="l2"></a>#</span><span class=cF1>help_file</span><span class=cF0> </span><span class=cF6>&quot;::/Doc/HeapDebug&quot;</span><span class=cF0>
<a name="l3"></a>
<a name="l4"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>HL_CALLER_DEPTH</span><span class=cF0> </span><span class=cFE>5</span><span class=cF0> </span><span class=cF2>//Feel free to change this.</span><span class=cF0>
<a name="l5"></a>#</span><span class=cF1>define</span><span class=cF0> </span><span class=cF3>HL_HASH_SIZE</span><span class=cF0> </span><span class=cFE>0x1000</span><span class=cF0>
<a name="l6"></a>
<a name="l7"></a></span><span class=cF1>class</span><span class=cF0> </span><span class=cF9>CHeapLog</span><span class=cF0>
<a name="l8"></a>{
<a name="l9"></a> </span><span class=cF9>CHeapLog</span><span class=cF0> *next, *last;
<a name="l10"></a> </span><span class=cF1>union</span><span class=cF0>
<a name="l11"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l12"></a> </span><span class=cF1>U8</span><span class=cF0> *addr;
<a name="l13"></a> </span><span class=cF9>I64</span><span class=cF0> size;
<a name="l14"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l15"></a> </span><span class=cF9>I64</span><span class=cF0> count;
<a name="l16"></a> </span><span class=cF1>U8</span><span class=cF0> *caller[</span><span class=cF3>HL_CALLER_DEPTH</span><span class=cF0>];
<a name="l17"></a>};
<a name="l18"></a>
<a name="l19"></a></span><span class=cF1>class</span><span class=cF0> </span><span class=cF9>CHeapLogHash</span><span class=cF0>
<a name="l20"></a>{
<a name="l21"></a> </span><span class=cF9>CHeapLog</span><span class=cF0> *next, *last;
<a name="l22"></a>};
<a name="l23"></a>
<a name="l24"></a></span><span class=cF9>CHeapCtrl</span><span class=cF0> *</span><span class=cFB>heaplog_hc_watched</span><span class=cF0>, *</span><span class=cFB>heaplog_hc</span><span class=cF0> = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l25"></a></span><span class=cF9>CHeapLogHash</span><span class=cF0> *</span><span class=cFB>heaplog_head</span><span class=cF0> = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l26"></a>
<a name="l27"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>HeapLogMAlloc</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *addr)
<a name="l28"></a>{
<a name="l29"></a> </span><span class=cF9>CHeapLog</span><span class=cF0> *tmphl;
<a name="l30"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l31"></a>
<a name="l32"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>MHeapCtrl</span><span class=cF7>(</span><span class=cF0>addr</span><span class=cF7>)</span><span class=cF0> == </span><span class=cFB>heaplog_hc_watched</span><span class=cF0>)
<a name="l33"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l34"></a> tmphl = </span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CHeapLog</span><span class=cF7>)</span><span class=cF0>, </span><span class=cFB>heaplog_hc</span><span class=cF0>);
<a name="l35"></a> tmphl-&gt;addr = addr;
<a name="l36"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cF3>HL_CALLER_DEPTH</span><span class=cF0>; i++)
<a name="l37"></a> tmphl-&gt;caller[i] = </span><span class=cF5>Caller</span><span class=cF0>(i + </span><span class=cFE>2</span><span class=cF0>);
<a name="l38"></a> i = addr &gt;&gt; </span><span class=cFE>3</span><span class=cF0> &amp; (</span><span class=cF3>HL_HASH_SIZE</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF0>);
<a name="l39"></a>
<a name="l40"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l41"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l42"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_LOCK</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF7>)</span><span class=cF0>)
<a name="l43"></a> </span><span class=cF1>PAUSE</span><span class=cF0>
<a name="l44"></a> </span><span class=cF5>QueueInsert</span><span class=cF0>(tmphl, </span><span class=cFB>heaplog_head</span><span class=cF0>[i].last);
<a name="l45"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_LOCK</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF0>);
<a name="l46"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l47"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l48"></a>}
<a name="l49"></a>
<a name="l50"></a></span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>HeapLogFree</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *addr)
<a name="l51"></a>{
<a name="l52"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l53"></a> </span><span class=cF9>CHeapLog</span><span class=cF0> *tmphl;
<a name="l54"></a>
<a name="l55"></a> </span><span class=cF1>if</span><span class=cF0> (!addr)
<a name="l56"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l57"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>MHeapCtrl</span><span class=cF7>(</span><span class=cF0>addr</span><span class=cF7>)</span><span class=cF0> == </span><span class=cFB>heaplog_hc_watched</span><span class=cF0>)
<a name="l58"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l59"></a> i = addr &gt;&gt; </span><span class=cFE>3</span><span class=cF0> &amp; (</span><span class=cF3>HL_HASH_SIZE</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF0>);
<a name="l60"></a>
<a name="l61"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l62"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l63"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_LOCK</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF7>)</span><span class=cF0>)
<a name="l64"></a> </span><span class=cF1>PAUSE</span><span class=cF0>
<a name="l65"></a> tmphl = </span><span class=cFB>heaplog_head</span><span class=cF0>[i].next;
<a name="l66"></a> </span><span class=cF1>while</span><span class=cF0> (tmphl != &amp;</span><span class=cFB>heaplog_head</span><span class=cF0>[i])
<a name="l67"></a> {
<a name="l68"></a> </span><span class=cF1>if</span><span class=cF0> (addr == tmphl-&gt;addr)
<a name="l69"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l70"></a> </span><span class=cF5>QueueRemove</span><span class=cF0>(tmphl);
<a name="l71"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_LOCK</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF0>);
<a name="l72"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l73"></a> </span><span class=cF5>Free</span><span class=cF0>(tmphl);
<a name="l74"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l75"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l76"></a> tmphl = tmphl-&gt;next;
<a name="l77"></a> }
<a name="l78"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_LOCK</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF0>);
<a name="l79"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l80"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l81"></a>}
<a name="l82"></a>
<a name="l83"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>HeapLog</span><span class=cF0>(</span><span class=cF1>Bool</span><span class=cF0> val=</span><span class=cF3>ON</span><span class=cF0>, </span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l84"></a>{</span><span class=cF2>//Turn on. Collect data.</span><span class=cF0> </span><span class=cF2>Call </span><a href="https://tomawezome.github.io/ZealOS/System/Utils/HeapLog.html#l139"><span class=cF4>HeapLogAddrRep</span></a><span class=cF2>() or </span><a href="https://tomawezome.github.io/ZealOS/System/Utils/HeapLog.html#l174"><span class=cF4>HeapLogSizeRep</span></a><span class=cF2>().</span><span class=cF0>
<a name="l85"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l86"></a>
<a name="l87"></a> </span><span class=cF1>if</span><span class=cF0> (val)
<a name="l88"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l89"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>Bt</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_ACTIVE</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF7>)</span><span class=cF0>)
<a name="l90"></a> {
<a name="l91"></a> </span><span class=cF6>&quot;HeapLog Already Active\n&quot;</span><span class=cF0>;
<a name="l92"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l93"></a> }
<a name="l94"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l95"></a> {
<a name="l96"></a> </span><span class=cF1>if</span><span class=cF0> (!task)
<a name="l97"></a> task = </span><span class=cF5>Fs</span><span class=cF0>;
<a name="l98"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>TaskValidate</span><span class=cF7>(</span><span class=cF0>task</span><span class=cF7>)</span><span class=cF0>)
<a name="l99"></a> </span><span class=cFB>heaplog_hc_watched</span><span class=cF0> = task-&gt;data_heap;
<a name="l100"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l101"></a> </span><span class=cFB>heaplog_hc_watched</span><span class=cF0> = task;</span><span class=cF2>//Actually, not a task, must be a HeapCtrl.</span><span class=cF0>
<a name="l102"></a>
<a name="l103"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l104"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l105"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_LOCK</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF7>)</span><span class=cF0>)
<a name="l106"></a> </span><span class=cF1>PAUSE</span><span class=cF0>
<a name="l107"></a> </span><span class=cFB>heaplog_hc</span><span class=cF0> = </span><span class=cF5>HeapCtrlInit</span><span class=cF0>(,, </span><span class=cFB>sys_data_bp</span><span class=cF0>);
<a name="l108"></a> </span><span class=cFB>ext</span><span class=cF0>[</span><span class=cF3>EXT_HEAPLOG_MALLOC</span><span class=cF0>] = &amp;</span><span class=cF5>HeapLogMAlloc</span><span class=cF0>;
<a name="l109"></a> </span><span class=cFB>ext</span><span class=cF0>[</span><span class=cF3>EXT_HEAPLOG_FREE</span><span class=cF0>] = &amp;</span><span class=cF5>HeapLogFree</span><span class=cF0>;
<a name="l110"></a> </span><span class=cFB>heaplog_head</span><span class=cF0> = </span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CHeapLogHash</span><span class=cF7>)</span><span class=cF0> * </span><span class=cF3>HL_HASH_SIZE</span><span class=cF0>, </span><span class=cFB>heaplog_hc</span><span class=cF0>);
<a name="l111"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cF3>HL_HASH_SIZE</span><span class=cF0>; i++)
<a name="l112"></a> </span><span class=cF5>QueueInit</span><span class=cF0>(&amp;</span><span class=cFB>heaplog_head</span><span class=cF0>[i]);
<a name="l113"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_LOCK</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF0>);
<a name="l114"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l115"></a> </span><span class=cF5>LBts</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_ACTIVE</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF0>);
<a name="l116"></a>
<a name="l117"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l118"></a> }
<a name="l119"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l120"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l121"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l122"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>LBtr</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_ACTIVE</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF7>)</span><span class=cF0>)
<a name="l123"></a> {
<a name="l124"></a> </span><span class=cF6>&quot;HeapLog Not Active\n&quot;</span><span class=cF0>;
<a name="l125"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l126"></a> }
<a name="l127"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l128"></a> {
<a name="l129"></a> </span><span class=cF5>HeapCtrlDel</span><span class=cF0>(</span><span class=cFB>heaplog_hc</span><span class=cF0>);
<a name="l130"></a> </span><span class=cFB>heaplog_head</span><span class=cF0> = </span><span class=cFB>heaplog_hc</span><span class=cF0> = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l131"></a> </span><span class=cFB>ext</span><span class=cF0>[</span><span class=cF3>EXT_HEAPLOG_MALLOC</span><span class=cF0>] = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l132"></a> </span><span class=cFB>ext</span><span class=cF0>[</span><span class=cF3>EXT_HEAPLOG_FREE</span><span class=cF0>] = </span><span class=cF3>NULL</span><span class=cF0>;
<a name="l133"></a>
<a name="l134"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l135"></a> }
<a name="l136"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l137"></a>}
<a name="l138"></a>
<a name="l139"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>HeapLogAddrRep</span><span class=cF0>(</span><span class=cF1>Bool</span><span class=cF0> leave_it=</span><span class=cF3>OFF</span><span class=cF0>)
<a name="l140"></a>{</span><span class=cF2>//Call </span><a href="https://tomawezome.github.io/ZealOS/System/Utils/HeapLog.html#l83"><span class=cF4>HeapLog</span></a><span class=cF2>() first and collect data.</span><span class=cF0>
<a name="l141"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, total = </span><span class=cFE>0</span><span class=cF0>;
<a name="l142"></a> </span><span class=cF9>CHeapLog</span><span class=cF0> *tmphl, hl;
<a name="l143"></a>
<a name="l144"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>LBtr</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_ACTIVE</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF7>)</span><span class=cF0>)
<a name="l145"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l146"></a> </span><span class=cF6>&quot;HeapLog Not Active\n&quot;</span><span class=cF0>;
<a name="l147"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l148"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l149"></a> </span><span class=cF6>&quot;$WW,0$&quot;</span><span class=cF0>;
<a name="l150"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_LOCK</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF7>)</span><span class=cF0>)
<a name="l151"></a> </span><span class=cF1>PAUSE</span><span class=cF0>
<a name="l152"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cF3>HL_HASH_SIZE</span><span class=cF0>; i++)
<a name="l153"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l154"></a> tmphl = </span><span class=cFB>heaplog_head</span><span class=cF0>[i].next;
<a name="l155"></a> </span><span class=cF1>while</span><span class=cF0> (tmphl != &amp;</span><span class=cFB>heaplog_head</span><span class=cF0>[i])
<a name="l156"></a> {
<a name="l157"></a></span><span class=cF2>//Take snapshot in case modified. (while we work)</span><span class=cF0>
<a name="l158"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(&amp;hl, tmphl, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CHeapLog</span><span class=cF7>)</span><span class=cF0>);
<a name="l159"></a> </span><span class=cF6>&quot;$PURPLE$%08X$FG$ %08X&quot;</span><span class=cF0>, </span><span class=cF5>MSize</span><span class=cF0>(hl.addr), hl.addr;
<a name="l160"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; </span><span class=cF3>HL_CALLER_DEPTH</span><span class=cF0>; j++)
<a name="l161"></a> </span><span class=cF6>&quot; %P&quot;</span><span class=cF0>, hl.caller[j];
<a name="l162"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l163"></a> total += </span><span class=cF5>MSize</span><span class=cF0>(hl.addr);
<a name="l164"></a> tmphl = hl.next;
<a name="l165"></a> }
<a name="l166"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l167"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_LOCK</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF0>);
<a name="l168"></a> </span><span class=cF6>&quot;\n$LTRED$Total:%08X$FG$\n&quot;</span><span class=cF0>, total;
<a name="l169"></a> </span><span class=cF5>LBts</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_ACTIVE</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF0>);
<a name="l170"></a> </span><span class=cF1>if</span><span class=cF0> (!leave_it)
<a name="l171"></a> </span><span class=cF5>HeapLog</span><span class=cF0>(</span><span class=cF3>OFF</span><span class=cF0>);
<a name="l172"></a>}
<a name="l173"></a>
<a name="l174"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>U0</span><span class=cF0> </span><span class=cF5>HeapLogSizeRep</span><span class=cF0>(</span><span class=cF1>Bool</span><span class=cF0> leave_it=</span><span class=cF3>OFF</span><span class=cF0>)
<a name="l175"></a>{</span><span class=cF2>//Call </span><a href="https://tomawezome.github.io/ZealOS/System/Utils/HeapLog.html#l83"><span class=cF4>HeapLog</span></a><span class=cF2>() first and collect data.</span><span class=cF0>
<a name="l176"></a> </span><span class=cF9>I64</span><span class=cF0> i, j, k, total = </span><span class=cFE>0</span><span class=cF0>;
<a name="l177"></a> </span><span class=cF9>CHeapLog</span><span class=cF0> *tmphla, hla, *tmphls, *tmphls1;
<a name="l178"></a> </span><span class=cF9>CHeapLogHash</span><span class=cF0> *size_head;
<a name="l179"></a>
<a name="l180"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>LBtr</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_ACTIVE</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF7>)</span><span class=cF0>)
<a name="l181"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l182"></a> </span><span class=cF6>&quot;HeapLog Not Active\n&quot;</span><span class=cF0>;
<a name="l183"></a> </span><span class=cF1>return</span><span class=cF0>;
<a name="l184"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l185"></a>
<a name="l186"></a> size_head = </span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CHeapLogHash</span><span class=cF7>)</span><span class=cF0> * </span><span class=cF3>HL_HASH_SIZE</span><span class=cF0>, </span><span class=cFB>heaplog_hc</span><span class=cF0>);
<a name="l187"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cF3>HL_HASH_SIZE</span><span class=cF0>; i++)
<a name="l188"></a> </span><span class=cF5>QueueInit</span><span class=cF0>(&amp;size_head[i]);
<a name="l189"></a>
<a name="l190"></a> </span><span class=cF6>&quot;$WW,0$&quot;</span><span class=cF0>;
<a name="l191"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_LOCK</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF7>)</span><span class=cF0>)
<a name="l192"></a> </span><span class=cF1>PAUSE</span><span class=cF0>
<a name="l193"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cF3>HL_HASH_SIZE</span><span class=cF0>; i++)
<a name="l194"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l195"></a> tmphla = </span><span class=cFB>heaplog_head</span><span class=cF0>[i].next;
<a name="l196"></a> </span><span class=cF1>while</span><span class=cF0> (tmphla != &amp;</span><span class=cFB>heaplog_head</span><span class=cF0>[i])
<a name="l197"></a> {
<a name="l198"></a></span><span class=cF2>//Take snapshot in case modified. (while we work)</span><span class=cF0>
<a name="l199"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(&amp;hla, tmphla, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CHeapLog</span><span class=cF7>)</span><span class=cF0>);
<a name="l200"></a> k = (</span><span class=cF5>MSize</span><span class=cF7>(</span><span class=cF0>hla.addr</span><span class=cF7>)</span><span class=cF0> &gt;&gt; </span><span class=cFE>3</span><span class=cF0> + hla.caller[</span><span class=cFE>0</span><span class=cF0>]) &amp; (</span><span class=cF3>HL_HASH_SIZE</span><span class=cF0> - </span><span class=cFE>1</span><span class=cF0>);
<a name="l201"></a> tmphls = size_head[k].next;
<a name="l202"></a> </span><span class=cF1>while</span><span class=cF0> (tmphls != &amp;size_head[k])
<a name="l203"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l204"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>MSize</span><span class=cF7>(</span><span class=cF0>hla.addr</span><span class=cF7>)</span><span class=cF0> == tmphls-&gt;size)
<a name="l205"></a> {
<a name="l206"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; </span><span class=cF3>HL_CALLER_DEPTH</span><span class=cF0>; j++)
<a name="l207"></a> </span><span class=cF1>if</span><span class=cF0> (hla.caller[j] != tmphls-&gt;caller[j])
<a name="l208"></a> </span><span class=cF1>goto</span><span class=cF0> hl_next;
<a name="l209"></a> tmphls-&gt;count++;
<a name="l210"></a> </span><span class=cF1>goto</span><span class=cF0> hl_found;
<a name="l211"></a> }
<a name="l212"></a>hl_next:
<a name="l213"></a> tmphls = tmphls-&gt;next;
<a name="l214"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l215"></a> tmphls = </span><span class=cF5>MAlloc</span><span class=cF0>(</span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CHeapLog</span><span class=cF7>)</span><span class=cF0>, </span><span class=cFB>heaplog_hc</span><span class=cF0>);
<a name="l216"></a> </span><span class=cF5>MemCopy</span><span class=cF0>(tmphls, &amp;hla, </span><span class=cF1>sizeof</span><span class=cF7>(</span><span class=cF9>CHeapLog</span><span class=cF7>)</span><span class=cF0>);
<a name="l217"></a> tmphls-&gt;count = </span><span class=cFE>1</span><span class=cF0>;
<a name="l218"></a> tmphls-&gt;size = </span><span class=cF5>MSize</span><span class=cF0>(hla.addr);
<a name="l219"></a> </span><span class=cF5>QueueInsert</span><span class=cF0>(tmphls, size_head[k].last);
<a name="l220"></a>hl_found:
<a name="l221"></a> tmphla = hla.next;
<a name="l222"></a> }
<a name="l223"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l224"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_LOCK</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF0>);
<a name="l225"></a>
<a name="l226"></a> </span><span class=cF1>for</span><span class=cF0> (i = </span><span class=cFE>0</span><span class=cF0>; i &lt; </span><span class=cF3>HL_HASH_SIZE</span><span class=cF0>; i++)
<a name="l227"></a> </span><span class=cF7>{</span><span class=cF0>
<a name="l228"></a> tmphls = size_head[i].next;
<a name="l229"></a> </span><span class=cF1>while</span><span class=cF0> (tmphls != &amp;size_head[i])
<a name="l230"></a> {
<a name="l231"></a> tmphls1 = tmphls-&gt;next;
<a name="l232"></a> </span><span class=cF6>&quot;%08X*%08X=%08X&quot;</span><span class=cF0>, tmphls-&gt;size, tmphls-&gt;count, tmphls-&gt;size * tmphls-&gt;count;
<a name="l233"></a> </span><span class=cF1>for</span><span class=cF0> (j = </span><span class=cFE>0</span><span class=cF0>; j &lt; </span><span class=cF3>HL_CALLER_DEPTH</span><span class=cF0>; j++)
<a name="l234"></a> </span><span class=cF6>&quot; %P&quot;</span><span class=cF0>, tmphls-&gt;caller[j];
<a name="l235"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l236"></a> total += tmphls-&gt;size * tmphls-&gt;count;
<a name="l237"></a> </span><span class=cF5>Free</span><span class=cF0>(tmphls);
<a name="l238"></a> tmphls = tmphls1;
<a name="l239"></a> }
<a name="l240"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l241"></a> </span><span class=cF5>Free</span><span class=cF0>(size_head);
<a name="l242"></a>
<a name="l243"></a> </span><span class=cF6>&quot;\n$LTRED$Total:%08X$FG$\n&quot;</span><span class=cF0>, total;
<a name="l244"></a> </span><span class=cF5>LBts</span><span class=cF0>(&amp;</span><span class=cFB>sys_semas</span><span class=cF0>[</span><span class=cF3>SEMA_HEAPLOG_ACTIVE</span><span class=cF0>], </span><span class=cFE>0</span><span class=cF0>);
<a name="l245"></a> </span><span class=cF1>if</span><span class=cF0> (!leave_it)
<a name="l246"></a> </span><span class=cF5>HeapLog</span><span class=cF0>(</span><span class=cF3>OFF</span><span class=cF0>);
<a name="l247"></a>}
</span></pre></body>
</html>